From 37e6539f99b0169995ec62a34070fd4736bc1376 Mon Sep 17 00:00:00 2001 From: rafaferri Date: Thu, 22 Jun 2023 08:41:30 +0200 Subject: [PATCH] [IMP] base_global_discount: Add check global discount in product --- base_global_discount/__manifest__.py | 1 + base_global_discount/models/__init__.py | 2 + .../models/product_product.py | 14 +++++++ .../models/product_template.py | 38 +++++++++++++++++++ base_global_discount/views/product_view.xml | 29 ++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 base_global_discount/models/product_product.py create mode 100644 base_global_discount/models/product_template.py create mode 100644 base_global_discount/views/product_view.xml diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py index d0b1f1c7f..dcd1683eb 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_view.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 8a1089eda..c1dc8f49b 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 000000000..3b299e1e3 --- /dev/null +++ b/base_global_discount/models/product_product.py @@ -0,0 +1,14 @@ +# Copyright 2023 Studio73 - Rafa Ferri +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + not_apply_global_discount = fields.Boolean( + string="Don't apply global discount", + help="If this checkbox is ticked, it means changing global discount on sale order " + "won't impact sale order lines with this related product.", + ) diff --git a/base_global_discount/models/product_template.py b/base_global_discount/models/product_template.py new file mode 100644 index 000000000..da15ad1a9 --- /dev/null +++ b/base_global_discount/models/product_template.py @@ -0,0 +1,38 @@ +# Copyright 2023 Studio73 - Rafa Ferri +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + not_apply_global_discount = fields.Boolean( + string="Don't apply global discount", + search="_search_not_apply_discount_apply", + compute="_compute_apply_discount_apply", + inverse="_inverse_apply_discount_apply", + help="If this checkbox is not ticked, it means changing global discount on sale order " + "won't impact sale order lines with this related product.", + ) + + def _search_not_apply_discount_apply(self, operator, value): + templates = self.with_context(active_test=False).search( + [("product_variant_ids.not_apply_global_discount", operator, value)] + ) + return [("id", "in", templates.ids)] + + @api.depends("product_variant_ids.not_apply_global_discount") + def _compute_apply_discount_apply(self): + self.not_apply_global_discount = True + for template in self: + if len(template.product_variant_ids) == 1: + template.not_apply_global_discount = ( + template.product_variant_ids.not_apply_global_discount + ) + + def _inverse_apply_discount_apply(self): + if len(self.product_variant_ids) == 1: + self.product_variant_ids.not_apply_global_discount = ( + self.not_apply_global_discount + ) diff --git a/base_global_discount/views/product_view.xml b/base_global_discount/views/product_view.xml new file mode 100644 index 000000000..b90a2415d --- /dev/null +++ b/base_global_discount/views/product_view.xml @@ -0,0 +1,29 @@ + + + + product.only.form + product.product + + + + + + + + + + product.template.only.form + product.template + + + + + + + + + +