Files
bank-payment/account_payment_purchase/models/account_move.py
Pedro M. Baeza e4d4c113e6 [FIX] account_payment_purchase: Don't propagate empty payment mode
Steps to reproduce the problem:

- Have a partner without payment mode.
- Create a PO with such partner.
- No payment mode is filled.
- Now fill the payment mode in the partner.
- Create the invoice for the PO.

Current behavior:

The invoice has empty payment mode.

Expected behavior:

The invoice has the partner payment mode. Someone may think that having
no payment mode in the PO may prevail over the partner's payment mode,
or even their flows may consist in empyting the payment mode in the PO
for not binding it with anything yet, but that strategy has more holes
than the one implemented here, as the flow presented proves.

You can then use another one like having an extra payment mode
"Undetermined" or similar for doing such classification as a more
resilient strategy.

It includes a regression test that fails before the change and now is
correct.

TT38608
2024-06-13 10:40:11 -05:00

34 lines
1.3 KiB
Python

# Copyright 2016 Akretion (<http://www.akretion.com>).
# Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2022 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, models
class AccountMove(models.Model):
_inherit = "account.move"
@api.onchange("purchase_vendor_bill_id", "purchase_id")
def _onchange_purchase_auto_complete(self):
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()._onchange_purchase_auto_complete() or {}
if self.payment_mode_id and new_mode and self.payment_mode_id.id != new_mode:
res["warning"] = {
"title": _("Warning"),
"message": _("Selected purchase order have different payment mode."),
}
return res
if new_mode:
self.payment_mode_id = new_mode
if self.partner_bank_id and new_bank and self.partner_bank_id.id != new_bank:
res["warning"] = {
"title": _("Warning"),
"message": _("Selected purchase order have different supplier bank."),
}
return res
if new_bank:
self.partner_bank_id = new_bank
return res