diff --git a/account_invoice_margin_sale/__manifest__.py b/account_invoice_margin_sale/__manifest__.py index 7c51edfb..378a43ab 100644 --- a/account_invoice_margin_sale/__manifest__.py +++ b/account_invoice_margin_sale/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Account Invoice Margin Sale", "summary": "Set margin in invoices from sale orders", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "development_status": "Production/Stable", "maintainers": ["sergio-teruel", "carlosdauden"], "category": "Account", diff --git a/account_invoice_margin_sale/models/account_invoice.py b/account_invoice_margin_sale/models/account_invoice.py index 1c5d55e0..71acb368 100644 --- a/account_invoice_margin_sale/models/account_invoice.py +++ b/account_invoice_margin_sale/models/account_invoice.py @@ -8,8 +8,10 @@ class AccountMove(models.Model): _inherit = "account.move" def _get_margin_applicable_lines(self): - lines = super()._get_margin_applicable_lines() - return lines.filtered(lambda x: not x.sale_line_ids.is_downpayment) + 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): @@ -18,10 +20,14 @@ class AccountMoveLine(models.Model): # pylint: disable=W8110 @api.depends("purchase_price", "price_subtotal") def _compute_margin(self): - for line in self: - if any(line.sale_line_ids.mapped("is_downpayment")): - line.update( - {"margin": 0.0, "margin_signed": 0.0, "margin_percent": 0.0} - ) - else: - super(AccountMoveLine, line)._compute_margin() + 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/readme/CONTRIBUTORS.rst b/account_invoice_margin_sale/readme/CONTRIBUTORS.rst index 59d8d996..684550f4 100644 --- a/account_invoice_margin_sale/readme/CONTRIBUTORS.rst +++ b/account_invoice_margin_sale/readme/CONTRIBUTORS.rst @@ -7,3 +7,7 @@ * `Open Source Integrators `__: * Bhavesh Odedra + +* `Factor Libre `__: + + * Luis J. Salvatierra diff --git a/account_invoice_margin_sale/readme/DESCRIPTION.rst b/account_invoice_margin_sale/readme/DESCRIPTION.rst index 6fb92734..f798a9ca 100644 --- a/account_invoice_margin_sale/readme/DESCRIPTION.rst +++ b/account_invoice_margin_sale/readme/DESCRIPTION.rst @@ -1 +1,2 @@ -This module allows transfer purchase price from sale order line to invoice. +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/tests/test_account_invoice_margin_sale.py b/account_invoice_margin_sale/tests/test_account_invoice_margin_sale.py index 08e928a9..18c44aa6 100644 --- a/account_invoice_margin_sale/tests/test_account_invoice_margin_sale.py +++ b/account_invoice_margin_sale/tests/test_account_invoice_margin_sale.py @@ -9,21 +9,24 @@ class TestAccountInvoiceMargin(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) cls.journal = cls.env["account.journal"].create( {"name": "Test journal", "type": "sale", "code": "TEST_J"} ) - cls.account_type = cls.env["account.account.type"].create( - { - "name": "Test account type", - "type": "receivable", - "internal_group": "income", - } - ) cls.account = cls.env["account.account"].create( { "name": "Test account", - "code": "TEST_A", - "user_type_id": cls.account_type.id, + "code": "TESTACCRECV", + "account_type": "asset_receivable", "reconcile": True, } )