Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FW] account_payment_purchase: multiple ports from 14.0 #1357

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions account_payment_purchase/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2016 Akretion (<http://www.akretion.com>).
# Copyright 2017 Tecnativa - Vicent Cubells.
# 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
Expand All @@ -10,31 +11,23 @@ class AccountMove(models.Model):

@api.onchange("purchase_vendor_bill_id", "purchase_id")
def _onchange_purchase_auto_complete(self):

new_mode = (
self.purchase_vendor_bill_id.purchase_order_id.payment_mode_id.id
or self.purchase_id.payment_mode_id.id
)
new_bank = (
self.purchase_vendor_bill_id.purchase_order_id.supplier_partner_bank_id.id
or self.purchase_id.supplier_partner_bank_id.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()._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
elif self.payment_mode_id.id != new_mode:
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
elif self.partner_bank_id.id != new_bank:
if new_bank:
self.partner_bank_id = new_bank
return res
4 changes: 3 additions & 1 deletion account_payment_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def onchange_partner_id(self):
self.supplier_partner_bank_id = self._get_default_supplier_partner_bank(
self.partner_id
)
self.payment_mode_id = self.partner_id.supplier_payment_mode_id
self.payment_mode_id = self.with_company(
self.company_id
).partner_id.supplier_payment_mode_id
else:
self.supplier_partner_bank_id = False
self.payment_mode_id = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def test_from_purchase_order_invoicing(self):
result and result.get("warning", {}).get("title", False), "Warning"
)

def test_from_purchase_order_empty_mode_invoicing(self):
self.purchase.payment_mode_id = False
self.purchase.button_confirm()
invoice_form = Form(
self.env["account.move"].with_context(default_type="in_invoice")
)
invoice_form.purchase_id = self.purchase
self.assertEqual(invoice_form.payment_mode_id, self.payment_mode)

def test_from_purchase_order_invoicing_bank(self):
# Test partner_bank
product = self.env["product.product"].create({"name": "Test product"})
Expand Down
Loading