from odoo import models, api from odoo.osv import expression class ReportStockQuantity(models.Model): _inherit = 'report.stock.quantity' @api.model def _search(self, domain, offset=0, limit=None, order=None, **kwargs): user = self.env.user # START Custom Restriction Logic # Bylass for System admins or explicit bypass context if not user.has_group('base.group_system') and not self.env.context.get('bypass_user_restriction'): allowed_wh = user.allowed_warehouse_ids | user.allowed_location_ids.warehouse_id # If user has specific allowed warehouses/locations, restrict report if allowed_wh: domain = expression.AND([domain, [('warehouse_id', 'in', allowed_wh.ids)]]) # Note: If allowed_wh is empty but allowed_location_ids is NOT empty, it means # the allowed locations don't belong to any warehouse (unlikely) or just user config issue. # If BOTH are empty, we fall back to standard access (All). # END Custom Restriction Logic return super()._search(domain, offset, limit, order, **kwargs)