Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Inventory

Entity: stock.move

Compute Method: _compute_location_dest_id

View 18.0 View 20.0
Inputs Method Outputs
  • picking_id
  • picking_id.location_dest_id
  • rule_id
  • rule_id.location_dest_from_rule
  • rule_id.location_dest_id
  • picking_type_id
  • picking_type_id.default_location_dest_id
  • location_final_id
  • is_scrap
  • location_dest_id
  • company_id
  • company_id.scrap_location_id
  • forecasted_location_id
  • forecasted_location_id.usage
customer_loc, __ = self.env['stock.warehouse']._get_partner_locations()
- inter_comp_location = self.env.ref('stock.stock_location_inter_company', raise_if_not_found=False)
for move in self:
            location_dest = False
-             if move.picking_id:
+             if move.is_scrap:
+                 curr_location_dest = move.location_dest_id
+                 if (
+                     curr_location_dest
+                     and curr_location_dest.usage == 'inventory'
+                     and (
+                         not curr_location_dest.company_id
+                         or curr_location_dest.company_id == move.company_id
+                     )
+                 ):
+                     location_dest = curr_location_dest
+                 location_dest = location_dest or move.company_id.scrap_location_id
+             elif move.picking_id:
                location_dest = move.picking_id.location_dest_id
            elif move.rule_id.location_dest_from_rule:
                location_dest = move.rule_id.location_dest_id
            elif move.picking_type_id:
                location_dest = move.picking_type_id.default_location_dest_id
-             is_move_to_interco_transit = False
+             is_move_to_transit = False
            if location_dest:
-                 is_move_to_interco_transit = location_dest._child_of(customer_loc) and move.location_final_id == inter_comp_location
-             if location_dest and move.location_final_id and (move.location_final_id._child_of(location_dest) or is_move_to_interco_transit):
+                 is_move_to_transit = location_dest._child_of(customer_loc) and move.forecasted_location_id.usage == 'transit'
+             if location_dest and move.forecasted_location_id and (move.forecasted_location_id._child_of(location_dest) or is_move_to_transit):
                # Force the location_final as dest in the following cases:
                # - The location_final is a sublocation of destination -> Means we reached the end
-                 # - The location dest is an out location (i.e. Customers) but the final dest is different (e.g. Inter-Company transfers)
-                 location_dest = move.location_final_id
+                 # - The location dest is an out location (i.e. Customers) but the final dest is different (e.g. Inter-Company/Warehouse transfers)
+                 location_dest = move.forecasted_location_id
            move.location_dest_id = location_dest
  • location_dest_id

Back to entity