xrg has proposed merging lp:~openerp-dev/openobject-server/trunk-bug-795444-xrg 
into lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #795444 in OpenERP Server: "res.lang, ir.values: don't use ir.values as 
defaults when creating"
  https://bugs.launchpad.net/openobject-server/+bug/795444

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-795444-xrg/+merge/64137
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-795444-xrg/+merge/64137
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-bug-795444-xrg.
=== modified file 'openerp/addons/base/ir/ir_values.py'
--- openerp/addons/base/ir/ir_values.py	2011-05-25 15:17:22 +0000
+++ openerp/addons/base/ir/ir_values.py	2011-06-10 09:43:30 +0000
@@ -141,7 +141,9 @@
                 vals['company_id']=cid
             if res_id:
                 vals['res_id']= res_id
-            ids_res.append(self.create(cr, uid, vals))
+            # Note that __ignore_ir_values means vals will not be appended with a recursive
+            # lookup using self.ir_get(, model='ir.values') !
+            ids_res.append(self.create(cr, uid, vals, context={'__ignore_ir_values': True}))
         return ids_res
 
     def get(self, cr, uid, key, key2, models, meta=False, context=None, res_id_req=False, without_user=True, key2_req=True):

=== modified file 'openerp/addons/base/res/res_lang.py'
--- openerp/addons/base/res/res_lang.py	2011-06-03 08:57:58 +0000
+++ openerp/addons/base/res/res_lang.py	2011-06-10 09:43:30 +0000
@@ -109,7 +109,7 @@
         }
         lang_id = False
         try:
-            lang_id = self.create(cr, uid, lang_info)
+            lang_id = self.create(cr, uid, lang_info, context={'__ignore_ir_values':True})
         finally:
             tools.resetlocale()
         return lang_id

=== modified file 'openerp/modules/loading.py'
--- openerp/modules/loading.py	2011-05-17 09:18:22 +0000
+++ openerp/modules/loading.py	2011-06-10 09:43:30 +0000
@@ -138,13 +138,13 @@
                 if ext == '.csv':
                     if kind in ('init', 'init_xml'):
                         noupdate = True
-                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
+                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate, context={ '__ignore_ir_values': True })
                 elif ext == '.sql':
                     process_sql_file(cr, fp)
                 elif ext == '.yml':
-                    tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate)
+                    tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate, context={ '__ignore_ir_values': True })
                 else:
-                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
+                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report, context={ '__ignore_ir_values': True })
             finally:
                 fp.close()
 

=== modified file 'openerp/tools/convert.py'
--- openerp/tools/convert.py	2011-05-16 15:05:34 +0000
+++ openerp/tools/convert.py	2011-06-10 09:43:30 +0000
@@ -347,7 +347,10 @@
                     groups_value.append((4, group_id))
             res['groups_id'] = groups_value
 
-        id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.report.xml", self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
+        id = self.pool.get('ir.model.data')._update(cr, self.uid, 
+                "ir.actions.report.xml", self.module, res, xml_id, 
+                noupdate=self.isnoupdate(data_node), mode=self.mode,
+                context=self.context)
         self.idref[xml_id] = int(id)
 
         if not rec.get('menu') or eval(rec.get('menu','False')):
@@ -390,7 +393,10 @@
                     groups_value.append((4, group_id))
             res['groups_id'] = groups_value
 
-        id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.wizard", self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
+        id = self.pool.get('ir.model.data')._update(cr, self.uid,
+                "ir.actions.wizard", self.module, res, xml_id,
+                noupdate=self.isnoupdate(data_node), mode=self.mode,
+                context=self.context)
         self.idref[xml_id] = int(id)
         # ir_set
         if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:
@@ -412,14 +418,19 @@
 
         res = {'name': name, 'url': url, 'target':target}
 
-        id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.url", self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
+        id = self.pool.get('ir.model.data')._update(cr, self.uid,
+                "ir.actions.url", self.module, res, xml_id, 
+                noupdate=self.isnoupdate(data_node), mode=self.mode,
+                context=self.context)
         self.idref[xml_id] = int(id)
         # ir_set
         if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:
             keyword = str(rec.get('keyword','') or 'client_action_multi')
             value = 'ir.actions.url,'+str(id)
             replace = rec.get("replace",'') or True
-            self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', keyword, url, ["ir.actions.url"], value, replace=replace, isobject=True, xml_id=xml_id)
+            self.pool.get('ir.model.data').ir_set(cr, self.uid, 
+                    'action', keyword, url, ["ir.actions.url"], value, 
+                    replace=replace, isobject=True, xml_id=xml_id)
         elif self.mode=='update' and (rec.get('menu') and eval(rec.get('menu','False'))==False):
             # Special check for URL having attribute menu=False on update
             value = 'ir.actions.url,'+str(id)
@@ -522,7 +533,10 @@
             res['target'] = rec.get('target','')
         if rec.get('multi'):
             res['multi'] = rec.get('multi', False)
