diff --git a/sale_order_type/models/__init__.py b/sale_order_type/models/__init__.py index 7f1eefb9b99..2cac95b9e85 100644 --- a/sale_order_type/models/__init__.py +++ b/sale_order_type/models/__init__.py @@ -5,3 +5,4 @@ from . import res_partner from . import account_move from . import res_currency +from . import account_payment diff --git a/sale_order_type/models/account_payment.py b/sale_order_type/models/account_payment.py new file mode 100644 index 00000000000..0b7b1ca689d --- /dev/null +++ b/sale_order_type/models/account_payment.py @@ -0,0 +1,24 @@ +from odoo import api, models + + +class AccountPayment(models.Model): + _inherit = "account.payment" + + @api.depends("available_partner_bank_ids", "journal_id") + def _compute_partner_bank_id(self): + """ + If the selected account is in the available accounts then the change is not made. + """ + partner_bank_by_pay = {} + for payment in self: + partner_bank_by_pay[payment.id] = payment.partner_bank_id + res = super(AccountPayment, self)._compute_partner_bank_id() + for payment in self: + if ( + partner_bank_by_pay.get(payment.id, False) + and partner_bank_by_pay.get(payment.id) + in payment.available_partner_bank_ids + ): + payment.partner_bank_id = partner_bank_by_pay.get(payment.id) + + return res \ No newline at end of file