diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py index 133876b0..52e7864a 100644 --- a/base_global_discount/__manifest__.py +++ b/base_global_discount/__manifest__.py @@ -13,6 +13,7 @@ "security/security.xml", "security/ir.model.access.csv", "views/global_discount_views.xml", + "views/product_views.xml", "views/res_partner_views.xml", ], "application": False, diff --git a/base_global_discount/models/__init__.py b/base_global_discount/models/__init__.py index 8a1089ed..c1dc8f49 100644 --- a/base_global_discount/models/__init__.py +++ b/base_global_discount/models/__init__.py @@ -1,2 +1,4 @@ from . import global_discount +from . import product_product +from . import product_template from . import res_partner diff --git a/base_global_discount/models/product_product.py b/base_global_discount/models/product_product.py new file mode 100644 index 00000000..82238473 --- /dev/null +++ b/base_global_discount/models/product_product.py @@ -0,0 +1,16 @@ +# Copyright 2024 Studio73 - Ferran Mora +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + bypass_global_discount = fields.Boolean( + string="Don't apply global discount", + help=( + "If this checkbox is ticked, it means that this product will not be taken " + "into account when calculating the global discounts." + ), + ) diff --git a/base_global_discount/models/product_template.py b/base_global_discount/models/product_template.py new file mode 100644 index 00000000..8b198594 --- /dev/null +++ b/base_global_discount/models/product_template.py @@ -0,0 +1,39 @@ +# Copyright 2024 Studio73 - Ferran Mora +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + bypass_global_discount = fields.Boolean( + string="Don't apply global discount", + help=( + "If this checkbox is ticked, it means that this product will not be taken " + "into account when calculating the global discounts." + ), + compute="_compute_bypass_global_discount", + inverse="_inverse_bypass_global_discount", + ) + + def _search_bypass_global_discount(self, operator, value): + templates = self.with_context(active_test=False).search( + [("product_variant_ids.bypass_global_discount", operator, value)] + ) + return [("id", "in", templates.ids)] + + @api.depends("product_variant_ids.bypass_global_discount") + def _compute_bypass_global_discount(self): + self.bypass_global_discount = False + for template in self: + if len(template.product_variant_ids) == 1: + template.bypass_global_discount = ( + template.product_variant_ids.bypass_global_discount + ) + + def _inverse_bypass_global_discount(self): + if len(self.product_variant_ids) == 1: + self.product_variant_ids.bypass_global_discount = ( + self.bypass_global_discount + ) diff --git a/base_global_discount/views/product_views.xml b/base_global_discount/views/product_views.xml new file mode 100644 index 00000000..65bc86c6 --- /dev/null +++ b/base_global_discount/views/product_views.xml @@ -0,0 +1,32 @@ + + + + sale_order_global_discount.product_normal_form_view + product.product + + + + + + + + + + product.template.sale_order_global_discount.form + product.template + + + + + + + + +