diff --git a/account_payment_order/models/account_move_line.py b/account_payment_order/models/account_move_line.py index 244000a98cd..75d229f503b 100644 --- a/account_payment_order/models/account_move_line.py +++ b/account_payment_order/models/account_move_line.py @@ -3,7 +3,6 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models -from odoo.fields import first class AccountMoveLine(models.Model): @@ -70,7 +69,11 @@ def _prepare_payment_line_vals(self, payment_order): # in this case if payment_order.payment_type == "outbound": amount_currency *= -1 - partner_bank_id = self.partner_bank_id.id or first(self.partner_id.bank_ids).id + partner_bank_id = self.partner_bank_id.id + if not partner_bank_id: + partner_bank_id = self.partner_id.bank_ids.filtered( + lambda bank: not bank.company_id or bank.company_id == self.company_id + )[:1].id vals = { "order_id": payment_order.id, "partner_bank_id": partner_bank_id, diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index 0bf8443b3cf..8d7a8dfadbd 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -142,7 +142,9 @@ def payment_line_hashcode(self): def partner_id_change(self): partner_bank = False if self.partner_id.bank_ids: - partner_bank = self.partner_id.bank_ids[0] + partner_bank = self.partner_id.bank_ids.filtered( + lambda bank: not bank.company_id or bank.company_id == self.company_id + )[:1] self.partner_bank_id = partner_bank @api.onchange("move_line_id")