diff --git a/account_invoice_margin_sale/README.rst b/account_invoice_margin_sale/README.rst new file mode 100644 index 00000000..7220446f --- /dev/null +++ b/account_invoice_margin_sale/README.rst @@ -0,0 +1,119 @@ +=========================== +Account Invoice Margin Sale +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4b6cc430e226d789e638616e03761cc6c56aea0be0b262601335bd62ba16d253 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github + :target: https://github.com/OCA/margin-analysis/tree/18.0/account_invoice_margin_sale + :alt: OCA/margin-analysis +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/margin-analysis-18-0/margin-analysis-18-0-account_invoice_margin_sale + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/margin-analysis&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module propagates purchase price from sale order line to invoice +and discards the invoice lines coming from sale order lines with +down-payment when computing the margin. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module is autoinstalable. + +Usage +===== + +This module also needs a security group to show margins. + +1. To activate it go to user and active "Show Invoice Margin" in + security options. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Sergio Teruel + - Carlos Dauden + - Víctor Martínez + +- `Open Source Integrators `__: + + - Bhavesh Odedra + - Daniel Reis + +- `Factor Libre `__: + + - Luis J. Salvatierra + +- `Avoin.Systems `__: + + - Nedas Żilinskas + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px + :target: https://github.com/sergio-teruel + :alt: sergio-teruel +.. |maintainer-carlosdauden| image:: https://github.com/carlosdauden.png?size=40px + :target: https://github.com/carlosdauden + :alt: carlosdauden + +Current `maintainers `__: + +|maintainer-sergio-teruel| |maintainer-carlosdauden| + +This module is part of the `OCA/margin-analysis `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_invoice_margin_sale/__init__.py b/account_invoice_margin_sale/__init__.py new file mode 100644 index 00000000..69f7babd --- /dev/null +++ b/account_invoice_margin_sale/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_invoice_margin_sale/__manifest__.py b/account_invoice_margin_sale/__manifest__.py new file mode 100644 index 00000000..3750d9f9 --- /dev/null +++ b/account_invoice_margin_sale/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2017-2018 Tecnativa - Sergio Teruel +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Account Invoice Margin Sale", + "summary": "Set margin in invoices from sale orders", + "version": "18.0.1.0.0", + "development_status": "Production/Stable", + "maintainers": ["sergio-teruel", "carlosdauden"], + "category": "Account", + "website": "https://github.com/OCA/margin-analysis", + "author": "Tecnativa, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": ["sale_margin", "account_invoice_margin"], +} diff --git a/account_invoice_margin_sale/i18n/account_invoice_margin_sale.pot b/account_invoice_margin_sale/i18n/account_invoice_margin_sale.pot new file mode 100644 index 00000000..8b03f15e --- /dev/null +++ b/account_invoice_margin_sale/i18n/account_invoice_margin_sale.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_margin_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/account_invoice_margin_sale/i18n/es.po b/account_invoice_margin_sale/i18n/es.po new file mode 100644 index 00000000..88e865fc --- /dev/null +++ b/account_invoice_margin_sale/i18n/es.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_margin_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-07 19:09+0000\n" +"Last-Translator: gelo joga Rodríguez \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move +msgid "Journal Entry" +msgstr "Asiento contable" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" + +#~ msgid "Journal Entries" +#~ msgstr "Entradas de diario" diff --git a/account_invoice_margin_sale/i18n/fr_FR.po b/account_invoice_margin_sale/i18n/fr_FR.po new file mode 100644 index 00000000..cf2ec905 --- /dev/null +++ b/account_invoice_margin_sale/i18n/fr_FR.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_margin_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-05 18:09+0000\n" +"Last-Translator: \"Sandrine (ACSONE)\" \n" +"Language-Team: none\n" +"Language: fr_FR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move +msgid "Journal Entry" +msgstr "Pièce comptable" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move_line +msgid "Journal Item" +msgstr "Ecriture comptable" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "Ligne de commande client" diff --git a/account_invoice_margin_sale/i18n/it.po b/account_invoice_margin_sale/i18n/it.po new file mode 100644 index 00000000..4291d58d --- /dev/null +++ b/account_invoice_margin_sale/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_margin_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-29 17:38+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move +msgid "Journal Entry" +msgstr "Registrazione contabile" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_account_move_line +msgid "Journal Item" +msgstr "Movimento contabile" + +#. module: account_invoice_margin_sale +#: model:ir.model,name:account_invoice_margin_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" diff --git a/account_invoice_margin_sale/models/__init__.py b/account_invoice_margin_sale/models/__init__.py new file mode 100644 index 00000000..1c5404c7 --- /dev/null +++ b/account_invoice_margin_sale/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import sale +from . import account_invoice diff --git a/account_invoice_margin_sale/models/account_invoice.py b/account_invoice_margin_sale/models/account_invoice.py new file mode 100644 index 00000000..71acb368 --- /dev/null +++ b/account_invoice_margin_sale/models/account_invoice.py @@ -0,0 +1,33 @@ +# Copyright 2021 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _get_margin_applicable_lines(self): + invoice_lines = super()._get_margin_applicable_lines() + return invoice_lines.filtered( + lambda x: not any(x.sale_line_ids.mapped("is_downpayment")) + ) + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + # pylint: disable=W8110 + @api.depends("purchase_price", "price_subtotal") + def _compute_margin(self): + invoice_lines_with_downpayment = self.filtered( + lambda x: any(x.sale_line_ids.mapped("is_downpayment")) + ) + invoice_lines_with_downpayment.update( + { + "margin": 0.0, + "margin_signed": 0.0, + "margin_percent": 0.0, + } + ) + super(AccountMoveLine, self - invoice_lines_with_downpayment)._compute_margin() diff --git a/account_invoice_margin_sale/models/sale.py b/account_invoice_margin_sale/models/sale.py new file mode 100644 index 00000000..0ee4ccb4 --- /dev/null +++ b/account_invoice_margin_sale/models/sale.py @@ -0,0 +1,14 @@ +# Copyright 2017-2018 Tecnativa - Sergio Teruel +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _prepare_invoice_line(self, **optional_values): + vals = super()._prepare_invoice_line(**optional_values) + vals["purchase_price"] = self.sudo().purchase_price + return vals diff --git a/account_invoice_margin_sale/pyproject.toml b/account_invoice_margin_sale/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/account_invoice_margin_sale/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_invoice_margin_sale/readme/CONTRIBUTORS.md b/account_invoice_margin_sale/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..9aeaf9f0 --- /dev/null +++ b/account_invoice_margin_sale/readme/CONTRIBUTORS.md @@ -0,0 +1,11 @@ +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel + - Carlos Dauden + - Víctor Martínez +- [Open Source Integrators](https://www.opensourceintegrators.com): + - Bhavesh Odedra + - Daniel Reis \<\> +- [Factor Libre](https://www.factorlibre.com): + - Luis J. Salvatierra +- [Avoin.Systems](https://avoin.systems/): + - Nedas Żilinskas diff --git a/account_invoice_margin_sale/readme/DESCRIPTION.md b/account_invoice_margin_sale/readme/DESCRIPTION.md new file mode 100644 index 00000000..c04ef530 --- /dev/null +++ b/account_invoice_margin_sale/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module propagates purchase price from sale order line to invoice +and discards the invoice lines coming from sale order lines with +down-payment when computing the margin. diff --git a/account_invoice_margin_sale/readme/INSTALL.md b/account_invoice_margin_sale/readme/INSTALL.md new file mode 100644 index 00000000..0cde2de7 --- /dev/null +++ b/account_invoice_margin_sale/readme/INSTALL.md @@ -0,0 +1 @@ +This module is autoinstalable. diff --git a/account_invoice_margin_sale/readme/USAGE.md b/account_invoice_margin_sale/readme/USAGE.md new file mode 100644 index 00000000..422be6bb --- /dev/null +++ b/account_invoice_margin_sale/readme/USAGE.md @@ -0,0 +1,4 @@ +This module also needs a security group to show margins. + +1. To activate it go to user and active "Show Invoice Margin" in + security options. diff --git a/account_invoice_margin_sale/static/description/icon.png b/account_invoice_margin_sale/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_invoice_margin_sale/static/description/icon.png differ diff --git a/account_invoice_margin_sale/static/description/index.html b/account_invoice_margin_sale/static/description/index.html new file mode 100644 index 00000000..c9dd5448 --- /dev/null +++ b/account_invoice_margin_sale/static/description/index.html @@ -0,0 +1,459 @@ + + + + + +Account Invoice Margin Sale + + + +
+

