diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 396727f8a2f64bf40480d5e7cf9d76e81625a2c9..51b670f3494a5730c4bd76ed8955ccbe1adf4554 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1013,7 +1013,12 @@ class AccountMove(models.Model): else: tax_type = line.tax_ids[0].type_tax_use is_refund = (tax_type == 'sale' and line.debit) or (tax_type == 'purchase' and line.credit) - taxes = line.tax_ids.flatten_taxes_hierarchy() + taxes = line.tax_ids._origin.flatten_taxes_hierarchy().filtered( + lambda tax: ( + tax.amount_type == 'fixed' and not invoice.company_id.currency_id.is_zero(tax.amount) + or not float_is_zero(tax.amount, precision_digits=4) + ) + ) if is_refund: tax_rep_lines = taxes.refund_repartition_line_ids._origin.filtered(lambda x: x.repartition_type == "tax") else: diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py index 6e134a8c511d4b45e0a24bf7dcc866f32bb947f4..b6dc6d1eca9b82a04c4eb6a4bbf7622fc546613d 100644 --- a/addons/account/tests/test_invoice_taxes.py +++ b/addons/account/tests/test_invoice_taxes.py @@ -706,3 +706,113 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): self.assertRecordValues(invoice.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable'), [{ 'balance': 686.54 }]) + + def test_change_tax_line_account_when_tax_zero_percent(self): + """ + This test checks the following flow: + - Invoice with three invoice lines: + • One with tax > 0% + • One with tax == 0% + • One with tax == 0 fixed + - On line_ids, change the account of the tax line + The tax line should still be there and the account should be effectively changed + """ + tax_0_percent, tax_0_fixed = self.env['account.tax'].create([ + { + 'name': '0%', + 'amount_type': 'percent', + 'amount': 0, + 'sequence': 10, + }, + { + 'name': '0 fixed', + 'amount_type': 'fixed', + 'amount': 0, + 'sequence': 10, + } + ]) + + + new_account_revenue = self.company_data['default_account_revenue'].copy() + + invoice = self._create_invoice([(500, self.percent_tax_1), (300, tax_0_percent), (100, tax_0_fixed)], inv_type='out_invoice') + + self.assertRecordValues(invoice.line_ids, [ + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': 'xxxx', + 'tax_ids': self.percent_tax_1.ids, + 'debit': 0.0, + 'credit': 500.0, + }, + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': 'xxxx', + 'tax_ids': tax_0_percent.ids, + 'debit': 0.0, + 'credit': 300.0, + }, + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': 'xxxx', + 'tax_ids': tax_0_fixed.ids, + 'debit': 0.0, + 'credit': 100.0, + }, + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': '21%', + 'tax_ids': [], + 'debit': 0.0, + 'credit': 105.0, + }, + { + 'account_id': self.company_data['default_account_receivable'].id, + 'name': '', + 'tax_ids': [], + 'debit': 1005.0, + 'credit': 0.0, + } + ]) + + with Form(invoice) as invoice_form: + with invoice_form.line_ids.edit(3) as line: + line.account_id = new_account_revenue + + self.assertRecordValues(invoice.line_ids, [ + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': 'xxxx', + 'tax_ids': self.percent_tax_1.ids, + 'debit': 0.0, + 'credit': 500.0, + }, + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': 'xxxx', + 'tax_ids': tax_0_percent.ids, + 'debit': 0.0, + 'credit': 300.0, + }, + { + 'account_id': self.company_data['default_account_revenue'].id, + 'name': 'xxxx', + 'tax_ids': tax_0_fixed.ids, + 'debit': 0.0, + 'credit': 100.0, + }, + { + 'account_id': new_account_revenue.id, + 'name': '21%', + 'tax_ids': [], + 'debit': 0.0, + 'credit': 105.0, + }, + { + 'account_id': self.company_data['default_account_receivable'].id, + 'name': '', + 'tax_ids': [], + 'debit': 1005.0, + 'credit': 0.0, + } + ])