From 3a96e905962e1993816bbd0d727ef0aa38f5a838 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Fri, 16 Jan 2026 08:58:43 +0700 Subject: [PATCH 1/3] feat: Hide quality check buttons on manufacturing orders for specific user groups with exceptions for quality roles. --- .gitignore | 37 ++++++++++++ README.md | 10 ++++ __manifest__.py | 3 +- models/__init__.py | 1 + models/__pycache__/__init__.cpython-312.pyc | Bin 299 -> 337 bytes models/mrp_production.py | 63 ++++++++++++++++++++ views/mrp_production_views.xml | 19 ++++++ 7 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 models/mrp_production.py create mode 100644 views/mrp_production_views.xml 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 2c5f802..ca0a458 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -16,12 +16,13 @@ """, 'category': 'Extra Tools', 'author': 'Suherdy Yacob', - 'depends': ['base', 'stock', 'mrp', 'approvals', 'stock_account', 'sale'], + 'depends': ['base', 'stock', 'mrp', 'approvals', 'stock_account', 'sale', 'quality_mrp'], 'data': [ 'security/ir.model.access.csv', 'security/ir_rule.xml', 'security/ir_actions_act_window.xml', 'views/res_users_views.xml', + 'views/mrp_production_views.xml', ], 'installable': True, 'application': False, diff --git a/models/__init__.py b/models/__init__.py index d5fe265..94a4606 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,4 +1,5 @@ from . import res_users from . import restricted_models from . import sale_order +from . import mrp_production diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index 2b838bcc0f19619ae7e71a173fb297beea4f86e6..644f3df66c67991a3f13fea078666c603bcb9949 100644 GIT binary patch delta 126 zcmZ3@bdiboG%qg~0}y!3%*@Q6$ScWcGErSqAcY}?C5IuGC5nZSp^{aTZDNS2h9=`J zzTBdM_=2MRl+xsq%=|n*P1aisMa)3mMJynK6-2O2oK>jI4P-F_aj_tf_`uA_$at4Q S{4Rt1T?UDJ3^GNWKv4j2%^XPp delta 88 zcmcb}w3>%;_8K|f8FTMR|aK=~pT5WzZe iZ=nK6JtGho^8twu%#4hTcNxU*GRWU!kSO8+3IPCb^AZ{W diff --git a/models/mrp_production.py b/models/mrp_production.py new file mode 100644 index 0000000..69eacd7 --- /dev/null +++ b/models/mrp_production.py @@ -0,0 +1,63 @@ +from odoo import models, fields, api + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + 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 diff --git a/views/mrp_production_views.xml b/views/mrp_production_views.xml new file mode 100644 index 0000000..f74f2e2 --- /dev/null +++ b/views/mrp_production_views.xml @@ -0,0 +1,19 @@ + + + + mrp.production.view.form.inherit.access.restriction + mrp.production + + + + + + + hide_quality_check_button + + + hide_quality_check_button + + + + From 4a049d124ecf9a3830893431fa442bba4d4ecb4b Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 19 Jan 2026 09:23:32 +0700 Subject: [PATCH 2/3] feat: Implement user-specific control for quality check button visibility on manufacturing orders and inventory transfers via a new `allowed_quality_checks` field on users. --- README.md | 13 +++-- __manifest__.py | 3 +- models/__init__.py | 1 + models/__pycache__/__init__.cpython-312.pyc | Bin 337 -> 374 bytes models/__pycache__/res_users.cpython-312.pyc | Bin 1932 -> 2172 bytes models/mrp_production.py | 58 ++----------------- models/res_users.py | 6 ++ models/stock_picking.py | 12 ++++ views/mrp_production_views.xml | 5 +- views/res_users_views.xml | 1 + views/stock_picking_views.xml | 20 +++++++ 11 files changed, 57 insertions(+), 62 deletions(-) create mode 100644 models/stock_picking.py create mode 100644 views/stock_picking_views.xml diff --git a/README.md b/README.md index 7a6d9fb..dc48563 100644 --- a/README.md +++ b/README.md @@ -10,7 +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) +* **Quality Checks Button** (on Manufacturing Orders and Inventory Transfers) ## Configuration @@ -32,12 +32,13 @@ Restrict visibility of the following records based on User configuration: ## 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** +The visibility of the "Quality Checks" and "Quality Alert" buttons on **Manufacturing Orders** and **Inventory Transfers** is controlled by a specific user setting. -**Exception**: If a user in these groups is *also* assigned the **Quality User** or **Quality Manager** role, the button will remain visible. +To allow a user to see these buttons: +1. Navigate to **Settings > Users & Companies > Users**. +2. Enable the checkbox **"Is Allowed todo Quality Checks?"** in the **Access Restrictions** tab. + +By default, this setting is unchecked, meaning users will **NOT** see these buttons unless explicitly allowed. ## Technical Details diff --git a/__manifest__.py b/__manifest__.py index ca0a458..70e244f 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -16,13 +16,14 @@ """, 'category': 'Extra Tools', 'author': 'Suherdy Yacob', - 'depends': ['base', 'stock', 'mrp', 'approvals', 'stock_account', 'sale', 'quality_mrp'], + 'depends': ['base', 'stock', 'mrp', 'approvals', 'stock_account', 'sale', 'quality_mrp', 'quality_control'], 'data': [ 'security/ir.model.access.csv', 'security/ir_rule.xml', 'security/ir_actions_act_window.xml', 'views/res_users_views.xml', 'views/mrp_production_views.xml', + 'views/stock_picking_views.xml', ], 'installable': True, 'application': False, diff --git a/models/__init__.py b/models/__init__.py index 94a4606..d5afda8 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -2,4 +2,5 @@ from . import res_users from . import restricted_models from . import sale_order from . import mrp_production +from . import stock_picking diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index 644f3df66c67991a3f13fea078666c603bcb9949..78e580eabf8314b295fe242a9a74a187a5f49ac9 100644 GIT binary patch delta 133 zcmcb}^o@!4G%qg~0}%N2=4N(JvN0adu zZ*fU}a&~+{W^#6BUb>$q+bxD7W}xOG77)P-BG^C#`^3G4YCJ#|BM=vh0ErLGjEszT W8N}~0$lqm#2x$q delta 96 zcmeyybdiboG%qg~0}y!3%*@Q6$ScWcGEv=>rIJ;XZDNkQn4c!=ErudypnMSvh+qW~ oY!mMnDsux_j6hs02qZo*Gcq#XWe~s1Ab*!Z;vR!c5hqX-01O)w;s5{u diff --git a/models/__pycache__/res_users.cpython-312.pyc b/models/__pycache__/res_users.cpython-312.pyc index 620603c45a557d4dc929185ae8ec7cff7721ece6..b7feec66487b71ed1024e9881f0d5949ab991e1a 100644 GIT binary patch delta 375 zcmeC-|0BS6nwOW00SKmb?Mkx`F{A(bUd3?zdJQe;!)QsmbttY(IY zNAXlDYAS7>%hx7brsdD9Y0b4rT1fm}aL-pMMgdlYW5JLTu+q$cLw5=(@*E4~oo zq`Gs5P_&5XOjZ*W6E^agMI7j_mowu>xMMM{$u z*)^OMfrb|;fe2+F@r%PIH$SB`C)KV<4aj8#;$jIP@qw9LIFtp;;_lhPbtkwwJTBvav6cRSOQ3VU}j`w Zyw4#2g+-5%t)r~JrnBZN1CR;U2>=tSAv*v7 diff --git a/models/mrp_production.py b/models/mrp_production.py index 69eacd7..27a8b0e 100644 --- a/models/mrp_production.py +++ b/models/mrp_production.py @@ -5,59 +5,11 @@ class MrpProduction(models.Model): hide_quality_check_button = fields.Boolean(compute='_compute_hide_quality_check_button') + @api.depends('product_id') @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 + # Logic: Hide logic is inverse of "is allowed" + # If allowed_quality_checks is True, hide = False + # If allowed_quality_checks is False, hide = True + record.hide_quality_check_button = not self.env.user.allowed_quality_checks diff --git a/models/res_users.py b/models/res_users.py index a50010c..1b3c7d7 100644 --- a/models/res_users.py +++ b/models/res_users.py @@ -47,3 +47,9 @@ class ResUsers(models.Model): string="Allowed Approvals", help="Approval Categories this user is allowed to access. Leave empty to restrict access to none." ) + + allowed_quality_checks = fields.Boolean( + string="Is Allowed todo Quality Checks?", + default=False, + help="If checked, this user can see the Quality Checks button on Manufacturing Orders." + ) diff --git a/models/stock_picking.py b/models/stock_picking.py new file mode 100644 index 0000000..f759da1 --- /dev/null +++ b/models/stock_picking.py @@ -0,0 +1,12 @@ +from odoo import models, fields, api + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + hide_quality_check_button = fields.Boolean(compute='_compute_hide_quality_check_button') + + @api.depends('picking_type_id') + @api.depends_context('uid') + def _compute_hide_quality_check_button(self): + for record in self: + record.hide_quality_check_button = not self.env.user.allowed_quality_checks diff --git a/views/mrp_production_views.xml b/views/mrp_production_views.xml index f74f2e2..29c627f 100644 --- a/views/mrp_production_views.xml +++ b/views/mrp_production_views.xml @@ -3,9 +3,10 @@ mrp.production.view.form.inherit.access.restriction mrp.production - + 99999 + - + diff --git a/views/res_users_views.xml b/views/res_users_views.xml index 6ca0e38..59ab6d9 100644 --- a/views/res_users_views.xml +++ b/views/res_users_views.xml @@ -16,6 +16,7 @@ + diff --git a/views/stock_picking_views.xml b/views/stock_picking_views.xml new file mode 100644 index 0000000..6a5df0c --- /dev/null +++ b/views/stock_picking_views.xml @@ -0,0 +1,20 @@ + + + + stock.picking.view.form.inherit.access.restriction + stock.picking + 1000 + + + + + + + hide_quality_check_button + + + hide_quality_check_button + + + + From b9b6e549c0f88a3d7b316df282b37c569a479603 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Wed, 21 Jan 2026 15:00:41 +0700 Subject: [PATCH 3/3] feat: Add `bypass_user_restriction` context to various action methods across multiple models and optimize the `allowed_quality_checks` field. --- models/__pycache__/res_users.cpython-312.pyc | Bin 2172 -> 2187 bytes .../restricted_models.cpython-312.pyc | Bin 7791 -> 8418 bytes models/__pycache__/sale_order.cpython-312.pyc | Bin 801 -> 1055 bytes models/mrp_production.py | 6 ++++++ models/res_users.py | 1 + models/restricted_models.py | 6 ++++++ models/sale_order.py | 3 +++ models/stock_picking.py | 6 ++++++ 8 files changed, 22 insertions(+) diff --git a/models/__pycache__/res_users.cpython-312.pyc b/models/__pycache__/res_users.cpython-312.pyc index b7feec66487b71ed1024e9881f0d5949ab991e1a..c4a4b78bf524eaf2188e69c76bda424a9d1a8cc3 100644 GIT binary patch delta 165 zcmew(&@IS&nwOW00SNlq3Nk$>@^&%mY@8v-$S#*6zeZs-%jVsTtSpi&MIa@&*i%x| z5=(PRZgCV8rKY8pBxh_s&lPO4pzI*`i<#KjUo;sY}yBjbGr`7bP{jBFic{WYC6Um1W*uucFA CJ}cJ% delta 150 zcmeAc{3F17nwOW00SKmbk_q>7X#D{yEyD*{y(DS-%OAn}XCCO1E&G$+-r nNDatk1ma=|An}2jk&*E}gZvj36Gpa3dShTU-E0AOc;?EvHVk+Zwh7zzah$vx# zF>59Zh>6#)VOkB<*~`zs0J9ZnF0)_AO2#5lplVH)A|)VI6bvM8@swwlWW*=u=ar;Z zl-%M=OfJdH&jaz(GK+FGnTj+)Ds_NFF~}l?h9UuwKqQc;l5;F5D9SHO%n3>@EKMyg z(F1DEL(-iH(gm{VM+3thevv8h3sSDDnO{^hzYq{|LCyTKTIfao)XV(o7dX<3bb-o} z;a&l9;9m9ta!B!V4dWVSSP%fc&EgkQ6b>{(lkpZuBG|pDMaThA6akck`x~l4lNsXg zXrLU#^PtdIfcZWK$U*qN9?AP4-$Ttv0V*oi0226oe<8p80w@eBE^t(U!=OkHs6&&{ zPm`<20LUsb1QA9c!WcxbfCv*1p$sBG(NM$&a!!%yOUOJaw2{wCa`FWp&&}H<1DGej7m=QvE6>NMFu6uvcJeA7 jp2^$gI~ZdpJ1F#uax(@nPDq=cGco5Y1BhLu3p4}(b^RH$ diff --git a/models/__pycache__/sale_order.cpython-312.pyc b/models/__pycache__/sale_order.cpython-312.pyc index 4517426db58d10065080ebf5d19e3924aa0d36b3..81666e7855ffb0ef4acbd30c1c8accc3314280fb 100644 GIT binary patch delta 326 zcmZ3;HlKs7LCS=HM3rQ4Vos`mQA%o&9-0Qu$^1-8d*K delta 212 zcmbQwv5<}LG%qg~0}#yImymgtVIp5Gqte74d5#LkDAr&GP3DPvD;YH>n=^U=$tK1M zMy|=f8GV>E*(Mt?>-&K;-r|jqPtHj!E>2F($%&8GWGvzViWV~h35OzHAX&r;BbY%F zB0%Ct3&Rb5=?0JQER3v4j2{?4WD(!wUCgQud?3XjZNE5da`RJ4b5iY!#DQFpdBsvd h;sY}yBja5L@h>baj7f|W*rxML