diff --git a/purchase_allowed_product/README.rst b/purchase_allowed_product/README.rst index a351c44a3c9..c14ca18d7b0 100644 --- a/purchase_allowed_product/README.rst +++ b/purchase_allowed_product/README.rst @@ -74,6 +74,8 @@ Contributors * Darius Žižys +* Eduardo de Miguel (`Moduon `__) + Maintainers ~~~~~~~~~~~ diff --git a/purchase_allowed_product/models/account_move.py b/purchase_allowed_product/models/account_move.py index 05fc785ce43..41f166b7c62 100644 --- a/purchase_allowed_product/models/account_move.py +++ b/purchase_allowed_product/models/account_move.py @@ -1,9 +1,18 @@ # © 2016 Chafique DELLI @ Akretion +# Copyright 2024 Moduon Team S.L. # 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() diff --git a/purchase_allowed_product/models/purchase_order.py b/purchase_allowed_product/models/purchase_order.py index 6e3b40be9f7..5527d2604b8 100644 --- a/purchase_allowed_product/models/purchase_order.py +++ b/purchase_allowed_product/models/purchase_order.py @@ -1,4 +1,5 @@ # © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion +# Copyright 2024 Moduon Team S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import models @@ -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 diff --git a/purchase_allowed_product/models/supplied_product_mixin.py b/purchase_allowed_product/models/supplied_product_mixin.py index 0d46993703d..5e4e6e358ca 100644 --- a/purchase_allowed_product/models/supplied_product_mixin.py +++ b/purchase_allowed_product/models/supplied_product_mixin.py @@ -1,4 +1,5 @@ # © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion +# Copyright 2024 Moduon Team S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models @@ -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 + ) diff --git a/purchase_allowed_product/readme/CONTRIBUTORS.rst b/purchase_allowed_product/readme/CONTRIBUTORS.rst index dd6ed196951..7c94d25cb61 100644 --- a/purchase_allowed_product/readme/CONTRIBUTORS.rst +++ b/purchase_allowed_product/readme/CONTRIBUTORS.rst @@ -9,3 +9,5 @@ * `Via laurea `__: * Darius Žižys + +* Eduardo de Miguel (`Moduon `__) diff --git a/purchase_allowed_product/static/description/index.html b/purchase_allowed_product/static/description/index.html index c67064af2a0..efac13f80d9 100644 --- a/purchase_allowed_product/static/description/index.html +++ b/purchase_allowed_product/static/description/index.html @@ -1,4 +1,3 @@ - @@ -419,6 +418,7 @@

Contributors

  • Darius Žižys
  • +
  • Eduardo de Miguel (Moduon)
  • diff --git a/purchase_allowed_product/views/account_move_views.xml b/purchase_allowed_product/views/account_move_views.xml index ad1eaaca191..764f4af387f 100644 --- a/purchase_allowed_product/views/account_move_views.xml +++ b/purchase_allowed_product/views/account_move_views.xml @@ -4,18 +4,13 @@ account.move - + - + purchase.order - - - + + + - +