diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 082d5656edc..1d86c79c2f0 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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([ diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index a8d704c8be2..b1b467c711a 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -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. diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index bf70a2a2f55..217ddf19a29 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -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)