From f590b743189f5d20068905a3dfd5581f11ac2006 Mon Sep 17 00:00:00 2001 From: "Jay (Open ERP)" Date: Mon, 5 Oct 2009 17:40:29 +0530 Subject: [PATCH] [FIX] Import : Context of the action/screen passed,taken into consideration while importing bzr revid: jvo@tinyerp.com-20091005121029-6sy1k3uvkpi2i8of --- bin/addons/base/ir/ir_model.py | 25 +++++++++++++------------ bin/osv/orm.py | 3 ++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 2fe3375d0a0..d69688bf6fc 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -445,10 +445,11 @@ class ir_model_data(osv.osv): id = False return id - def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False): + def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False, context=None): warning = True model_obj = self.pool.get(model) - context = {} + if not context: + context = {} if xml_id and ('.' in xml_id): assert len(xml_id.split('.'))==2, _('"%s" contains too many dots. XML ids should not contain dots ! These are used to refer to other modules data, as in module.reference_id') % (xml_id) warning = False @@ -471,12 +472,12 @@ class ir_model_data(osv.osv): res_id,action_id = res_id2,action_id2 if action_id and res_id: - model_obj.write(cr, uid, [res_id], values) + model_obj.write(cr, uid, [res_id], values, context=context) self.write(cr, uid, [action_id], { 'date_update': time.strftime('%Y-%m-%d %H:%M:%S'), - }) + },context=context) elif res_id: - model_obj.write(cr, uid, [res_id], values) + model_obj.write(cr, uid, [res_id], values, context=context) if xml_id: self.create(cr, uid, { 'name': xml_id, @@ -484,21 +485,21 @@ class ir_model_data(osv.osv): 'module':module, 'res_id':res_id, 'noupdate': noupdate, - }) + },context=context) if model_obj._inherits: for table in model_obj._inherits: inherit_id = model_obj.browse(cr, uid, - res_id)[model_obj._inherits[table]] + res_id,context=context)[model_obj._inherits[table]] self.create(cr, uid, { 'name': xml_id + '_' + table.replace('.', '_'), 'model': table, 'module': module, 'res_id': inherit_id, 'noupdate': noupdate, - }) + },context=context) else: if mode=='init' or (mode=='update' and xml_id): - res_id = model_obj.create(cr, uid, values) + res_id = model_obj.create(cr, uid, values, context=context) if xml_id: self.create(cr, uid, { 'name': xml_id, @@ -506,18 +507,18 @@ class ir_model_data(osv.osv): 'module': module, 'res_id': res_id, 'noupdate': noupdate - }) + },context=context) if model_obj._inherits: for table in model_obj._inherits: inherit_id = model_obj.browse(cr, uid, - res_id)[model_obj._inherits[table]] + res_id,context=context)[model_obj._inherits[table]] self.create(cr, uid, { 'name': xml_id + '_' + table.replace('.', '_'), 'model': table, 'module': module, 'res_id': inherit_id, 'noupdate': noupdate, - }) + },context=context) if xml_id: if res_id: self.loads[(module, xml_id)] = (model, res_id) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index e4f36a041bd..f9a62a02f18 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -577,6 +577,7 @@ class orm_template(object): raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),)) if not line[i]: continue + field = fields[i] if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'): # Database ID @@ -811,7 +812,7 @@ class orm_template(object): try: id = ir_model_data_obj._update(cr, uid, self._name, current_module, res, xml_id=data_id, mode=mode, - noupdate=noupdate, res_id=res_id) + noupdate=noupdate, res_id=res_id, context=context) except Exception, e: import psycopg2 if isinstance(e,psycopg2.IntegrityError):