[FIX] Import : Context of the action/screen passed,taken into consideration while importing

bzr revid: jvo@tinyerp.com-20091005121029-6sy1k3uvkpi2i8of
This commit is contained in:
Jay (Open ERP) 2009-10-05 17:40:29 +05:30
parent f822efa074
commit f590b74318
2 changed files with 15 additions and 13 deletions

View File

@ -445,10 +445,11 @@ class ir_model_data(osv.osv):
id = False id = False
return id 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 warning = True
model_obj = self.pool.get(model) model_obj = self.pool.get(model)
context = {} if not context:
context = {}
if xml_id and ('.' in xml_id): 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) 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 warning = False
@ -471,12 +472,12 @@ class ir_model_data(osv.osv):
res_id,action_id = res_id2,action_id2 res_id,action_id = res_id2,action_id2
if action_id and res_id: 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], { self.write(cr, uid, [action_id], {
'date_update': time.strftime('%Y-%m-%d %H:%M:%S'), 'date_update': time.strftime('%Y-%m-%d %H:%M:%S'),
}) },context=context)
elif res_id: elif res_id:
model_obj.write(cr, uid, [res_id], values) model_obj.write(cr, uid, [res_id], values, context=context)
if xml_id: if xml_id:
self.create(cr, uid, { self.create(cr, uid, {
'name': xml_id, 'name': xml_id,
@ -484,21 +485,21 @@ class ir_model_data(osv.osv):
'module':module, 'module':module,
'res_id':res_id, 'res_id':res_id,
'noupdate': noupdate, 'noupdate': noupdate,
}) },context=context)
if model_obj._inherits: if model_obj._inherits:
for table in model_obj._inherits: for table in model_obj._inherits:
inherit_id = model_obj.browse(cr, uid, 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, { self.create(cr, uid, {
'name': xml_id + '_' + table.replace('.', '_'), 'name': xml_id + '_' + table.replace('.', '_'),
'model': table, 'model': table,
'module': module, 'module': module,
'res_id': inherit_id, 'res_id': inherit_id,
'noupdate': noupdate, 'noupdate': noupdate,
}) },context=context)
else: else:
if mode=='init' or (mode=='update' and xml_id): 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: if xml_id:
self.create(cr, uid, { self.create(cr, uid, {
'name': xml_id, 'name': xml_id,
@ -506,18 +507,18 @@ class ir_model_data(osv.osv):
'module': module, 'module': module,
'res_id': res_id, 'res_id': res_id,
'noupdate': noupdate 'noupdate': noupdate
}) },context=context)
if model_obj._inherits: if model_obj._inherits:
for table in model_obj._inherits: for table in model_obj._inherits:
inherit_id = model_obj.browse(cr, uid, 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, { self.create(cr, uid, {
'name': xml_id + '_' + table.replace('.', '_'), 'name': xml_id + '_' + table.replace('.', '_'),
'model': table, 'model': table,
'module': module, 'module': module,
'res_id': inherit_id, 'res_id': inherit_id,
'noupdate': noupdate, 'noupdate': noupdate,
}) },context=context)
if xml_id: if xml_id:
if res_id: if res_id:
self.loads[(module, xml_id)] = (model, res_id) self.loads[(module, xml_id)] = (model, res_id)

View File

@ -577,6 +577,7 @@ class orm_template(object):
raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),)) raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),))
if not line[i]: if not line[i]:
continue continue
field = fields[i] field = fields[i]
if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'): if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'):
# Database ID # Database ID
@ -811,7 +812,7 @@ class orm_template(object):
try: try:
id = ir_model_data_obj._update(cr, uid, self._name, id = ir_model_data_obj._update(cr, uid, self._name,
current_module, res, xml_id=data_id, mode=mode, 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: except Exception, e:
import psycopg2 import psycopg2
if isinstance(e,psycopg2.IntegrityError): if isinstance(e,psycopg2.IntegrityError):