[FIX] account: fix misc reverse tags

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 <oco@odoo.com>
This commit is contained in:
jbw
2021-11-26 10:32:07 +00:00
parent 71f737fa12
commit 08b12bbdc7
2 changed files with 14 additions and 6 deletions
+13 -6
View File
@@ -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 ====
@@ -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',