diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a3334c --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# Odoo +*.log +.pylintrc +.pylint.d/ + +# VS Code +.vscode/ + +# PyCharm +.idea/ + +# Translations +*.pot +*.po diff --git a/README.md b/README.md index ac82a6b..7a6d9fb 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Restrict visibility of the following records based on User configuration: * **Locations** (`stock.location`) * **Work Centers** (`mrp.workcenter`) * **Approval Categories** (`approval.category`) +* **Quality Checks Button** (on Manufacturing Orders) ## Configuration @@ -29,6 +30,15 @@ Restrict visibility of the following records based on User configuration: * **Populated List = Restricted**: If one or more records are added, the user will **ONLY** see those specific records. * **Superuser**: The Superuser (OdooBot) and administrators bypassing access rights are not affected by these restrictions. +## Quality Checks Button Restriction + +The "Quality Checks" button on Manufacturing Orders is automatically hidden for users who belong to the following groups: +* **Inventory User** +* **Manufacturing User** +* **MPS User** + +**Exception**: If a user in these groups is *also* assigned the **Quality User** or **Quality Manager** role, the button will remain visible. + ## Technical Details This module overrides the `_search` method on the target models to apply a domain filter based on the current user's allowed list. This ensures consistency across views (list, kanban, many2one dropdowns) and avoids common issues associated with Record Rules. diff --git a/__manifest__.py b/__manifest__.py index 8922bf4..8fffbb9 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -16,14 +16,12 @@ """, 'category': 'Extra Tools', 'author': 'Suherdy Yacob', - 'depends': ['base', 'stock', 'mrp', 'approvals', 'stock_account', 'sale', 'quality_control', 'quality_mrp'], + 'depends': ['base', 'stock', 'mrp', 'approvals', 'stock_account', 'sale'], 'data': [ 'security/ir.model.access.csv', 'security/ir_rule.xml', 'security/ir_actions_act_window.xml', 'views/res_users_views.xml', - 'views/stock_picking_views.xml', - 'views/mrp_production_views.xml', ], 'installable': True, 'application': False, diff --git a/models/__init__.py b/models/__init__.py index a751a50..b7e89d9 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,6 +1,9 @@ from . import res_users from . import restricted_models from . import sale_order +<<<<<<< HEAD from . import stock_picking +======= +>>>>>>> 3a96e90 (feat: Hide quality check buttons on manufacturing orders for specific user groups with exceptions for quality roles.) from . import mrp_production diff --git a/models/mrp_production.py b/models/mrp_production.py index 32abdfd..9a60cb7 100644 --- a/models/mrp_production.py +++ b/models/mrp_production.py @@ -3,6 +3,7 @@ from odoo import models, fields, api class MrpProduction(models.Model): _inherit = 'mrp.production' +<<<<<<< HEAD restrict_quality_check_button = fields.Boolean(compute='_compute_restrict_quality_check_button') @api.depends_context('uid') @@ -22,3 +23,63 @@ class MrpProduction(models.Model): production.restrict_quality_check_button = True else: production.restrict_quality_check_button = False +======= + hide_quality_check_button = fields.Boolean(compute='_compute_hide_quality_check_button') + + @api.depends_context('uid') + def _compute_hide_quality_check_button(self): + for record in self: + user = self.env.user + + # Define the restricted groups + # 1. Inventory User (stock.group_stock_user) + # 2. Manufacturing User (mrp.group_mrp_user) + # 3. MPS User (mrp_mps.group_mrp_mps) - handled safely + + is_restricted = False + + if user.has_group('stock.group_stock_user') or user.has_group('mrp.group_mrp_user'): + is_restricted = True + + # Check MPS User group safely as it might not be installed or ID might differ + if not is_restricted: + if user.has_group('mrp_mps.group_mrp_mps'): + is_restricted = True + else: + # Fallback search by name if XML ID not found or module not standard in this env + if self.env['res.groups'].search_count([('name', '=', 'MPS User'), ('id', 'in', user.groups_id.ids)]): + is_restricted = True + + # Logic: If user is in ANY of the restricted groups, we hide the button. + # However, usually "Manager" groups inherit "User" groups. + # So a Manager would also be a User. + # We must Ensure that we DO NOT hide it if the user is a Quality Manager or Quality User? + # The request says: "only hide ... from user in inventory user group, manufacturing user group and MPS user group" + # It implies if I am ONLY one of those, I shouldn't see it. + # But if I am ALSO a Quality User, should I see it? + # Usually, Quality User > Inventory User regarding Quality checks. + # If I hide it for Inventory User, and I am both Inventory User AND Quality User, I will simply NOT see it if I check "if has_group(Inventory)". + # So I should probably check if the user is NOT a Quality User/Manager. + + # But the user request is specific: "change the logic... to only hide ... from user in [groups]" + # If I am an Inventory User, I shouldn't see it. + # If I am also a Quality User, do I see it? Standard Odoo: Quality Users see it. + # If the user wants to restriction, likely they want these specific functional users NOT to do quality checks + # UNLESS they are explicitly Quality Users? + # Or maybe they want to hide it EVEN IF they are Quality Users? + # "Only hide ... from user in ..." suggests targeting these specific roles. + + # Let's refine the logic: + # Hide IF (User is Inventory OR Mfg OR MPS) AND (User is NOT Quality Manager/User?) + # Or is it a hard hide? "Only hide ... from [list]" + # If I assume the user implies "People who are just Inventory/Mfg/MPS users shouldn't see this", + # then if someone is ALSO a Quality Manager, they should probably see it. + # So I will add an exception: If user is Quality User+, they see it. + + is_quality_user = user.has_group('quality.group_quality_user') or user.has_group('quality.group_quality_manager') + + if is_restricted and not is_quality_user: + record.hide_quality_check_button = True + else: + record.hide_quality_check_button = False +>>>>>>> 3a96e90 (feat: Hide quality check buttons on manufacturing orders for specific user groups with exceptions for quality roles.) diff --git a/views/mrp_production_views.xml b/views/mrp_production_views.xml index 259b0e4..eb291bb 100644 --- a/views/mrp_production_views.xml +++ b/views/mrp_production_views.xml @@ -1,11 +1,16 @@ +<<<<<<< HEAD +======= + +>>>>>>> 3a96e90 (feat: Hide quality check buttons on manufacturing orders for specific user groups with exceptions for quality roles.) mrp.production.view.form.inherit.access.restriction mrp.production +<<<<<<< HEAD @@ -26,6 +31,17 @@ not check_ids or not quality_check_fail or restrict_quality_check_button +======= + + + + + hide_quality_check_button + + + hide_quality_check_button + +>>>>>>> 3a96e90 (feat: Hide quality check buttons on manufacturing orders for specific user groups with exceptions for quality roles.)