account_payment_purchase: replace api.onchange by computed field on purchase.order

Add check_company=True on the 2 fields of purchase.order
This commit is contained in:
Alexis de Lattre
2023-11-05 16:33:14 +01:00
committed by David Ramia
parent 5dc27e9f13
commit 30204f66e9
6 changed files with 31 additions and 28 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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

View File

@@ -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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-payment/tree/16.0/account_payment_purchase"><img alt="OCA/bank-payment" src="https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-payment-16-0/bank-payment-16-0-account_payment_purchase"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds 2 fields on purchase orders: <em>Bank Account</em> and <em>Payment

View File

@@ -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,
},
}
)
],
}

View File

@@ -9,11 +9,7 @@
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="payment_term_id" position="after">
<field
name="payment_mode_id"
domain="[('payment_type', '=', 'outbound')]"
widget="selection"
/>
<field name="payment_mode_id" />
<field name="supplier_partner_bank_id" />
</field>
</field>