From d6fd96d0e9930647edc164ccff4cba1754e28543 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 11 Sep 2014 11:25:36 +0200 Subject: [PATCH] [FIX] stock: multicompany warehouse creation When creating a new warehouse, the linked locations should have the same company as the warehouse. The company_id field is required on warehouse (not necessary in vals as could be added by default values) while it is not for stock.location (meaning global location, also filled with default value). --- addons/stock/stock.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index dd2b07c..47bf0ad 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -3229,11 +3229,14 @@ class stock_warehouse(osv.osv): location_obj = self.pool.get('stock.location') #create view location for warehouse - wh_loc_id = location_obj.create(cr, uid, { + loc_vals = { 'name': _(vals.get('code')), 'usage': 'view', - 'location_id': data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_locations')[1] - }, context=context) + 'location_id': data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_locations')[1], + } + if vals.get('company_id'): + loc_vals['company_id'] = vals.get('company_id') + wh_loc_id = location_obj.create(cr, uid, loc_vals, context=context) vals['view_location_id'] = wh_loc_id #create all location def_values = self.default_get(cr, uid, {'reception_steps', 'delivery_steps'}) @@ -3249,12 +3252,15 @@ class stock_warehouse(osv.osv): {'name': _('Packing Zone'), 'active': delivery_steps == 'pick_pack_ship', 'field': 'wh_pack_stock_loc_id'}, ] for values in sub_locations: - location_id = location_obj.create(cr, uid, { + loc_vals = { 'name': values['name'], 'usage': 'internal', 'location_id': wh_loc_id, 'active': values['active'], - }, context=context_with_inactive) + } + if vals.get('company_id'): + loc_vals['company_id'] = vals.get('company_id') + location_id = location_obj.create(cr, uid, loc_vals, context=context_with_inactive) vals[values['field']] = location_id #create WH -- 1.7.10.4