Skip to content

Commit

Permalink
[FIX] account: Fix invoice reversing default bank
Browse files Browse the repository at this point in the history
Problem
---------
Currently, when reversing a move, the current company is used as
recipient bank.

1. Set a bank on a partner A
2. Go to Accounting
3. Set A as the customer of the invoice
4. Set a bank under 'recipient bank' in Other Info tab
5. Post the invoice
6. "Add Credit Note"
7. Fill in with wathever and press Reverse
-> The Other Info tab of the reverse move has the company bank and not
the customer's

Objective
---------
Obtain a similar behavior as when a credit note is created directly:
have the customer's bank set as recipient bank.

Solution
---------
Provide a default bank id that is set, if possible, to one of the
customer's bank.

opw-4035448

closes odoo#173640

Signed-off-by: Wala Gauthier (gawa) <gawa@odoo.com>
  • Loading branch information
aboo-odoo committed Aug 14, 2024
1 parent d8f9cae commit c1ea29e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions addons/account/tests/test_account_move_in_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,11 @@ def test_in_invoice_onchange_past_invoice_1(self):
def test_in_invoice_create_refund(self):
self.invoice.action_post()

bank1 = self.env['res.partner.bank'].create({
'acc_number': 'BE43798822936101',
'partner_id': self.partner_a.id,
})

move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=self.invoice.ids).create({
'date': fields.Date.from_string('2019-02-01'),
'reason': 'no reason',
Expand Down Expand Up @@ -1300,6 +1305,7 @@ def test_in_invoice_create_refund(self):
'state': 'draft',
'ref': 'Reversal of: %s, %s' % (self.invoice.name, move_reversal.reason),
'payment_state': 'not_paid',
'partner_bank_id': bank1.id,
})

move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=self.invoice.ids).create({
Expand Down
10 changes: 9 additions & 1 deletion addons/account/wizard/account_move_reversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ def reverse_moves(self):
moves = self.move_ids

# Create default values.
bank_ids = self.env['res.partner.bank'].search([
('partner_id', 'in', moves.commercial_partner_id.ids),
('company_id', 'in', moves.company_id.ids + [False]),
], order='sequence DESC')
partner_to_bank = {bank.partner_id: bank for bank in bank_ids}
default_values_list = []
for move in moves:
default_values_list.append(self._prepare_default_reversal(move))
default_values_list.append({
'partner_bank_id': partner_to_bank.get(move.commercial_partner_id, self.env['res.partner.bank']).id,
**self._prepare_default_reversal(move),
})

batches = [
[self.env['account.move'], [], True], # Moves to be cancelled by the reverses.
Expand Down

0 comments on commit c1ea29e

Please sign in to comment.