feat: Extend access restrictions for picking types and locations to include warehouse-based rules and remove redundant _search override.

This commit is contained in:
Suherdy Yacob 2026-02-12 10:23:13 +07:00
parent 9dfecde29e
commit ebb4ea65db
2 changed files with 11 additions and 11 deletions

View File

@ -26,15 +26,15 @@ class StockWarehouse(models.Model):
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'
@api.model
def _search(self, domain, offset=0, limit=None, order=None, **kwargs):
if self.env.context.get('bypass_user_restriction'):
return super()._search(domain, offset=offset, limit=limit, order=order, **kwargs)
if not self.env.su and not self.env.user.has_group('base.group_system'):
allowed_ids = get_allowed_ids(self.env, 'res_users_stock_picking_type_rel', 'picking_type_id', self.env.user.id)
if allowed_ids:
domain = Domain(domain or []) & Domain([('id', 'in', allowed_ids)])
return super()._search(domain, offset=offset, limit=limit, order=order, **kwargs)
# @api.model
# def _search(self, domain, offset=0, limit=None, order=None, **kwargs):
# if self.env.context.get('bypass_user_restriction'):
# return super()._search(domain, offset=offset, limit=limit, order=order, **kwargs)
# if not self.env.su and not self.env.user.has_group('base.group_system'):
# allowed_ids = get_allowed_ids(self.env, 'res_users_stock_picking_type_rel', 'picking_type_id', self.env.user.id)
# if allowed_ids:
# domain = Domain(domain or []) & Domain([('id', 'in', allowed_ids)])
# return super()._search(domain, offset=offset, limit=limit, order=order, **kwargs)

View File

@ -28,7 +28,7 @@
<field name="domain_force">
(
[(1, '=', 1)] if user.env.context.get('bypass_user_restriction') or user.has_group('base.group_system') else
[('id', 'in', user.allowed_picking_type_ids.ids)] if user.allowed_picking_type_ids else [(1, '=', 1)]
['|', ('id', 'in', user.allowed_picking_type_ids.ids), ('warehouse_id', 'in', (user.allowed_warehouse_ids + user.allowed_location_ids.warehouse_id).ids)] if (user.allowed_picking_type_ids or user.allowed_warehouse_ids or user.allowed_location_ids) else [(1, '=', 1)]
)
</field>
</record>
@ -41,7 +41,7 @@
<field name="domain_force">
(
[(1, '=', 1)] if user.env.context.get('bypass_user_restriction') or user.has_group('base.group_system') else
['|', '|', ('id', 'in', user.allowed_location_ids.ids), ('id', 'child_of', user.allowed_location_ids.ids), ('id', 'parent_of', user.allowed_location_ids.ids)] if user.allowed_location_ids else [(1, '=', 1)]
['|', '|', '|', ('id', 'in', user.allowed_location_ids.ids), ('id', 'child_of', user.allowed_location_ids.ids), ('id', 'parent_of', user.allowed_location_ids.ids), ('warehouse_id', 'in', (user.allowed_warehouse_ids + user.allowed_location_ids.warehouse_id).ids)] if (user.allowed_location_ids or user.allowed_warehouse_ids) else [(1, '=', 1)]
)
</field>
</record>