How to use _get_allowed_locations method in lisa

Best Python code snippet using lisa_python

models.py

Source:models.py Github

copy

Full Screen

...17 return [(6, 0, [wh.id for wh in self.allowed_warehouse_ids])]18 # otherwise, return a list of *all* warehouses (which effectively disables the access-control)19 return [(6, 0, [wh.id for wh in self.env["stock.warehouse"].sudo().search([(1, "=", 1)])])]20 @api.multi21 def _get_allowed_locations(self):22 if not self or len(self) > 1: return False23 24 if self.restrict_wh_locations:25 return [(6, 0, self._recurse_location_children(self.allowed_location_ids))]26 return [(6, 0, [loc.id for loc in self.env["stock.location"].sudo().search([(1, "=", 1)])])]27 @api.multi28 def _get_allowed_picking_types(self):29 if not self or len(self) > 1: return False30 31 if self.restrict_wh_locations:32 return [(6, 0, [pick.id for pick in self.allowed_picking_type_ids])]33 return [(6, 0, [pick.id for pick in self.env["stock.picking.type"].sudo().search([(1, "=", 1)])])]34 # Should the user be restricted to certain warehouses?35 restrict_wh_locations = fields.Boolean(string="Restrict Warehouses/Locations", default=True)36 # Warehouses/Locations/Picking Types that the user *should* have access to. This field is not used directly in the access rules37 allowed_warehouse_ids = fields.Many2many(string="Allowed Warehouses", help="List of warehouses that this user is allowed to access", comodel_name="stock.warehouse")38 allowed_location_ids = fields.Many2many(string="Allowed Locations", help="List of locations that this user is allowed to access", comodel_name="stock.location")39 allowed_picking_type_ids = fields.Many2many(string="Allowed Picking Types", help="List of picking types that this user is allowed to access", comodel_name="stock.picking.type")40 # Ghost fields that contain lists of IDs that are *actually* allowed. For example, @allowed_location_ids_computed will contain all IDs from the above field, but also41 # all sub-locations (see _recurse_location_children). 42 allowed_warehouse_ids_computed = fields.Many2many(comodel_name="stock.warehouse", relation="res_users_allowed_warehouses_comp_rel", column1="res_users_id", column2="stock_warehouse_id", default=_get_allowed_warehouses)43 allowed_location_ids_computed = fields.Many2many(comodel_name="stock.location", relation="res_users_allowed_locations_comp_rel", column1="res_users_id", column2="stock_location_id", default=_get_allowed_locations)44 allowed_picking_type_ids_computed = fields.Many2many(comodel_name="stock.picking.type", relation="res_users_allowed_picking_type_comp_rel", column1="res_users_id", column2="stock_picking_type_id", default=_get_allowed_picking_types)45 @api.model46 def _recurse_location_children(self, locations):47 # Adding a location implies that the user should have access to its sub-locations also48 location_ids = self.env['stock.location'].search([('usage', '!=', 'internal')]).ids49# location_ids = []50 for location in locations:51 location_ids.append(location.id)52 if location.child_ids and len(location.child_ids) > 0:53 for child_id in self._recurse_location_children(location.child_ids):54 if child_id not in location_ids:55 location_ids.append(child_id)56 return location_ids57 @api.multi58 @api.onchange('restrict_wh_locations')59 def _onchange_restrict_wh_locations(self):60 for user in self:61 # Update the xxx_ids_computed fields. See the _get_allowed_xxx() functions for more details62 user.allowed_warehouse_ids_computed = user._get_allowed_warehouses()63 user.allowed_location_ids_computed = user._get_allowed_locations()64 user.allowed_picking_type_ids_computed = user._get_allowed_picking_types()65 self.clear_wh_rule_caches()66 @api.multi67 @api.onchange('allowed_warehouse_ids')68 def _onchange_allowed_warehouse_ids(self):69 self.ensure_one()70 self.allowed_warehouse_ids_computed = self._get_allowed_warehouses()71 self.clear_wh_rule_caches()72 @api.multi73 @api.onchange('allowed_location_ids')74 def _onchange_allowed_location_ids(self):75 self.ensure_one()76 self.allowed_location_ids_computed = self._get_allowed_locations()77 self.clear_wh_rule_caches()78 @api.multi79 @api.onchange('allowed_picking_type_ids')80 def _onchange_allowed_picking_type_ids(self):81 self.ensure_one()82 self.allowed_picking_type_ids_computed = self._get_allowed_picking_types()83 self.clear_wh_rule_caches()84 @api.model85 def _recompute_location_restrictions(self):86 # Helper function to recompute the allowed IDs for users who are *not* restricted87 self.search([("restrict_wh_locations", "=", False)])._onchange_restrict_wh_locations()88 @api.multi89 def clear_wh_rule_caches(self):90 # Invalidate the ir.rule cache to ensure that changes take effect immediately...

Full Screen

Full Screen

stock_picking_wizard.py

Source:stock_picking_wizard.py Github

copy

Full Screen

...19 stock_picking_obj = self.env['stock.picking']20 pickings = stock_picking_obj.browse(self.env.context['active_ids'])21 first_operation = pickings.mapped('pack_operation_product_ids')[:1]22 return first_operation.location_dest_id.id23 def _get_allowed_locations(self):24 return ['internal']25 def _get_allowed_picking(self):26 return ['assigned']27 location_dest_id = fields.Many2one(28 comodel_name='stock.location',29 string='Actual destination location',30 required=True,31 readonly=True,32 )33 old_location_dest_id = fields.Many2one(34 comodel_name='stock.location',35 string='Old destination location',36 default=_default_old_dest_location_id,37 domain=lambda self: [('usage', 'in', self._get_allowed_locations())],38 )39 new_location_dest_id = fields.Many2one(40 comodel_name='stock.location',41 string='New destination location',42 required=True,43 domain=lambda self: [('usage', 'in', self._get_allowed_locations())],44 )45 change_all = fields.Boolean(46 string='Change All',47 help='Check if you want change all operations without filter '48 'by old location')49 def check_forbbiden_pickings(self, pickings):50 forbidden_pickings = pickings.filtered(51 lambda x: x.state not in self._get_allowed_picking())52 if forbidden_pickings:53 raise UserError(_(54 'You can not change operations destination location if '55 'picking state not is in %s') % ','.join(56 self._get_allowed_picking()))57 @api.multi...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful