feat: Restrict stock picking validation for non-Quality users when pending quality checks exist.

This commit is contained in:
Suherdy Yacob 2026-01-15 13:12:09 +07:00
parent 07bb9367e1
commit f783c381ca
3 changed files with 25 additions and 1 deletions

View File

@ -1 +1,2 @@
from . import hooks
from . import models

1
models/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import stock_picking

22
models/stock_picking.py Normal file
View File

@ -0,0 +1,22 @@
from odoo import models, _
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = "stock.picking"
def check_quality(self):
"""
Override to prevent Access Error when non-Quality users allow validation
triggers check_quality.
"""
# Check if user has Quality User group
is_quality_user = self.env.user.has_group('quality.group_quality_user')
if not is_quality_user:
# Check if there are checks to do
checks = self._checks_to_do()
if checks:
# If there are pending checks and user is not allowed to do them, raise clear error
raise UserError(_("You cannot validate this transfer because there are pending Quality Checks. Please ask a Quality User to perform them."))
return super().check_quality()