diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 96a3af94ab8..2655a5381a7 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1358,7 +1358,12 @@ class StockMove(models.Model): raise UserError(_('You cannot move the same package content more than once in the same transfer or split the same package into two location.')) picking = moves_todo.mapped('picking_id') moves_todo.write({'state': 'done', 'date': fields.Datetime.now()}) - moves_todo.mapped('move_dest_ids')._action_assign() + + move_dests_per_company = defaultdict(lambda: self.env['stock.move']) + for move_dest in moves_todo.move_dest_ids: + move_dests_per_company[move_dest.company_id.id] |= move_dest + for company_id, move_dests in move_dests_per_company.items(): + move_dests.sudo().with_company(company_id)._action_assign() # We don't want to create back order for scrap moves # Replace by a kwarg in master diff --git a/addons/stock/security/stock_security.xml b/addons/stock/security/stock_security.xml index 3ffaa1cc9ab..bbf0a2714f5 100644 --- a/addons/stock/security/stock_security.xml +++ b/addons/stock/security/stock_security.xml @@ -116,14 +116,14 @@ stock_move multi-company - ['|', ('company_id', 'in', company_ids), ('location_dest_id.company_id', '=', False)] + ['|', ('company_id', 'in', company_ids), '&', ('location_dest_id.company_id', '=', False), ('location_dest_id.usage', '=', 'transit')] stock_move_line multi-company - ['|','|',('company_id','=',False),('company_id', 'in', company_ids),('location_dest_id.company_id', '=', False)] + ['|','|',('company_id','=',False),('company_id', 'in', company_ids),'&',('location_dest_id.company_id', '=', False), ('location_dest_id.usage', '=', 'transit')]