Merge PR #1291 into 16.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2024-06-17 08:33:55 +00:00
3 changed files with 20 additions and 16 deletions

View File

@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import account_move, purchase_order
from . import account_move
from . import purchase_order

View File

@@ -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
@@ -10,16 +11,8 @@ 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"] = {
@@ -27,7 +20,7 @@ class AccountMove(models.Model):
"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"] = {
@@ -35,6 +28,6 @@ class AccountMove(models.Model):
"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

View File

@@ -3,7 +3,7 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import Command, fields
from odoo.tests import TransactionCase, tagged
from odoo.tests import Form, TransactionCase, tagged
@tagged("-at_install", "post_install")
@@ -112,6 +112,17 @@ class TestAccountPaymentPurchase(TransactionCase):
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_move_type="in_invoice")
)
invoice_form.purchase_vendor_bill_id = self.env["purchase.bill.union"].browse(
-self.purchase.id
)
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"})