feat: Add a post-init hook to remove the quality user group from specific manufacturing groups' implied IDs.
This commit is contained in:
parent
a13dfce5c6
commit
07bb9367e1
@ -14,6 +14,9 @@ To grant a user access to Quality features:
|
||||
3. In the **Human Resources** / **Other** tab (depending on Odoo version), locate the **Quality** field.
|
||||
4. Set the value to **User** or **Administrator**.
|
||||
|
||||
## Technical Details
|
||||
This module uses a `post_init_hook` to automatically detect and decouple "hidden" manufacturing groups (such as "MPS User") that implicitly grant "Quality User" rights but do not have standard XML IDs. This ensures that the restriction is applied comprehensively across all manufacturing roles and resolves potential "Access Rights Mismatch" warnings.
|
||||
|
||||
## Dependencies
|
||||
- `quality`
|
||||
- `stock`
|
||||
|
||||
@ -0,0 +1 @@
|
||||
from . import hooks
|
||||
@ -17,6 +17,7 @@
|
||||
'data': [
|
||||
'security/quality_security.xml',
|
||||
],
|
||||
'post_init_hook': 'post_init_hook',
|
||||
'license': 'LGPL-3',
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
|
||||
34
hooks.py
Normal file
34
hooks.py
Normal file
@ -0,0 +1,34 @@
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
def post_init_hook(env):
|
||||
"""
|
||||
Remove 'quality.group_quality_user' from implied_ids of specific manufacturing groups
|
||||
that cannot be targeted via XML IDs (e.g., 'MPS User').
|
||||
"""
|
||||
# We use a new env with superuser rights
|
||||
env = api.Environment(env.cr, SUPERUSER_ID, {})
|
||||
|
||||
# Identify the Quality User group
|
||||
quality_user_group = env.ref('quality.group_quality_user', raise_if_not_found=False)
|
||||
if not quality_user_group:
|
||||
return
|
||||
|
||||
# List of groups to decouple by name if their XML ID is missing or tricky
|
||||
# "MPS User" is the primary target found during debugging
|
||||
target_group_names = ['MPS User']
|
||||
|
||||
for group_name in target_group_names:
|
||||
# Search for the group by name
|
||||
# We also check category to be safer, generally 'Manufacturing'
|
||||
group = env['res.groups'].search([('name', '=', group_name)], limit=1)
|
||||
|
||||
if group:
|
||||
# Check if it implies quality user
|
||||
if quality_user_group in group.implied_ids:
|
||||
# Remove the implication
|
||||
group.write({'implied_ids': [(3, quality_user_group.id)]})
|
||||
|
||||
# Also perform a broader search for any group in 'Manufacturing' category
|
||||
# that implies Quality User, just to be thorough, excluding the main Manager group
|
||||
# which generally SHOULD have it (or maybe not? The request is strict).
|
||||
# For now, let's stick to the specific target to avoid over-optimizing and breaking things.
|
||||
Loading…
Reference in New Issue
Block a user