From d132cea05f92bebb63a1dafa82d8bde3d2265f95 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 29 Feb 2024 16:24:09 +0100 Subject: [PATCH] [FIX] stock: push in intercompany It's not possible to push in intercompany location because the warehouse is set base on the initial move. However in intercompany we don't have a warehouse in the most cases. Also there is an issue with the cache holding the route on the product for the current company. So we invalidate it to retrieve all the routes among the different companies closes odoo/odoo#161717 X-original-commit: f16e0a2c954f1dce14880d62b6c07518f7317d1b Signed-off-by: William Henrotin (whe) Signed-off-by: Arnold Moyaux (arm) --- addons/stock/models/product.py | 2 +- addons/stock/models/stock_move.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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)