diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 36a6e696cc6..a1516d82ac0 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -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):