[FIX] account: Prevent exchange diff entry with full refund

- create an invoice with a CABA tax
- full refund it using 'add credit note', 'cancel' mode.
=> No CABA entry generated but an exchange difference journal entry
has been created.

This is because the CABA entry is not generated in case of full refund
thanks to the 'move_reverse_cancel' context key. However, this key is not
preventing the generation of the exchange journal entry for CABA.

opw-3321897

X-original-commit: 01799569bb3d450719968c77c1d4bb4c9ff31fdb

[FIX] account: Fix 'reverse_move_cancel' context key in reversal wizard

When reversing an invoice using the reversal wizard, the reverse_move_cancel is not passed to
the reconciliation and then, we are not able to prevent the generation of the cash basis entry.
This is because the reversal wizard 1) posts the credit note and 2) reconcile it with the invoice.
However, the reconciliation is done directly during the post but forcing the 'reverse_move_cancel'
key to 'False'. Then, at step 2), there is nothing left to reconcile.
So the reconciliation is never called using the 'reverse_move_cancel' context key set to true.

closes odoo/odoo#122732

X-original-commit: 42a8b091c4085c5caa97c838342a1ca0748c403c
Signed-off-by: Laurent Smet <las@odoo.com>
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Laurent Smet
2023-05-26 21:16:28 +02:00
parent 15f1913225
commit 6b51c8b6ed
3 changed files with 42 additions and 4 deletions
+1 -2
View File
@@ -3401,7 +3401,6 @@ class AccountMove(models.Model):
# Reconcile moves together to cancel the previous one.
if cancel:
reverse_moves.with_context(move_reverse_cancel=cancel)._post(soft=False)
reverse_moves = self._reconcile_reversed_moves(reverse_moves, cancel)
return reverse_moves
@@ -3533,7 +3532,7 @@ class AccountMove(models.Model):
'posted_before': True,
})
draft_reverse_moves.reversed_entry_id._reconcile_reversed_moves(draft_reverse_moves, False)
draft_reverse_moves.reversed_entry_id._reconcile_reversed_moves(draft_reverse_moves, self._context.get('move_reverse_cancel', False))
for invoice in to_post:
invoice.message_subscribe([
+3 -2
View File
@@ -2332,8 +2332,10 @@ class AccountMoveLine(models.Model):
)
# Exchange difference for cash basis entries.
# If we are fully reversing the entry, no need to fix anything since the journal entry
# is exactly the mirror of the source journal entry.
caba_lines_to_reconcile = None
if is_cash_basis_needed(involved_amls.account_id):
if is_cash_basis_needed(involved_amls.account_id) and not self._context.get('move_reverse_cancel'):
caba_lines_to_reconcile = involved_amls._add_exchange_difference_cash_basis_vals(exchange_diff_values)
# Prepare the exchange difference.
@@ -2691,7 +2693,6 @@ class AccountMoveLine(models.Model):
caba_reconcile_key = (transition_line.move_id, transition_line.account_id, transition_line.tax_repartition_line_id)
caba_lines_to_reconcile[caba_reconcile_key] |= transition_line
# ==========================================================================
# Generate the exchange difference journal items:
# - to reset the balance of all transfer account to zero.
@@ -4564,3 +4564,41 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon):
}
]
self.assertRecordValues(caba_move.line_ids, expected_values)
def test_cash_basis_full_refund(self):
""" Ensure the caba entry and the exchange difference journal entry for caba are not created in case of full
refund.
"""
self.env.company.tax_exigibility = True
tax = self.env['account.tax'].create({
'name': 'cash basis 20%',
'type_tax_use': 'purchase',
'amount': 20,
'tax_exigibility': 'on_payment',
'cash_basis_transition_account_id': self.cash_basis_transfer_account.id,
})
invoice = self.init_invoice('out_invoice', post=True, amounts=[1000.0], taxes=tax)
# Reverse completely the invoice.
credit_note_wizard = self.env['account.move.reversal']\
.with_context({'active_ids': invoice.ids, 'active_model': 'account.move'})\
.create({
'reason': 'test_cash_basis_full_refund',
'journal_id': invoice.journal_id.id,
})
action_values = credit_note_wizard.modify_moves()
self.assertRecordValues(invoice, [{'payment_state': 'reversed'}])
# Check no CABA move has been created.
cash_basis_moves = self.env['account.move']\
.search([('tax_cash_basis_origin_move_id', 'in', (invoice.id, action_values['res_id']))])
self.assertFalse(cash_basis_moves)
# No exchange journal entry created for CABA.
caba_transfer_amls = self.env['account.move.line'].search([
('account_id', '=', self.cash_basis_transfer_account.id),
('move_id.move_type', '=', 'entry'),
])
self.assertFalse(caba_transfer_amls.move_id)