Skip to content

Commit 7497fe4

Browse files
committed
[FIX] purchase_allowed_product: Improve UX
- Make use_only_supplied_product field computed, stored and not readonly - Propagation of use_only_supplied_product field to invoices
1 parent 221caf0 commit 7497fe4

9 files changed

+40
-25
lines changed

purchase_allowed_product/README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Contributors
7474

7575
* Darius Žižys
7676

77+
* Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)
78+
7779
Maintainers
7880
~~~~~~~~~~~
7981

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
# © 2016 Chafique DELLI @ Akretion
2+
# Copyright 2024 Moduon Team S.L. <info@moduon.team>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34

4-
from odoo import models
5+
from odoo import api, models
56

67

78
class AccountMove(models.Model):
89
_inherit = ["account.move", "supplied.product.mixin"]
910
_name = "account.move"
11+
12+
@api.onchange("invoice_vendor_bill_id")
13+
def _onchange_invoice_vendor_bill(self):
14+
if self.invoice_vendor_bill_id:
15+
self.use_only_supplied_product = (
16+
self.invoice_vendor_bill_id.use_only_supplied_product
17+
)
18+
return super()._onchange_invoice_vendor_bill()

purchase_allowed_product/models/purchase_order.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
2+
# Copyright 2024 Moduon Team S.L. <info@moduon.team>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34

45
from odoo import models
@@ -7,3 +8,9 @@
78
class PurchaseOrder(models.Model):
89
_inherit = ["purchase.order", "supplied.product.mixin"]
910
_name = "purchase.order"
11+
12+
def _prepare_invoice(self):
13+
self.ensure_one()
14+
invoice_vals = super()._prepare_invoice()
15+
invoice_vals["use_only_supplied_product"] = self.use_only_supplied_product
16+
return invoice_vals
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
2+
# Copyright 2024 Moduon Team S.L. <info@moduon.team>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34

45
from odoo import api, fields, models
@@ -10,13 +11,17 @@ class SuppliedProductMixin(models.AbstractModel):
1011

1112
use_only_supplied_product = fields.Boolean(
1213
string="Use only allowed products",
14+
compute="_compute_partner_id_supplied_product",
15+
store=True,
16+
readonly=False,
1317
help="If checked, only the products provided by this supplier "
1418
"will be shown.",
1519
)
1620

17-
@api.onchange("partner_id")
18-
def _onchange_partner_id_supplied_product(self):
19-
self.use_only_supplied_product = (
20-
self.partner_id.use_only_supplied_product
21-
or self.partner_id.commercial_partner_id.use_only_supplied_product
22-
)
21+
@api.depends("partner_id")
22+
def _compute_partner_id_supplied_product(self):
23+
for record in self:
24+
record.use_only_supplied_product = (
25+
record.partner_id.use_only_supplied_product
26+
or record.partner_id.commercial_partner_id.use_only_supplied_product
27+
)

purchase_allowed_product/readme/CONTRIBUTORS.rst

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
* `Via laurea <https://www.vialaurea.com>`__:
1010

1111
* Darius Žižys
12+
13+
* Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)

purchase_allowed_product/static/description/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -419,6 +418,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
419418
<li>Darius Žižys</li>
420419
</ul>
421420
</li>
421+
<li>Eduardo de Miguel (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
422422
</ul>
423423
</div>
424424
<div class="section" id="maintainers">

purchase_allowed_product/views/account_move_views.xml

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
<field name="model">account.move</field>
55
<field name="inherit_id" ref="account.view_move_form" />
66
<field name="arch" type="xml">
7-
<field name="invoice_line_ids" position="before">
7+
<xpath expr="//field[@name='partner_id']/.." position="inside">
88
<field
99
name="use_only_supplied_product"
1010
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}"
11-
class="oe_edit_only"
11+
widget="boolean_toggle"
1212
/>
13-
<label
14-
for="use_only_supplied_product"
15-
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}"
16-
class="oe_edit_only"
17-
/>
18-
</field>
13+
</xpath>
1914
<xpath
2015
expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']"
2116
position="attributes"

purchase_allowed_product/views/purchase_order_views.xml

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
<field name="model">purchase.order</field>
55
<field name="inherit_id" ref="purchase.purchase_order_form" />
66
<field name="arch" type="xml">
7-
<field name="order_line" position="before">
7+
<xpath expr="//field[@name='partner_id']/.." position="inside">
88
<field
99
name="use_only_supplied_product"
1010
attrs="{'invisible': [('state', 'not in', ('draft', 'sent'))]}"
11-
class="oe_edit_only"
11+
widget="boolean_toggle"
1212
/>
13-
<label
14-
for="use_only_supplied_product"
15-
attrs="{'invisible': [('state', 'not in', ('draft', 'sent'))]}"
16-
class="oe_edit_only"
17-
/>
18-
</field>
13+
</xpath>
1914
<xpath
2015
expr="//field[@name='order_line']/tree/field[@name='product_id']"
2116
position="attributes"

purchase_allowed_product/views/res_partner_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<field name="inherit_id" ref="base.view_partner_form" />
66
<field name="arch" type="xml">
77
<group name="purchase" position="inside">
8-
<field name="use_only_supplied_product" />
8+
<field name="use_only_supplied_product" widget="boolean_toggle" />
99
</group>
1010
</field>
1111
</record>

0 commit comments

Comments
 (0)