diff --git a/product_assortment/__manifest__.py b/product_assortment/__manifest__.py index de8dd666733b..c7421df3cabf 100644 --- a/product_assortment/__manifest__.py +++ b/product_assortment/__manifest__.py @@ -14,6 +14,7 @@ "depends": ["base", "product"], "data": [ "data/ir_cron.xml", + "security/product_assortment_security.xml", "views/product_assortment.xml", "views/res_partner_view.xml", ], diff --git a/product_assortment/models/__init__.py b/product_assortment/models/__init__.py index c03968c0074d..40f9898560a8 100644 --- a/product_assortment/models/__init__.py +++ b/product_assortment/models/__init__.py @@ -1,2 +1,3 @@ from . import ir_filters +from . import ir_rule from . import res_partner diff --git a/product_assortment/models/ir_rule.py b/product_assortment/models/ir_rule.py new file mode 100644 index 000000000000..48c80a522251 --- /dev/null +++ b/product_assortment/models/ir_rule.py @@ -0,0 +1,36 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html + +from odoo import api, models, tools +from odoo.osv import expression +from odoo.tools import config + + +class IrRule(models.Model): + _inherit = "ir.rule" + + @api.model + @tools.conditional( + "xml" not in config["dev_mode"], + tools.ormcache( + "self.env.uid", + "self.env.su", + "model_name", + "mode", + "tuple(self._compute_domain_context_values())", + ), + ) + def _compute_domain(self, model_name, mode="read"): + """Inject extra domain for restricting filter (Assortments) when the user + has not the group 'Product Assortment Manager'. + """ + res = super()._compute_domain(model_name, mode=mode) + user = self.env.user + if model_name == "ir.filters" and not self.env.su: + if not user.has_group( + "product_assortment.group_product_assortment_manager" + ): + extra_domain = [("is_assortment", "=", False)] + extra_domain = expression.normalize_domain(extra_domain) + res = expression.AND([extra_domain] + [res]) + return res diff --git a/product_assortment/security/product_assortment_security.xml b/product_assortment/security/product_assortment_security.xml new file mode 100644 index 000000000000..363e69db9c61 --- /dev/null +++ b/product_assortment/security/product_assortment_security.xml @@ -0,0 +1,18 @@ + + + + Product Assortment Manager + Access to all product assortment + + + + ir.filters.product.assortment.manager.rule + + [('is_assortment','=', True)] + + + + diff --git a/product_assortment/views/product_assortment.xml b/product_assortment/views/product_assortment.xml index 515b67da8432..fb877b4fdedd 100644 --- a/product_assortment/views/product_assortment.xml +++ b/product_assortment/views/product_assortment.xml @@ -122,6 +122,7 @@ name="Product Assortment" id="menu_product_assortments" action="actions_product_assortment_view" + groups="product_assortment.group_product_assortment_manager" sequence="5" web_icon="product_assortment,static/description/icon.png" /> diff --git a/product_assortment/views/res_partner_view.xml b/product_assortment/views/res_partner_view.xml index 543615b22e45..b9bd5b55e674 100644 --- a/product_assortment/views/res_partner_view.xml +++ b/product_assortment/views/res_partner_view.xml @@ -11,6 +11,7 @@ name="action_define_product_assortment" icon="fa-pencil" type="object" + groups="product_assortment.group_product_assortment_manager" > Product Assortments