Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] [16.0] purchase_allowed_product: Improve UX #2155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = (
self.invoice_vendor_bill_id.use_only_supplied_product
)
return super()._onchange_invoice_vendor_bill()
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
15 changes: 3 additions & 12 deletions purchase_allowed_product/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@
<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">
<field
name="use_only_supplied_product"
attrs="{'invisible': [('state', 'not in', ('draft', 'sent'))]}"
class="oe_edit_only"
/>
<label
for="use_only_supplied_product"
attrs="{'invisible': [('state', 'not in', ('draft', 'sent'))]}"
class="oe_edit_only"
/>
</field>
<xpath expr="//field[@name='partner_id']/.." position="inside">
<field name="use_only_supplied_product" widget="boolean_toggle" />
</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
Loading