diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 93fd3a739fd..33553352a91 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -681,7 +681,7 @@ class ProductTemplate(models.Model): default=lambda self: self.env['stock.route'].search_count([('product_selectable', '=', True)])) route_ids = fields.Many2many( 'stock.route', 'stock_route_product', 'product_id', 'route_id', 'Routes', - domain=[('product_selectable', '=', True)], + domain=[('product_selectable', '=', True)], depends_context=['company', 'allowed_companies'], help="Depending on the modules installed, this will allow you to define the route of the product: whether it will be bought, manufactured, replenished on order, etc.") nbr_moves_in = fields.Integer(compute='_compute_nbr_moves', compute_sudo=False, help="Number of incoming stock moves in the past 12 months") nbr_moves_out = fields.Integer(compute='_compute_nbr_moves', compute_sudo=False, help="Number of outgoing stock moves in the past 12 months") diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 2ae144dacfe..b7a6118c983 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -939,7 +939,9 @@ Please change the quantity done or the rounding precision of your unit of measur if move.location_dest_id.company_id == self.env.company: rule = self.env['procurement.group']._search_rule(move.route_ids, move.product_packaging_id, move.product_id, warehouse_id, domain) else: - rule = self.sudo().env['procurement.group']._search_rule(move.route_ids, move.product_packaging_id, move.product_id, warehouse_id, domain) + procurement_group = self.env['procurement.group'].sudo() + move = move.with_context(allowed_companies=self.env.user.company_ids.ids) + rule = procurement_group._search_rule(move.route_ids, move.product_packaging_id, move.product_id, False, domain) # Make sure it is not returning the return if rule and (not move.origin_returned_move_id or move.origin_returned_move_id.location_dest_id.id != rule.location_dest_id.id): new_move = rule._run_push(move)