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.

This commit is contained in:
Suherdy Yacob 2026-01-19 09:23:32 +07:00
parent 88494104cc
commit 4eee218534
10 changed files with 59 additions and 8 deletions

View File

@ -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

View File

@ -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,

View File

@ -6,4 +6,5 @@ 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
from . import stock_picking

View File

@ -26,9 +26,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:
<<<<<<< HEAD
user = self.env.user
# Define the restricted groups
@ -83,3 +85,9 @@ class MrpProduction(models.Model):
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.)
=======
# 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
>>>>>>> 4a049d1 (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.)

View File

@ -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."
)

View File

@ -3,6 +3,7 @@ from odoo import models, fields, api
class StockPicking(models.Model):
_inherit = 'stock.picking'
<<<<<<< HEAD
restrict_quality_check_button = fields.Boolean(compute='_compute_restrict_quality_check_button')
@api.depends_context('uid')
@ -32,3 +33,12 @@ class StockPicking(models.Model):
picking.restrict_quality_check_button = True
else:
picking.restrict_quality_check_button = False
=======
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
>>>>>>> 4a049d1 (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.)

View File

@ -8,8 +8,10 @@
>>>>>>> 3a96e90 (feat: Hide quality check buttons on manufacturing orders for specific user groups with exceptions for quality roles.)
<field name="name">mrp.production.view.form.inherit.access.restriction</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="quality_mrp.mrp_production_view_form_inherit_quality"/>
<field name="priority">99999</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml">
<<<<<<< HEAD
<<<<<<< HEAD
<field name="state" position="before">
<field name="restrict_quality_check_button" invisible="1"/>
@ -33,6 +35,9 @@
=======
<xpath expr="//header" position="inside">
=======
<xpath expr="//sheet" position="inside">
>>>>>>> 4a049d1 (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.)
<field name="hide_quality_check_button" invisible="1"/>
</xpath>
<xpath expr="//button[@name='check_quality']" position="attributes">

View File

@ -16,6 +16,7 @@
<group string="Manufacturing &amp; others">
<field name="allowed_workcenter_ids" widget="many2many_tags"/>
<field name="allowed_approval_category_ids" widget="many2many_tags"/>
<field name="allowed_quality_checks"/>
</group>
</group>
</page>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<<<<<<< HEAD
<!-- Inherit from the quality control view that adds the button -->
<!-- We need to ensure we target the right buttons. The Quality Checks button is added by quality_control/views/stock_picking_views.xml -->
<!-- The button names are 'check_quality', 'open_quality_alert_picking', 'action_open_quality_check_picking' -->
@ -32,6 +33,23 @@
<attribute name="invisible">not check_ids or not quality_check_fail or restrict_quality_check_button</attribute>
</xpath>
=======
<record id="stock_picking_view_form_inherit_access_restriction" model="ir.ui.view">
<field name="name">stock.picking.view.form.inherit.access.restriction</field>
<field name="model">stock.picking</field>
<field name="priority">1000</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<field name="hide_quality_check_button" invisible="1"/>
</xpath>
<xpath expr="//button[@name='check_quality']" position="attributes">
<attribute name="invisible">hide_quality_check_button</attribute>
</xpath>
<xpath expr="//button[@name='button_quality_alert']" position="attributes">
<attribute name="invisible">hide_quality_check_button</attribute>
</xpath>
>>>>>>> 4a049d1 (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.)
</field>
</record>
</odoo>