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',