diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 90ce939f426dc16044041994fcc0f7f33a4bea6e..99754757674b699b00646ea309d503254f0a4e68 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1144,6 +1144,7 @@ class AccountMove(models.Model): expected_tax_rep_lines = set() current_tax_rep_lines = set() inv_recompute_all_taxes = recompute_all_taxes + has_taxes = False for line in invoice.line_ids: if line.recompute_tax_line: inv_recompute_all_taxes = True @@ -1151,6 +1152,7 @@ class AccountMove(models.Model): if line.tax_repartition_line_id: current_tax_rep_lines.add(line.tax_repartition_line_id._origin) elif line.tax_ids: + has_taxes = True if invoice.is_invoice(include_receipts=True): is_refund = invoice.move_type in ('out_refund', 'in_refund') else: @@ -1171,12 +1173,13 @@ class AccountMove(models.Model): delta_tax_rep_lines = expected_tax_rep_lines - current_tax_rep_lines # Compute taxes. - if inv_recompute_all_taxes: - invoice._recompute_tax_lines() - elif recompute_tax_base_amount: - invoice._recompute_tax_lines(recompute_tax_base_amount=True) - elif delta_tax_rep_lines and not self._context.get('move_reverse_cancel'): - invoice._recompute_tax_lines(tax_rep_lines_to_recompute=delta_tax_rep_lines) + if has_taxes or current_tax_rep_lines: + if inv_recompute_all_taxes: + invoice._recompute_tax_lines() + elif recompute_tax_base_amount: + invoice._recompute_tax_lines(recompute_tax_base_amount=True) + elif delta_tax_rep_lines and not self._context.get('move_reverse_cancel'): + invoice._recompute_tax_lines(tax_rep_lines_to_recompute=delta_tax_rep_lines) if invoice.is_invoice(include_receipts=True): diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index ec10204316d7cfe3804d7e40143896726399d4ff..ce3628cbf6fd9d238478b41b1c392fc1105eeeb9 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -486,6 +486,29 @@ class TestAccountMove(AccountTestInvoicingCommon): {'name': 'credit_line_1', 'debit': 0.0, 'credit': 1200.0, 'tax_ids': [], 'tax_line_id': False}, ]) + def test_misc_custom_tags(self): + tag = self.env['account.account.tag'].create({ + 'name': "test_misc_custom_tags", + 'applicability': 'taxes', + 'country_id': self.env.ref('base.us').id, + }) + move_form = Form(self.env['account.move'].with_context(default_move_type='entry')) + with move_form.line_ids.new() as debit_line: + debit_line.name = 'debit_line' + debit_line.account_id = self.company_data['default_account_revenue'] + debit_line.debit = 1000 + debit_line.tax_tag_ids.add(tag) + with move_form.line_ids.new() as credit_line: + credit_line.name = 'credit_line' + credit_line.account_id = self.company_data['default_account_revenue'] + credit_line.credit = 1000 + move = move_form.save() + self.assertRecordValues(move.line_ids, [ + # pylint: disable=bad-whitespace + {'debit': 1000.0, 'credit': 0.0, 'tax_tag_ids': tag.ids}, + {'debit': 0.0, 'credit': 1000.0, 'tax_tag_ids': []}, + ]) + def test_misc_prevent_unlink_posted_items(self): # You cannot remove journal items if the related journal entry is posted. self.test_move.action_post()