-
-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_assortment: Add security group to only show assortments…
… to managers TT51064
- Loading branch information
1 parent
6dc0923
commit 287849a
Showing
6 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import ir_filters | ||
from . import ir_rule | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
18 changes: 18 additions & 0 deletions
18
product_assortment/security/product_assortment_security.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
<record id="group_product_assortment_manager" model="res.groups"> | ||
<field name="name">Product Assortment Manager</field> | ||
<field name="comment">Access to all product assortment</field> | ||
</record> | ||
|
||
<record id="ir_filters_product_assortment_rule" model="ir.rule"> | ||
<field name="name">ir.filters.product.assortment.manager.rule</field> | ||
<field name="model_id" ref="model_ir_filters" /> | ||
<field name="domain_force">[('is_assortment','=', True)]</field> | ||
<field | ||
name="groups" | ||
eval="[Command.link(ref('product_assortment.group_product_assortment_manager'))]" | ||
/> | ||
<field name="perm_unlink" eval="False" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters