[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) <whe@odoo.com>
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
Arnold Moyaux
2024-04-12 16:57:51 +00:00
parent 8db471e742
commit d132cea05f
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -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")
+3 -1
View File
@@ -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)