Skip to content

Commit 72513e9

Browse files
committed
[FIX] account : compute invoice_partner_bank_id when computing bank_partner_id
To reproduce ============ - add a bank account to *MyCompany* - create contact who has a bank account - create customer invoice for this contact - create credit note from this invoice the Bank Account of the credit note is set to *MyCompany's* bank account, where it should be the customer's account Purpose ======= when creating the credit note we don't set the field `invoice_partner_bank_id` Specification ============= to solve the issue we compute the field `invoice_partner_bank_id` when computing the field `bank_partner_id` opw-2862601 closes odoo#92660 Signed-off-by: William André (wan) <[email protected]>
1 parent cd91426 commit 72513e9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

addons/account/models/account_move.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def _get_default_invoice_incoterm(self):
216216
domain=[('exclude_from_invoice_tab', '=', False)],
217217
states={'draft': [('readonly', False)]})
218218
invoice_partner_bank_id = fields.Many2one('res.partner.bank', string='Bank Account',
219+
compute="_compute_invoice_partner_bank_id", store=True, readonly=False,
219220
help='Bank Account Number to which the invoice will be paid. A Company bank account if this is a Customer Invoice or Vendor Credit Note, otherwise a Partner bank account number.',
220221
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
221222
invoice_incoterm_id = fields.Many2one('account.incoterms', string='Incoterm',
@@ -362,7 +363,6 @@ def _onchange_partner_id(self):
362363
line.account_id = new_term_account
363364

364365
self._compute_bank_partner_id()
365-
self.invoice_partner_bank_id = self.bank_partner_id.bank_ids and self.bank_partner_id.bank_ids[0]
366366

367367
# Find the new fiscal position.
368368
delivery_partner_id = self._get_invoice_delivery_partner_id()
@@ -1071,7 +1071,13 @@ def _compute_commercial_partner_id(self):
10711071
for move in self:
10721072
move.commercial_partner_id = move.partner_id.commercial_partner_id
10731073

1074-
@api.depends('commercial_partner_id')
1074+
@api.depends('bank_partner_id')
1075+
def _compute_invoice_partner_bank_id(self):
1076+
for move in self:
1077+
filtered_bank_partner_id = move.bank_partner_id.filtered(lambda bank: bank.company_id.id in (False, move.company_id.id))
1078+
move.invoice_partner_bank_id = filtered_bank_partner_id.bank_ids[:1]
1079+
1080+
@api.depends('commercial_partner_id', 'type')
10751081
def _compute_bank_partner_id(self):
10761082
for move in self:
10771083
if move.is_outbound():
@@ -2587,7 +2593,7 @@ def action_switch_invoice_into_refund_credit_note(self):
25872593
'debit' : line_vals['credit'],
25882594
'credit' : line_vals['debit']
25892595
})
2590-
move.write({'invoice_line_ids' : [(5, 0, 0)], 'invoice_partner_bank_id': False})
2596+
move.write({'invoice_line_ids' : [(5, 0, 0)]})
25912597
move.write({'invoice_line_ids' : new_invoice_line_ids})
25922598

25932599
def _get_report_base_filename(self):

0 commit comments

Comments
 (0)