From f783c381ca754680dd4d0b3e21fffe6356cb9c67 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Thu, 15 Jan 2026 13:12:09 +0700 Subject: [PATCH] feat: Restrict stock picking validation for non-Quality users when pending quality checks exist. --- __init__.py | 3 ++- models/__init__.py | 1 + models/stock_picking.py | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 models/__init__.py create mode 100644 models/stock_picking.py diff --git a/__init__.py b/__init__.py index b10171a..a16fc98 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1,2 @@ -from . import hooks \ No newline at end of file +from . import hooks +from . import models \ No newline at end of file diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..ae4c272 --- /dev/null +++ b/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/models/stock_picking.py b/models/stock_picking.py new file mode 100644 index 0000000..2e63802 --- /dev/null +++ b/models/stock_picking.py @@ -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()