diff --git a/account_payment_purchase/README.rst b/account_payment_purchase/README.rst index 42f9f58f0..1af3027ca 100644 --- a/account_payment_purchase/README.rst +++ b/account_payment_purchase/README.rst @@ -7,7 +7,7 @@ Account Payment Purchase !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:8d93c85e8df02a578609972f9e3fc8161a0fb18ef743faa25defb0840a17d845 + !! source digest: sha256:8bb70e483c7735270307f2b148fe836015177c7ee199e05dcfc95429696b9832 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/account_payment_purchase/__manifest__.py b/account_payment_purchase/__manifest__.py index 89cb4a503..5043e153f 100644 --- a/account_payment_purchase/__manifest__.py +++ b/account_payment_purchase/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Payment Purchase", - "version": "16.0.1.0.0", + "version": "16.0.2.0.0", "category": "Banking addons", "license": "AGPL-3", "summary": "Adds Bank Account and Payment Mode on Purchase Orders", diff --git a/account_payment_purchase/models/purchase_order.py b/account_payment_purchase/models/purchase_order.py index 88dc46979..8021dda8b 100644 --- a/account_payment_purchase/models/purchase_order.py +++ b/account_payment_purchase/models/purchase_order.py @@ -10,16 +10,26 @@ class PurchaseOrder(models.Model): supplier_partner_bank_id = fields.Many2one( comodel_name="res.partner.bank", + compute="_compute_payment_mode", + readonly=False, + store=True, + precompute=True, string="Supplier Bank Account", - domain="[('partner_id', '=', partner_id)]", + domain="[('partner_id', '=', partner_id), ('company_id', 'in', [False, company_id])]", + check_company=True, help="Select the bank account of your supplier on which your company " "should send the payment. This field is copied from the partner " "and will be copied to the supplier invoice.", ) payment_mode_id = fields.Many2one( comodel_name="account.payment.mode", + compute="_compute_payment_mode", + readonly=False, + store=True, + precompute=True, string="Payment Mode", - domain="[('payment_type', '=', 'outbound')]", + domain="[('payment_type', '=', 'outbound'), ('company_id', '=', company_id)]", + check_company=True, ) @api.model @@ -31,15 +41,14 @@ class PurchaseOrder(models.Model): or False ) - @api.onchange("partner_id", "company_id") - def onchange_partner_id(self): - ret = super().onchange_partner_id() - if self.partner_id: - 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 - else: - self.supplier_partner_bank_id = False - self.payment_mode_id = False - return ret + @api.depends("partner_id", "company_id") + def _compute_payment_mode(self): + for order in self: + if order.partner_id: + order.supplier_partner_bank_id = ( + order._get_default_supplier_partner_bank(order.partner_id) + ) + order.payment_mode_id = order.partner_id.supplier_payment_mode_id + else: + order.supplier_partner_bank_id = False + order.payment_mode_id = False diff --git a/account_payment_purchase/static/description/index.html b/account_payment_purchase/static/description/index.html index 320ebf3e7..8d3e601b8 100644 --- a/account_payment_purchase/static/description/index.html +++ b/account_payment_purchase/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:8d93c85e8df02a578609972f9e3fc8161a0fb18ef743faa25defb0840a17d845 +!! source digest: sha256:8bb70e483c7735270307f2b148fe836015177c7ee199e05dcfc95429696b9832 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
This module adds 2 fields on purchase orders: Bank Account and Payment
diff --git a/account_payment_purchase/tests/test_account_payment_purchase.py b/account_payment_purchase/tests/test_account_payment_purchase.py
index 1f1501c79..e772c54cd 100644
--- a/account_payment_purchase/tests/test_account_payment_purchase.py
+++ b/account_payment_purchase/tests/test_account_payment_purchase.py
@@ -2,7 +2,7 @@
# Copyright 2017 Tecnativa - Vicent Cubells
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
-from odoo import fields
+from odoo import Command, fields
from odoo.tests import TransactionCase, tagged
@@ -50,7 +50,7 @@ class TestAccountPaymentPurchase(TransactionCase):
"name": "Test buy product",
"uom_id": cls.uom_id,
"uom_po_id": cls.uom_id,
- "seller_ids": [(0, 0, {"partner_id": cls.partner.id})],
+ "seller_ids": [Command.create({"partner_id": cls.partner.id})],
}
)
cls.purchase = cls.env["purchase.order"].create(
@@ -58,9 +58,7 @@ class TestAccountPaymentPurchase(TransactionCase):
"partner_id": cls.partner.id,
"payment_mode_id": cls.payment_mode.id,
"order_line": [
- (
- 0,
- 0,
+ Command.create(
{
"name": "Test line",
"product_qty": 1.0,
@@ -68,7 +66,7 @@ class TestAccountPaymentPurchase(TransactionCase):
"product_uom": cls.uom_id,
"date_planned": fields.Datetime.today(),
"price_unit": 1.0,
- },
+ }
)
],
}
diff --git a/account_payment_purchase/views/purchase_order_view.xml b/account_payment_purchase/views/purchase_order_view.xml
index c2fa9cb1f..72844016b 100644
--- a/account_payment_purchase/views/purchase_order_view.xml
+++ b/account_payment_purchase/views/purchase_order_view.xml
@@ -9,11 +9,7 @@