[FIX] sale: fix multi-company error with partner bank

On creating Invoice for an SO, Odoo checks for available bank records for the
partner and if there few of them, it chooses the first one.

However, the first one might be from another company, which leads to
"Incompatible companies error". It may happen when user works with several
companies (few active companies in the company switcher).

Fix it by filtering available bank records by company

opw-2745339

closes odoo/odoo#95790

X-original-commit: 2617772f07a77375b49a64a8e379ffe1d6f450dd
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Signed-off-by: Ivan Elizaryev (iel) <iel@odoo.com>
This commit is contained in:
Ivan Yelizariev
2022-07-12 12:00:47 +02:00
parent bdc4b4a21b
commit e0c179b6d2
+1 -1
View File
@@ -941,7 +941,7 @@ class SaleOrder(models.Model):
'partner_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id._get_fiscal_position(self.partner_invoice_id)).id,
'partner_bank_id': self.company_id.partner_id.bank_ids[:1].id,
'partner_bank_id': self.company_id.partner_id.bank_ids.filtered(lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id,
'journal_id': journal.id, # company comes from the journal
'invoice_origin': self.name,
'invoice_payment_term_id': self.payment_term_id.id,