Skip to content

Commit

Permalink
[FIX] purchase_allowed_product: Improve UX
Browse files Browse the repository at this point in the history
- Make use_only_supplied_product field computed, stored and not readonly
- Propagation of use_only_supplied_product field to invoices
  • Loading branch information
Shide committed Jan 23, 2024
1 parent 221caf0 commit 7497fe4
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 25 deletions.
2 changes: 2 additions & 0 deletions purchase_allowed_product/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Contributors

* Darius Žižys

* Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)

Maintainers
~~~~~~~~~~~

Expand Down
11 changes: 10 additions & 1 deletion purchase_allowed_product/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# © 2016 Chafique DELLI @ Akretion
# Copyright 2024 Moduon Team S.L. <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
from odoo import api, models


class AccountMove(models.Model):
_inherit = ["account.move", "supplied.product.mixin"]
_name = "account.move"

@api.onchange("invoice_vendor_bill_id")
def _onchange_invoice_vendor_bill(self):
if self.invoice_vendor_bill_id:
self.use_only_supplied_product = (

Check warning on line 15 in purchase_allowed_product/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

purchase_allowed_product/models/account_move.py#L15

Added line #L15 was not covered by tests
self.invoice_vendor_bill_id.use_only_supplied_product
)
return super()._onchange_invoice_vendor_bill()

Check warning on line 18 in purchase_allowed_product/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

purchase_allowed_product/models/account_move.py#L18

Added line #L18 was not covered by tests
7 changes: 7 additions & 0 deletions purchase_allowed_product/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# Copyright 2024 Moduon Team S.L. <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
Expand All @@ -7,3 +8,9 @@
class PurchaseOrder(models.Model):
_inherit = ["purchase.order", "supplied.product.mixin"]
_name = "purchase.order"

def _prepare_invoice(self):
self.ensure_one()
invoice_vals = super()._prepare_invoice()
invoice_vals["use_only_supplied_product"] = self.use_only_supplied_product
return invoice_vals
17 changes: 11 additions & 6 deletions purchase_allowed_product/models/supplied_product_mixin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# Copyright 2024 Moduon Team S.L. <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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

use_only_supplied_product = fields.Boolean(
string="Use only allowed products",
compute="_compute_partner_id_supplied_product",
store=True,
readonly=False,
help="If checked, only the products provided by this supplier "
"will be shown.",
)

@api.onchange("partner_id")
def _onchange_partner_id_supplied_product(self):
self.use_only_supplied_product = (
self.partner_id.use_only_supplied_product
or self.partner_id.commercial_partner_id.use_only_supplied_product
)
@api.depends("partner_id")
def _compute_partner_id_supplied_product(self):
for record in self:
record.use_only_supplied_product = (
record.partner_id.use_only_supplied_product
or record.partner_id.commercial_partner_id.use_only_supplied_product
)
2 changes: 2 additions & 0 deletions purchase_allowed_product/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
* `Via laurea <https://www.vialaurea.com>`__:

* Darius Žižys

* Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)
2 changes: 1 addition & 1 deletion purchase_allowed_product/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -419,6 +418,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Darius Žižys</li>
</ul>
</li>
<li>Eduardo de Miguel (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
11 changes: 3 additions & 8 deletions purchase_allowed_product/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<field name="invoice_line_ids" position="before">
<xpath expr="//field[@name='partner_id']/.." position="inside">
<field
name="use_only_supplied_product"
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}"
class="oe_edit_only"
widget="boolean_toggle"
/>
<label
for="use_only_supplied_product"
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}"
class="oe_edit_only"
/>
</field>
</xpath>
<xpath
expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']"
position="attributes"
Expand Down
11 changes: 3 additions & 8 deletions purchase_allowed_product/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="order_line" position="before">
<xpath expr="//field[@name='partner_id']/.." position="inside">
<field
name="use_only_supplied_product"
attrs="{'invisible': [('state', 'not in', ('draft', 'sent'))]}"
class="oe_edit_only"
widget="boolean_toggle"
/>
<label
for="use_only_supplied_product"
attrs="{'invisible': [('state', 'not in', ('draft', 'sent'))]}"
class="oe_edit_only"
/>
</field>
</xpath>
<xpath
expr="//field[@name='order_line']/tree/field[@name='product_id']"
position="attributes"
Expand Down
2 changes: 1 addition & 1 deletion purchase_allowed_product/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<group name="purchase" position="inside">
<field name="use_only_supplied_product" />
<field name="use_only_supplied_product" widget="boolean_toggle" />
</group>
</field>
</record>
Expand Down

0 comments on commit 7497fe4

Please sign in to comment.