From 9bf6f0310e3eef2bb526ee09e01d1d402649f712 Mon Sep 17 00:00:00 2001 From: Kersten Jeremy Date: Thu, 20 Mar 2014 19:02:40 +0100 Subject: [PATCH] [FIX] Move default value in the _defaults of model and not in default_get. Don't override the location_id if the super get_default don't retrun a value. Else it is impossible to set a default value, because the ir_values is always overrided with stock_location_stock as location_id bzr revid: jke@openerp.com-20140320180240-un42lptu3pjnsmxq --- .../stock/wizard/stock_change_product_qty.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py index 01ed6f2409a..cf4099ac3ba 100644 --- a/addons/stock/wizard/stock_change_product_qty.py +++ b/addons/stock/wizard/stock_change_product_qty.py @@ -33,6 +33,10 @@ class stock_change_product_qty(osv.osv_memory): 'prodlot_id': fields.many2one('stock.production.lot', 'Serial Number', domain="[('product_id','=',product_id)]"), 'location_id': fields.many2one('stock.location', 'Location', required=True, domain="[('usage', '=', 'internal')]"), } + _defaults = { + 'new_quantity': 1, + 'product_id': lambda self, cr, uid, ctx: ctx and ctx.get('active_id', False) or False + } def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): if context is None: context = {} @@ -54,20 +58,22 @@ class stock_change_product_qty(osv.osv_memory): @param context: A standard dictionary @return: A dictionary which of fields with values. """ - product_id = context and context.get('active_id', False) or False + res = super(stock_change_product_qty, self).default_get(cr, uid, fields, context=context) - if 'new_quantity' in fields: - res.update({'new_quantity': 1}) - if 'product_id' in fields: - res.update({'product_id': product_id}) if 'location_id' in fields: - try: - model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') - self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context) - except (orm.except_orm, ValueError): - location_id = False - res.update({'location_id': location_id}) + location_id = res.get('location_id', False) + if not location_id: + try: + model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') + except (orm.except_orm, ValueError): + pass + if location_id: + try: + self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context) + except (orm.except_orm, ValueError): + pass + res['location_id'] = location_id return res def change_product_qty(self, cr, uid, ids, context=None):