From 08b12bbdc73ad791984fa80b3af39f62bb4bbbbf Mon Sep 17 00:00:00 2001 From: jbw Date: Mon, 22 Nov 2021 12:42:29 +0000 Subject: [PATCH] [FIX] account: fix misc reverse tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this fix, all moves of type “entry“ were considered as misc operations in regard to repartition tags and the tax report. And only moves of type “out_refund” and “in_refund” were considered refunds. Now reverse entries with sale/purchase taxes get their tags set accordingly to repartition lines. Account D C Tax Tax Grids 700000 Ventes en Belgique (marchandises) 0 1000 21% +03 451000 T.V.A. à payer 0 210 +54 400000 Clients 1210 0 Was reversed to: Account D C Tax Tax Grids 700000 Ventes en Belgique (marchandises) 1000 0 21% +03 451000 T.V.A. à payer 210 0 +54 400000 Clients 0 1210 Is now reversed to: Account D C Tax Tax Grids 700000 Ventes en Belgique (marchandises) 1000 0 21% +49 451000 T.V.A. à payer 210 0 +64 400000 Clients 0 1210 closes odoo/odoo#80427 X-original-commit: a337d5d5b3886eabbdc8de95eb615dffc91d5d8e Related: odoo/enterprise#22532 Signed-off-by: Olivier Colson --- addons/account/models/account_move.py | 19 +++++++++++++------ .../tests/test_account_move_reconcile.py | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 42d526d7d08..f0372c241f6 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2608,10 +2608,6 @@ class AccountMove(models.Model): # invoice_repartition_line => refund_repartition_line mapping = {} - # Do nothing if the move is not a credit note. - if move_vals['move_type'] not in ('out_refund', 'in_refund'): - return mapping - for line_command in move_vals.get('line_ids', []): line_vals = line_command[2] # (0, 0, {...}) @@ -2631,7 +2627,18 @@ class AccountMove(models.Model): move_vals = self.with_context(include_business_fields=True).copy_data(default=default_values)[0] - tax_repartition_lines_mapping = compute_tax_repartition_lines_mapping(move_vals) + is_refund = False + if move_vals['move_type'] in ('out_refund', 'in_refund'): + is_refund = True + elif move_vals['move_type'] == 'entry': + base_lines = self.line_ids.filtered(lambda line: line.tax_ids) + tax_type = set(base_lines.tax_ids.mapped('type_tax_use')) + if tax_type == {'sale'} and sum(base_lines.mapped('debit')) == 0: + is_refund = True + elif tax_type == {'purchase'} and sum(base_lines.mapped('credit')) == 0: + is_refund = True + + tax_repartition_lines_mapping = compute_tax_repartition_lines_mapping(move_vals) if is_refund else {} for line_command in move_vals.get('line_ids', []): line_vals = line_command[2] # (0, 0, {...}) @@ -2650,7 +2657,7 @@ class AccountMove(models.Model): 'credit': balance < 0.0 and -balance or 0.0, }) - if move_vals['move_type'] not in ('out_refund', 'in_refund'): + if not is_refund: continue # ==== Map tax repartition lines ==== diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index 6fa4e61568f..0c25ef6d9d2 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -1907,6 +1907,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): def test_reconcile_cash_basis_revert(self): ''' Ensure the cash basis journal entry can be reverted. ''' self.cash_basis_transfer_account.reconcile = True + self.cash_basis_tax_a_third_amount.cash_basis_transition_account_id = self.tax_account_1 invoice_move = self.env['account.move'].create({ 'move_type': 'entry',