mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
If the user set no purchase order on an invoice, it makes no sense to warn them about details being different. The onchange for the purchase_id field is not only run when the user sets a purchase, but also when they open a new, empty form view. Normally this causes no problems, but in some contexts the user may want to define defaults for the payment term or bank account. If these are defined, they will not be False on a new draft invoice, but there will be no purchase, so the code interpreted the values as having "changed". We avoid this by simply not checking for changes if no purchase has been set on the invoice.
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
# Copyright 2016 Akretion (<http://www.akretion.com>).
|
|
# Copyright 2017 Tecnativa - Vicent Cubells.
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
from odoo import _, api, models
|
|
|
|
|
|
class AccountInvoice(models.Model):
|
|
_inherit = "account.invoice"
|
|
|
|
@api.onchange('purchase_id')
|
|
def purchase_order_change(self):
|
|
new_purchase = self.purchase_id
|
|
new_mode = self.purchase_id.payment_mode_id.id or False
|
|
new_bank = self.purchase_id.supplier_partner_bank_id.id or False
|
|
res = super(AccountInvoice, self).purchase_order_change()
|
|
if not new_purchase:
|
|
# User did not add a purchase order, no need to warn
|
|
return res
|
|
if self.payment_mode_id and self.payment_mode_id.id != new_mode:
|
|
res['warning'] = {
|
|
'title': _('Warning'),
|
|
'message': _('Selected purchase order have different '
|
|
'payment mode.'),
|
|
}
|
|
return res
|
|
self.payment_mode_id = new_mode
|
|
if self.partner_bank_id and self.partner_bank_id.id != new_bank:
|
|
res['warning'] = {
|
|
'title': _('Warning'),
|
|
'message': _('Selected purchase order have different '
|
|
'supplier bank.'),
|
|
}
|
|
return res
|
|
self.partner_bank_id = new_bank
|