From e2178ba796d596c05b3549b5c2fc1f59cc561fcb Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Fri, 10 Jun 2022 06:27:14 +0000 Subject: [PATCH] [REV] account: 0% tax not in tax report due This reverts commit 65b5ec4ad65f798b1d647978b5b42a49e760139a. closes odoo/odoo#93717 X-original-commit: 09eb1b725e2f8b86dc671d0f77503e49d106d14c Signed-off-by: Olivier Colson (oco) Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 22 +++-- .../test_account_move_line_tax_details.py | 85 ------------------- .../tests/test_account_move_out_invoice.py | 2 +- .../l10n_in_edi/models/account_edi_format.py | 4 +- addons/l10n_in_edi/tests/test_edi_json.py | 4 +- ...o_saxon_valuation_reconciliation_common.py | 2 +- 6 files changed, 20 insertions(+), 99 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 0954e379559..9c771a0eba1 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -715,6 +715,9 @@ class AccountMove(models.Model): currency = self.env['res.currency'].browse(update_vals['currency_id']) tax_amount = update_vals.pop('tax_amount') + if currency.is_zero(tax_amount): + return True + tax_rep = self.env['account.tax.repartition.line'].browse(update_vals['tax_repartition_line_id']) tax_id = update_vals.pop('tax_id') if tax_id == tax_rep.tax_id.id: @@ -780,7 +783,7 @@ class AccountMove(models.Model): # ===== TAX LINES ===== - # Tax lines that are no longer neeeded. + # Tax lines that are no longer needed. if not recompute_tax_base_amount: for tax_line_vals in tax_results['tax_lines_to_delete']: tax_line = tax_line_vals['record'] @@ -789,19 +792,20 @@ class AccountMove(models.Model): # Newly created tax lines. if not recompute_tax_base_amount: for tax_line_vals in tax_results['tax_lines_to_add']: - fill_accounting_tax_vals(tax_line_vals) - line_ids_commands.append(Command.create(tax_line_vals)) + if not fill_accounting_tax_vals(tax_line_vals): + line_ids_commands.append(Command.create(tax_line_vals)) # Update of existing tax lines. for tax_line_vals, to_update in tax_results['tax_lines_to_update']: tax_line = tax_line_vals['record'] - fill_accounting_tax_vals(to_update) - - if recompute_tax_base_amount: - fields_to_update = ('tax_base_amount',) + if fill_accounting_tax_vals(to_update): + line_ids_commands.append(Command.unlink(tax_line.id)) else: - fields_to_update = ('tax_base_amount', 'amount_currency', 'debit', 'credit') - line_ids_commands.append(Command.update(tax_line.id, {k: v for k, v in to_update.items() if k in fields_to_update})) + if recompute_tax_base_amount: + fields_to_update = ('tax_base_amount',) + else: + fields_to_update = ('tax_base_amount', 'amount_currency', 'debit', 'credit') + line_ids_commands.append(Command.update(tax_line.id, {k: v for k, v in to_update.items() if k in fields_to_update})) (self.update if in_draft_mode else self.write)({'line_ids': line_ids_commands}) diff --git a/addons/account/tests/test_account_move_line_tax_details.py b/addons/account/tests/test_account_move_line_tax_details.py index 55c94463314..e878393be48 100644 --- a/addons/account/tests/test_account_move_line_tax_details.py +++ b/addons/account/tests/test_account_move_line_tax_details.py @@ -1168,91 +1168,6 @@ class TestAccountTaxDetailsReport(AccountTestInvoicingCommon): ) self.assertTotalAmounts(invoice, tax_details) - def test_zero_amount_tax(self): - """ Ensure the tax details is generated for 0% tax. """ - zero_tax = self.env['account.tax'].create({ - 'name': "zero_tax", - 'amount_type': 'percent', - 'amount': 0.0, - }) - - invoice = self.env['account.move'].create({ - 'move_type': 'out_invoice', - 'partner_id': self.partner_a.id, - 'invoice_date': '2019-01-01', - 'invoice_line_ids': [ - Command.create({ - 'name': 'line1', - 'account_id': self.company_data['default_account_revenue'].id, - 'price_unit': 1000.0, - 'tax_ids': [Command.set(zero_tax.ids)], - }), - Command.create({ - 'name': 'line2', - 'account_id': self.company_data['default_account_revenue'].id, - 'price_unit': 1000.0, - 'tax_ids': [Command.set(zero_tax.ids)], - }), - ] - }) - base_lines, tax_lines = self._dispatch_move_lines(invoice) - - tax_details = self._get_tax_details() - self.assertTaxDetailsValues( - tax_details, - [ - { - 'base_line_id': base_lines[0].id, - 'tax_line_id': tax_lines[0].id, - 'base_amount': -1000.0, - 'tax_amount': 0.0, - }, - { - 'base_line_id': base_lines[1].id, - 'tax_line_id': tax_lines[0].id, - 'base_amount': -1000.0, - 'tax_amount': 0.0, - }, - ], - ) - self.assertTotalAmounts(invoice, tax_details) - - # Same with a group of taxes - - tax_group = self.env['account.tax'].create({ - 'name': "tax_group", - 'amount_type': 'group', - 'children_tax_ids': [Command.set(zero_tax.ids)], - }) - - invoice.write({ - 'invoice_line_ids': [ - Command.update(base_lines[0].id, {'tax_ids': [Command.set(tax_group.ids)]}), - Command.update(base_lines[1].id, {'tax_ids': [Command.set(tax_group.ids)]}), - ], - }) - base_lines, tax_lines = self._dispatch_move_lines(invoice) - - tax_details = self._get_tax_details() - self.assertTaxDetailsValues( - tax_details, - [ - { - 'base_line_id': base_lines[0].id, - 'tax_line_id': tax_lines[0].id, - 'base_amount': -1000.0, - 'tax_amount': 0.0, - }, - { - 'base_line_id': base_lines[1].id, - 'tax_line_id': tax_lines[0].id, - 'base_amount': -1000.0, - 'tax_amount': 0.0, - }, - ], - ) - self.assertTotalAmounts(invoice, tax_details) - def test_amounts_sign(self): for tax_sign in (1, -1): tax = self.env['account.tax'].create({ diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 430034cd700..94ded3675d8 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3063,7 +3063,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): }) self.assertEqual(len(invoice.invoice_line_ids), 1) - self.assertEqual(len(invoice.line_ids), 3) + self.assertEqual(len(invoice.line_ids), 2) def test_out_invoice_recomputation_receivable_lines(self): ''' Test a tricky specific case caused by some framework limitations. Indeed, when diff --git a/addons/l10n_in_edi/models/account_edi_format.py b/addons/l10n_in_edi/models/account_edi_format.py index 6cb7a751406..152178c1972 100644 --- a/addons/l10n_in_edi/models/account_edi_format.py +++ b/addons/l10n_in_edi/models/account_edi_format.py @@ -290,7 +290,9 @@ class AccountEdiFormat(models.Model): This method is call for rounding. If anything is wrong with rounding then we quick fix in method """ - return round(amount, precision_digits) + value = round(amount, precision_digits) + # avoid -0.0 + return value if value else 0.0 def _get_l10n_in_edi_line_details(self, index, line, line_tax_details, sign): """ diff --git a/addons/l10n_in_edi/tests/test_edi_json.py b/addons/l10n_in_edi/tests/test_edi_json.py index 4abc1742dd4..86ba0c00a4f 100644 --- a/addons/l10n_in_edi/tests/test_edi_json.py +++ b/addons/l10n_in_edi/tests/test_edi_json.py @@ -110,7 +110,7 @@ class TestEdiJson(AccountTestInvoicingCommon): "ItemList": [{ "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "01111", "Qty": 1.0, "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 1000.0, "AssAmt": 0.0, - "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0, + "GstRt": 0.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0, "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0, "OthChrg": 0.0, "TotItemVal": 0.0}], "ValDtls": {"AssVal": 0.0, "CgstVal": 0.0, "SgstVal": 0.0, "IgstVal": 0.0, "CesVal": 0.0, @@ -125,7 +125,7 @@ class TestEdiJson(AccountTestInvoicingCommon): "ItemList": [{ "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "01111", "Qty": 0.0, "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 0.0, "Discount": 0.0, "AssAmt": 0.0, - "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0, + "GstRt": 0.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0, "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0, "OthChrg": 0.0, "TotItemVal": 0.0}], }) diff --git a/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py b/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py index 1da8b017ada..d611af5c0bc 100644 --- a/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py +++ b/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py @@ -80,7 +80,7 @@ class ValuationReconciliationTestCommon(AccountTestInvoicingCommon): def check_reconciliation(self, invoice, picking, full_reconcile=True, operation='purchase'): interim_account_id = self.company_data['default_account_stock_in'].id if operation == 'purchase' else self.company_data['default_account_stock_out'].id - invoice_line = invoice.line_ids.filtered(lambda line: line.account_id.id == interim_account_id and not line.tax_line_id) + invoice_line = invoice.line_ids.filtered(lambda line: line.account_id.id == interim_account_id) stock_moves = picking.move_ids