bank-payment/account_payment_purchase/models/account_move.py

34 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-03-12 16:21:19 +00:00
# Copyright 2016 Akretion (<http://www.akretion.com>).
2023-05-19 08:19:51 +00:00
# Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2022 Tecnativa - Pedro M. Baeza
2021-03-12 16:21:19 +00:00
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from flectra import _, api, models
class AccountMove(models.Model):
_inherit = "account.move"
@api.onchange("purchase_vendor_bill_id", "purchase_id")
def _onchange_purchase_auto_complete(self):
2023-05-19 08:19:51 +00:00
new_mode = self.purchase_id.payment_mode_id.id or False
new_bank = self.purchase_id.supplier_partner_bank_id.id or False
2021-03-12 16:21:19 +00:00
res = super()._onchange_purchase_auto_complete() or {}
2021-12-12 03:12:37 +00:00
if self.payment_mode_id and new_mode and self.payment_mode_id.id != new_mode:
2021-03-12 16:21:19 +00:00
res["warning"] = {
"title": _("Warning"),
"message": _("Selected purchase order have different payment mode."),
}
return res
2023-05-19 08:19:51 +00:00
if new_mode:
self.payment_mode_id = new_mode
2021-12-12 03:12:37 +00:00
if self.partner_bank_id and new_bank and self.partner_bank_id.id != new_bank:
2021-03-12 16:21:19 +00:00
res["warning"] = {
"title": _("Warning"),
"message": _("Selected purchase order have different supplier bank."),
}
return res
2023-05-19 08:19:51 +00:00
if new_bank:
self.partner_bank_id = new_bank
2021-03-12 16:21:19 +00:00
return res