diff --git a/addons/stock/stock.py b/addons/stock/stock.py index e99a8c84170..ac11920f8a6 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -3041,20 +3041,33 @@ class stock_warehouse(osv.osv): raise osv.except_osv(_('Error!'), _('Can\'t find any customer or supplier location.')) return location_obj.browse(cr, uid, [customer_loc, supplier_loc], context=context) + def _location_used(self, cr, uid, location_id, warehouse, context=None): + pull_obj = self.pool['procurement.rule'] + push_obj = self.pool['stock.location.path'] + pulls = pull_obj.search(cr, uid, ['&', ('route_id', 'not in ', [x.id for x in warehouse.route_ids]), '|', ('location_src_id', '=', location_id), ('location_id', '=', location_id)], context=context) + pushs = push_obj.search(cr, uid, ['&', ('route_id', 'not in ', [x.id for x in warehouse.route_ids]), '|', ('location_from_id', '=', location_id), ('location_dest_id', '=', location_id)], context=context) + if pulls or pushs: + return True + return False + def switch_location(self, cr, uid, ids, warehouse, new_reception_step=False, new_delivery_step=False, context=None): location_obj = self.pool.get('stock.location') new_reception_step = new_reception_step or warehouse.reception_steps new_delivery_step = new_delivery_step or warehouse.delivery_steps if warehouse.reception_steps != new_reception_step: - location_obj.write(cr, uid, [warehouse.wh_input_stock_loc_id.id, warehouse.wh_qc_stock_loc_id.id], {'active': False}, context=context) + if not self._location_used(cr, uid, warehouse.wh_input_stock_loc_id.id, warehouse, context=context): + location_obj.write(cr, uid, [warehouse.wh_input_stock_loc_id.id, warehouse.wh_qc_stock_loc_id.id], {'active': False}, context=context) if new_reception_step != 'one_step': location_obj.write(cr, uid, warehouse.wh_input_stock_loc_id.id, {'active': True}, context=context) if new_reception_step == 'three_steps': location_obj.write(cr, uid, warehouse.wh_qc_stock_loc_id.id, {'active': True}, context=context) if warehouse.delivery_steps != new_delivery_step: - location_obj.write(cr, uid, [warehouse.wh_output_stock_loc_id.id, warehouse.wh_pack_stock_loc_id.id], {'active': False}, context=context) + if not self._location_used(cr, uid, warehouse.wh_output_stock_loc_id.id, warehouse, context=context): + location_obj.write(cr, uid, [warehouse.wh_output_stock_loc_id.id], {'active': False}, context=context) + if not self._location_used(cr, uid, warehouse.wh_pack_stock_loc_id.id, warehouse, context=context): + location_obj.write(cr, uid, [warehouse.wh_pack_stock_loc_id.id], {'active': False}, context=context) if new_delivery_step != 'ship_only': location_obj.write(cr, uid, warehouse.wh_output_stock_loc_id.id, {'active': True}, context=context) if new_delivery_step == 'pick_pack_ship':