From 4cc403772617be3579a75e6ab85d4256e405556a Mon Sep 17 00:00:00 2001 From: Pouya Malekinejad Date: Sun, 8 May 2022 17:37:46 +0000 Subject: [PATCH] [FIX] account: Tax grids stay when removing a tax from invoice line Currently, when the user removes a tax from an invoice line (tax_ids), the tax grid stays on the account move lines, after this commit, when the tax is deleted in invoice line, the related tax_tags are removed from `aml.tax_tag_ids` which is the correct behavior task ID:2843666 closes odoo/odoo#90950 Pr: #90836 X-original-commit: 27b3d3412b347ef7fb62626d5087eaf34621395a Signed-off-by: Laurent Smet --- addons/account/models/account_tax.py | 2 +- .../tests/test_account_move_out_invoice.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index 6ee67c6a765..905ae23e089 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -840,7 +840,7 @@ class AccountTax(models.Model): else: price_subtotal = currency.round(price_unit_after_discount * line_vals['quantity']) to_update_vals = { - 'tax_tag_ids': [], + 'tax_tag_ids': [Command.clear()], 'price_subtotal': price_subtotal, 'price_total': price_subtotal, } diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 5623379c812..2d451a53dec 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3416,3 +3416,36 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'credit': value['debit'], }) self.assertRecordValues(reversed_caba_move.line_ids, expected_values) + + def test_tax_grid_remove_tax(self): + # Add a tag to tax_sale_a + tax_line_tag = self.env['account.account.tag'].create({ + 'name': "Tax tag", + 'applicability': 'taxes', + 'country_id': self.company_data['company'].country_id.id, + }) + + repartition_line = self.tax_sale_a.invoice_repartition_line_ids\ + .filtered(lambda x: x.repartition_type == 'tax') + repartition_line.tag_ids |= tax_line_tag + + # Create the invoice + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'invoice_date': fields.Date.from_string('2022-02-20'), + 'partner_id': self.partner_a.id, + 'invoice_line_ids': [ + Command.create({ + 'product_id': self.product_a.id, + 'price_unit': 999.99, + 'tax_ids': [Command.set(self.product_a.taxes_id.ids)], + }), + ], + }) + + with Form(invoice) as form: + with form.invoice_line_ids.edit(0) as line_form: + line_form.tax_ids.clear() + + # Tags should be empty since the tax has been removed from the invoice line + self.assertRecordValues(invoice.line_ids, [{'tax_tag_ids': []}, {'tax_tag_ids': []}])