|
|
customer_loc, __ = self.env['stock.warehouse']._get_partner_locations()
for move in self:
location_dest = False
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_transit = False
if location_dest:
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/Warehouse transfers)
location_dest = move.forecasted_location_id
move.location_dest_id = location_dest
|
|