diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 66024256f9a..b48dd88b81a 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -552,7 +552,6 @@ class stock_warehouse_orderpoint(osv.osv): 'qty_multiple': lambda *a: 1, 'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'stock.orderpoint') or '', 'product_uom': lambda sel, cr, uid, context: context.get('product_uom', False), - 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=c) } _sql_constraints = [ ('qty_multiple_check', 'CHECK( qty_multiple > 0 )', 'Qty Multiple must be greater than zero.'), @@ -562,14 +561,15 @@ class stock_warehouse_orderpoint(osv.osv): ] def default_get(self, cr, uid, fields, context=None): + warehouse_obj = self.pool.get('stock.warehouse') res = super(stock_warehouse_orderpoint, self).default_get(cr, uid, fields, context) + res['company_id'] = self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=context) # default 'warehouse_id' and 'location_id' if 'warehouse_id' not in res: - warehouse = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'warehouse0', context) - res['warehouse_id'] = warehouse.id + warehouse_ids = warehouse_obj.search(cr, uid, [('company_id', '=', res['company_id'])], context=context) + res['warehouse_id'] = warehouse_ids and warehouse_ids[0] or False if 'location_id' not in res: - warehouse = self.pool.get('stock.warehouse').browse(cr, uid, res['warehouse_id'], context) - res['location_id'] = warehouse.lot_stock_id.id + res['location_id'] = False if not res.get('warehouse_id') else warehouse_obj.browse(cr, uid, res['warehouse_id'], context).lot_stock_id.id return res def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context=None):