From 07bb9367e1b2014b55e49bcbc8a296406976a00c Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Thu, 15 Jan 2026 10:14:04 +0700 Subject: [PATCH] feat: Add a post-init hook to remove the quality user group from specific manufacturing groups' implied IDs. --- README.md | 3 +++ __init__.py | 1 + __manifest__.py | 1 + hooks.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 hooks.py diff --git a/README.md b/README.md index ee77c11..3ccbda3 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/__init__.py b/__init__.py index e69de29..b10171a 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1 @@ +from . import hooks \ No newline at end of file diff --git a/__manifest__.py b/__manifest__.py index fcea9e4..a57656f 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -17,6 +17,7 @@ 'data': [ 'security/quality_security.xml', ], + 'post_init_hook': 'post_init_hook', 'license': 'LGPL-3', 'installable': True, 'auto_install': False, diff --git a/hooks.py b/hooks.py new file mode 100644 index 0000000..71c8450 --- /dev/null +++ b/hooks.py @@ -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.