Account Invoice Margin Sale

+ + +

Production/Stable License: AGPL-3 OCA/margin-analysis Translate me on Weblate Try me on Runboat

+

This module propagates purchase price from sale order line to invoice +and discards the invoice lines coming from sale order lines with +down-payment when computing the margin.

+

Table of contents

+ +
+

Installation

+

This module is autoinstalable.

+
+
+

Usage

+

This module also needs a security group to show margins.

+
    +
  1. To activate it go to user and active “Show Invoice Margin” in +security options.
  2. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainers:

+

sergio-teruel carlosdauden

+

This module is part of the OCA/margin-analysis project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_invoice_margin_sale/tests/__init__.py b/account_invoice_margin_sale/tests/__init__.py new file mode 100644 index 00000000..4423d9c3 --- /dev/null +++ b/account_invoice_margin_sale/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_account_invoice_margin_sale diff --git a/account_invoice_margin_sale/tests/test_account_invoice_margin_sale.py b/account_invoice_margin_sale/tests/test_account_invoice_margin_sale.py new file mode 100644 index 00000000..15328eae --- /dev/null +++ b/account_invoice_margin_sale/tests/test_account_invoice_margin_sale.py @@ -0,0 +1,126 @@ +# Copyright 2017-2018 Tecnativa - Sergio Teruel +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestAccountInvoiceMargin(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + cls.journal = cls.env["account.journal"].create( + {"name": "Test journal", "type": "sale", "code": "TEST_J"} + ) + cls.account = cls.env["account.account"].create( + { + "name": "Test account", + "code": "TESTACCRECV", + "account_type": "asset_receivable", + "reconcile": True, + } + ) + cls.partner = cls.env["res.partner"].create( + {"name": "Test partner", "customer_rank": 1, "is_company": True} + ) + cls.partner.property_account_receivable_id = cls.account + cls.product_categ = cls.env["product.category"].create( + {"name": "Test category"} + ) + + cls.product = cls.env["product.product"].create( + { + "name": "test product", + "categ_id": cls.product_categ.id, + "uom_id": cls.env.ref("uom.product_uom_unit").id, + "uom_po_id": cls.env.ref("uom.product_uom_unit").id, + "default_code": "test-margin", + "invoice_policy": "order", + "list_price": 200.00, + "standard_price": 100.00, + } + ) + pricelist = cls.env["product.pricelist"].create({"name": "Public Pricelist"}) + + cls.sale_order = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "pricelist_id": pricelist.id, + "order_line": [ + ( + 0, + 0, + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_uom_qty": 1, + "product_uom": cls.product.uom_id.id, + "price_unit": 100.0, + }, + ) + ], + } + ) + + def test_invoice_sale_order(self): + self.sale_order.action_confirm() + self.sale_order.order_line.purchase_price = 500.00 + invoice = self.sale_order._create_invoices() + self.assertAlmostEqual(invoice.invoice_line_ids.purchase_price, 500.00, 2) + + def test_invoice_down_payment(self): + SaleAdvancePaymentInv = self.env["sale.advance.payment.inv"] + AccountMove = self.env["account.move"] + product = self.env["product.product"].create( + { + "name": "test product for down payment", + "categ_id": self.product_categ.id, + "uom_id": self.env.ref("uom.product_uom_unit").id, + "list_price": 1000.00, + "standard_price": 500.00, + "type": "service", + "invoice_policy": "order", + } + ) + self.order = self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + ( + 0, + False, + { + "product_id": product.id, + "name": "Testing Product", + "product_uom_qty": 1, + "product_uom": product.uom_id.id, + "price_unit": 1000.00, + "purchase_price": 500.00, + }, + ), + ], + } + ) + self.order.action_confirm() + # Create one down payment + wiz = SaleAdvancePaymentInv.with_context( + active_ids=self.order.ids, + open_invoices=True, + ).create({"advance_payment_method": "fixed", "fixed_amount": 100.00}) + action = wiz.create_invoices() + invoice_id = action["res_id"] + invoice1 = AccountMove.browse(invoice_id) + self.assertEqual(invoice1.margin, 0.0) + + # Create regular invoice which has a down payment + wiz = SaleAdvancePaymentInv.with_context( + active_ids=self.order.ids, + open_invoices=True, + ).create({"advance_payment_method": "delivered"}) + wiz.create_invoices() + invoice2 = self.order.invoice_ids - invoice1 + self.assertEqual(invoice2.margin, 500.00) + self.assertEqual(invoice2.margin_percent, 50.0) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000..b5b22ccb --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-account_invoice_margin @ git+https://github.com/OCA/margin-analysis.git@refs/pull/230/head#subdirectory=account_invoice_margin