-        id = self.pool.get('ir.model.data')._update(cr, self.uid, 'ir.actions.act_window', self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
+        id = self.pool.get('ir.model.data')._update(cr, self.uid,
+                'ir.actions.act_window', self.module, res, xml_id,
+                noupdate=self.isnoupdate(data_node), mode=self.mode,
+                context=self.context)
         self.idref[xml_id] = int(id)
 
         if src_model:
@@ -679,7 +693,11 @@
 
         xml_id = rec.get('id','').encode('utf8')
         self._test_xml_id(xml_id)
-        pid = self.pool.get('ir.model.data')._update(cr, self.uid, 'ir.ui.menu', self.module, values, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode, res_id=res and res[0] or False)
+        pid = self.pool.get('ir.model.data')._update(cr, self.uid, 
+                'ir.ui.menu', self.module, values, xml_id,
+                noupdate=self.isnoupdate(data_node), mode=self.mode,
+                res_id=res and res[0] or False,
+                context=self.context)
 
         if rec_id and pid:
             self.idref[rec_id] = int(pid)
@@ -774,9 +792,9 @@
         model = self.pool.get(rec_model)
         assert model, "The model %s does not exist !" % (rec_model,)
         rec_id = rec.get("id",'').encode('ascii')
-        rec_context = rec.get("context", None)
-        if rec_context:
-            rec_context = unsafe_eval(rec_context)
+        rec_context = self.context.copy()
+        if rec.get("context", None):
+            rec_context.update(unsafe_eval(rec.get('context')))
         self._test_xml_id(rec_id)
         if self.isnoupdate(data_node) and self.mode != 'init':
             # check if the xml record has an id string
@@ -849,7 +867,11 @@
                         f_val = int(f_val)
             res[f_name] = f_val
 
-        id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
+        id = self.pool.get('ir.model.data')._update(cr, self.uid,
+                rec_model, self.module, res, rec_id or False,
+                not self.isnoupdate(data_node),
+                noupdate=self.isnoupdate(data_node),
+                mode=self.mode, context=rec_context )
         if rec_id:
             self.idref[rec_id] = int(id)
         if config.get('import_partial', False):
@@ -892,7 +914,7 @@
                             raise
         return True
 
-    def __init__(self, cr, module, idref, mode, report=None, noupdate=False):
+    def __init__(self, cr, module, idref, mode, report=None, noupdate=False, context=None):
 
         self.logger = logging.getLogger('init')
         self.mode = mode
@@ -905,6 +927,7 @@
             report = assertion_report()
         self.assert_report = report
         self.noupdate = noupdate
+        self.context = context or {}
         self._tags = {
             'menuitem': self._tag_menuitem,
             'record': self._tag_record,
@@ -920,7 +943,7 @@
         }
 
 def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
-        noupdate=False):
+        noupdate=False, context=None):
     '''Import csv file :
         quote: "
         delimiter: ,
@@ -964,7 +987,8 @@
             datas.append(map(lambda x: misc.ustr(x), line))
         except:
             logger.error("Cannot import the line: %s", line)
-    result, rows, warning_msg, dummy = pool.get(model).import_data(cr, uid, fields, datas,mode, module, noupdate, filename=fname_partial)
+    result, rows, warning_msg, dummy = pool.get(model).import_data(cr, uid,
+        fields, datas,mode, module, noupdate, filename=fname_partial, context=context)
     if result < 0:
         # Report failed import and abort module install
         raise Exception(_('Module loading failed: file %s/%s could not be processed:\n %s') % (module, fname, warning_msg))
@@ -977,7 +1001,7 @@
 #
 # xml import/export
 #
-def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None):
+def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None, context=None):
     doc = etree.parse(xmlfile)
     relaxng = etree.RelaxNG(
         etree.parse(os.path.join(config['root_path'],'import_xml.rng' )))
@@ -991,7 +1015,7 @@
 
     if idref is None:
         idref={}
-    obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate)
+    obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate, context=context)
     obj.parse(doc.getroot())
     return True
 

=== modified file 'openerp/tools/yaml_import.py'
--- openerp/tools/yaml_import.py	2011-06-05 13:51:16 +0000
+++ openerp/tools/yaml_import.py	2011-06-10 09:43:30 +0000
@@ -132,7 +132,7 @@
         self.logger = logging.getLogger("%s.%s" % (logger_channel, self.module))
         self.pool = pooler.get_pool(cr.dbname)
         self.uid = 1
-        self.context = {} # opererp context
+        self.context = kwargs.get('context', {})
         self.eval_context = {'ref': self._ref(),
                              '_ref': self._ref(), # added '_ref' so that record['ref'] is possible
                              'time': time,
@@ -792,7 +792,7 @@
             is_preceded_by_comment = False
         return is_preceded_by_comment
 
-def yaml_import(cr, module, yamlfile, idref=None, mode='init', noupdate=False):
+def yaml_import(cr, module, yamlfile, idref=None, mode='init', noupdate=False, context=None):
     if idref is None:
         idref = {}
     yaml_string = yamlfile.read()

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to