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).
location_obj = self.pool.get('stock.location')
#create view location for warehouse
location_obj = self.pool.get('stock.location')
#create view location for warehouse
- wh_loc_id = location_obj.create(cr, uid, {
'name': _(vals.get('code')),
'usage': 'view',
'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'})
vals['view_location_id'] = wh_loc_id
#create all location
def_values = self.default_get(cr, uid, {'reception_steps', 'delivery_steps'})
{'name': _('Packing Zone'), 'active': delivery_steps == 'pick_pack_ship', 'field': 'wh_pack_stock_loc_id'},
]
for values in sub_locations:
{'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, {
'name': values['name'],
'usage': 'internal',
'location_id': wh_loc_id,
'active': values['active'],
'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
vals[values['field']] = location_id
#create WH