From 4a0054a409f4ddae5bd86029fc8ca2a8504adb78 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Wed, 4 Nov 2020 16:20:02 +0000 Subject: [PATCH] [FIX] account: fix total recomputation when having 100% tax Create a tax as follows: * Tax Computation: Percentage of Price Tax Included * Tax Scope: Purchase * Amount: 100% * Included in Price * Affect Base of Subsequent Taxes Create a vendor bill with the tax on the line Change unit price The total does not change This occur because when having 100% tax debit/credit are unchanged. So the onchange `_onchange_mark_recompute_taxes` is not triggered and the tax lines are not updated, thus not changing the total (as in this case the invoice total is just the tax value) opw-2370861 closes odoo/odoo#61555 X-original-commit: 9e203cc016b45875f699ffab24fe3f8382a97303 Signed-off-by: Laurent Smet Signed-off-by: agr-odoo --- addons/account/models/account_move.py | 2 +- addons/account/tests/test_invoice_taxes.py | 38 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 441e1c46713..9decc62a290 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3335,7 +3335,7 @@ class AccountMoveLine(models.Model): # ONCHANGE METHODS # ------------------------------------------------------------------------- - @api.onchange('amount_currency', 'currency_id', 'debit', 'credit', 'tax_ids', 'account_id') + @api.onchange('amount_currency', 'currency_id', 'debit', 'credit', 'tax_ids', 'account_id', 'price_unit') def _onchange_mark_recompute_taxes(self): ''' Recompute the dynamic onchange based on taxes. If the edited line is a tax line, don't recompute anything as the user must be able to diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py index ceeff912c44..a8653d90148 100644 --- a/addons/account/tests/test_invoice_taxes.py +++ b/addons/account/tests/test_invoice_taxes.py @@ -266,6 +266,44 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): self.assertAlmostEqual(abs(ref_tax_lines.filtered(lambda x: x.account_id == account_1).balance), 37.8, 2, "Refund tax line on account 1 should amount to 37.8 (90% of 42)") self.assertEqual(ref_tax_lines.mapped('tax_tag_ids'), ref_tax_tag, "Refund tax lines should have the right tag") + def test_division_tax(self): + ''' + Test that when using division tax, with percentage amount + 100% any change on price unit is correctly reflected on + the whole move. + + Complete scenario: + - Create a division tax, 100% amount, included in price. + - Create an invoice, with only the mentioned tax + - Change price_unit of the aml + - Total price of the move should change as well + ''' + + sale_tax = self.env['account.tax'].create({ + 'name': 'tax', + 'type_tax_use': 'sale', + 'amount_type': 'division', + 'amount': 100, + 'price_include': True, + 'include_base_amount': True, + }) + invoice = self._create_invoice([(100, sale_tax)]) + self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [{ + 'name': sale_tax.name, + 'tax_base_amount': 0.0, + 'balance': -100, + }]) + # change price unit, everything should change as well + with Form(invoice) as invoice_form: + with invoice_form.line_ids.edit(0) as line_edit: + line_edit.price_unit = 200 + + self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [{ + 'name': sale_tax.name, + 'tax_base_amount': 0.0, + 'balance': -200, + }]) + def test_misc_journal_entry_tax_tags_sale(self): sale_tax = self.env['account.tax'].create({ 'name': 'tax',