[FIX] stock: prevent to create the reception route over and over when deleted once
When the reception route of a warehouse company is deleted by the user e.g. My company, Chicago Receipt in 1 step is deleted, and then changing the given warehouse `Incoming Shipments` multiple times e.g. from `one_step` to `two_steps` multiple time, the reception route is created again and again and again. This is because the reception route which is created for the warehouse is not being assigned to the warehouse as the `reception_route_id` once newly created. _update_routes should work the same way than _create_routes, it should return new value to write on the warehouse. based on preliminary by Denis Ledoux opw-1836544
This commit is contained in:
@@ -151,11 +151,14 @@ class Warehouse(models.Model):
|
||||
# If another partner assigned
|
||||
if vals.get('partner_id'):
|
||||
warehouses._update_partner_data(vals['partner_id'], vals.get('company_id'))
|
||||
|
||||
res = super(Warehouse, self).write(vals)
|
||||
|
||||
# check if we need to delete and recreate route
|
||||
if vals.get('reception_steps') or vals.get('delivery_steps'):
|
||||
warehouses._update_routes()
|
||||
route_vals = warehouses._update_routes()
|
||||
if route_vals:
|
||||
self.write(route_vals)
|
||||
|
||||
if vals.get('resupply_wh_ids') and not vals.get('resupply_route_ids'):
|
||||
for warehouse in warehouses:
|
||||
@@ -585,12 +588,19 @@ class Warehouse(models.Model):
|
||||
# change the default source and destination location and (de)activate picking types
|
||||
self._update_picking_type()
|
||||
# update delivery route and rules: unlink the existing rules of the warehouse delivery route and recreate it
|
||||
self._create_or_update_delivery_route(routes_data)
|
||||
delivery_route = self._create_or_update_delivery_route(routes_data)
|
||||
# update receipt route and rules: unlink the existing rules of the warehouse receipt route and recreate it
|
||||
self._create_or_update_reception_route(routes_data)
|
||||
self._create_or_update_crossdock_route(routes_data)
|
||||
self._create_or_update_mto_pull(routes_data)
|
||||
return True
|
||||
reception_route = self._create_or_update_reception_route(routes_data)
|
||||
crossdock_route = self._create_or_update_crossdock_route(routes_data)
|
||||
mto_pull = self._create_or_update_mto_pull(routes_data)
|
||||
|
||||
return {
|
||||
'route_ids': [(4, route.id) for route in reception_route | delivery_route | crossdock_route],
|
||||
'mto_pull_id': mto_pull.id,
|
||||
'reception_route_id': reception_route.id,
|
||||
'delivery_route_id': delivery_route.id,
|
||||
'crossdock_route_id': crossdock_route.id,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def change_route(self):
|
||||
|
||||
Reference in New Issue
Block a user