Merge lp:~openerp-dev/openobject-server/trunk-bug-795444-xrg into lp:openobject-server

Proposed by xrg
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-bug-795444-xrg
Merge into: lp:openobject-server
Diff against target: 225 lines (+48/-22)
5 files modified
openerp/addons/base/ir/ir_values.py (+3/-1)
openerp/addons/base/res/res_lang.py (+1/-1)
openerp/modules/loading.py (+3/-3)
openerp/tools/convert.py (+39/-15)
openerp/tools/yaml_import.py (+2/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-bug-795444-xrg
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+64137@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vo Minh Thu (thu) wrote :
Revision history for this message
Vo Minh Thu (thu) wrote :

Setting it to `Work in progress` as the related branch is in that state.

Unmerged revisions

3455. By OpenERP buildbot

addons/init: pass context to tools.convert_*

3454. By OpenERP buildbot

tools/convert,yaml_import: have context passed from caller

In the context, we will be able to distinguish if we are being called
in the module loading sequence or not

3453. By OpenERP buildbot

res.lang, ir.values: don't use ir.values as defaults when creating
(cherry picked from commit 7e419058ea3391e8b2e2bb45f8054dfb8af88e7b)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:47:26 +0000
@@ -141,7 +141,9 @@
141 vals['company_id']=cid141 vals['company_id']=cid
142 if res_id:142 if res_id:
143 vals['res_id']= res_id143 vals['res_id']= res_id
144 ids_res.append(self.create(cr, uid, vals))144 # Note that __ignore_ir_values means vals will not be appended with a recursive
145 # lookup using self.ir_get(, model='ir.values') !
146 ids_res.append(self.create(cr, uid, vals, context={'__ignore_ir_values': True}))
145 return ids_res147 return ids_res
146148
147 def get(self, cr, uid, key, key2, models, meta=False, context=None, res_id_req=False, without_user=True, key2_req=True):149 def get(self, cr, uid, key, key2, models, meta=False, context=None, res_id_req=False, without_user=True, key2_req=True):
148150
=== 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:47:26 +0000
@@ -109,7 +109,7 @@
109 }109 }
110 lang_id = False110 lang_id = False
111 try:111 try:
112 lang_id = self.create(cr, uid, lang_info)112 lang_id = self.create(cr, uid, lang_info, context={'__ignore_ir_values':True})
113 finally:113 finally:
114 tools.resetlocale()114 tools.resetlocale()
115 return lang_id115 return lang_id
116116
=== 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:47:26 +0000
@@ -138,13 +138,13 @@
138 if ext == '.csv':138 if ext == '.csv':
139 if kind in ('init', 'init_xml'):139 if kind in ('init', 'init_xml'):
140 noupdate = True140 noupdate = True
141 tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)141 tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate, context={ '__ignore_ir_values': True })
142 elif ext == '.sql':142 elif ext == '.sql':
143 process_sql_file(cr, fp)143 process_sql_file(cr, fp)
144 elif ext == '.yml':144 elif ext == '.yml':
145 tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate)145 tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate, context={ '__ignore_ir_values': True })
146 else:146 else:
147 tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)147 tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report, context={ '__ignore_ir_values': True })
148 finally:148 finally:
149 fp.close()149 fp.close()
150150
151151
=== 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:47:26 +0000
@@ -347,7 +347,10 @@
347 groups_value.append((4, group_id))347 groups_value.append((4, group_id))
348 res['groups_id'] = groups_value348 res['groups_id'] = groups_value
349349
350 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)350 id = self.pool.get('ir.model.data')._update(cr, self.uid,
351 "ir.actions.report.xml", self.module, res, xml_id,
352 noupdate=self.isnoupdate(data_node), mode=self.mode,
353 context=self.context)
351 self.idref[xml_id] = int(id)354 self.idref[xml_id] = int(id)
352355
353 if not rec.get('menu') or eval(rec.get('menu','False')):356 if not rec.get('menu') or eval(rec.get('menu','False')):
@@ -390,7 +393,10 @@
390 groups_value.append((4, group_id))393 groups_value.append((4, group_id))
391 res['groups_id'] = groups_value394 res['groups_id'] = groups_value
392395
393 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)396 id = self.pool.get('ir.model.data')._update(cr, self.uid,
397 "ir.actions.wizard", self.module, res, xml_id,
398 noupdate=self.isnoupdate(data_node), mode=self.mode,
399 context=self.context)
394 self.idref[xml_id] = int(id)400 self.idref[xml_id] = int(id)
395 # ir_set401 # ir_set
396 if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:402 if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:
@@ -412,14 +418,19 @@
412418
413 res = {'name': name, 'url': url, 'target':target}419 res = {'name': name, 'url': url, 'target':target}
414420
415 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)421 id = self.pool.get('ir.model.data')._update(cr, self.uid,
422 "ir.actions.url", self.module, res, xml_id,
423 noupdate=self.isnoupdate(data_node), mode=self.mode,
424 context=self.context)
416 self.idref[xml_id] = int(id)425 self.idref[xml_id] = int(id)
417 # ir_set426 # ir_set
418 if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:427 if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:
419 keyword = str(rec.get('keyword','') or 'client_action_multi')428 keyword = str(rec.get('keyword','') or 'client_action_multi')
420 value = 'ir.actions.url,'+str(id)429 value = 'ir.actions.url,'+str(id)
421 replace = rec.get("replace",'') or True430 replace = rec.get("replace",'') or True
422 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)431 self.pool.get('ir.model.data').ir_set(cr, self.uid,
432 'action', keyword, url, ["ir.actions.url"], value,
433 replace=replace, isobject=True, xml_id=xml_id)
423 elif self.mode=='update' and (rec.get('menu') and eval(rec.get('menu','False'))==False):434 elif self.mode=='update' and (rec.get('menu') and eval(rec.get('menu','False'))==False):
424 # Special check for URL having attribute menu=False on update435 # Special check for URL having attribute menu=False on update
425 value = 'ir.actions.url,'+str(id)436 value = 'ir.actions.url,'+str(id)
@@ -522,7 +533,10 @@
522 res['target'] = rec.get('target','')533 res['target'] = rec.get('target','')
523 if rec.get('multi'):534 if rec.get('multi'):
524 res['multi'] = rec.get('multi', False)535 res['multi'] = rec.get('multi', False)
525 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)536 id = self.pool.get('ir.model.data')._update(cr, self.uid,
537 'ir.actions.act_window', self.module, res, xml_id,
538 noupdate=self.isnoupdate(data_node), mode=self.mode,
539 context=self.context)
526 self.idref[xml_id] = int(id)540 self.idref[xml_id] = int(id)
527541
528 if src_model:542 if src_model:
@@ -679,7 +693,11 @@
679693
680 xml_id = rec.get('id','').encode('utf8')694 xml_id = rec.get('id','').encode('utf8')
681 self._test_xml_id(xml_id)695 self._test_xml_id(xml_id)
682 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)696 pid = self.pool.get('ir.model.data')._update(cr, self.uid,
697 'ir.ui.menu', self.module, values, xml_id,
698 noupdate=self.isnoupdate(data_node), mode=self.mode,
699 res_id=res and res[0] or False,
700 context=self.context)
683701
684 if rec_id and pid:702 if rec_id and pid:
685 self.idref[rec_id] = int(pid)703 self.idref[rec_id] = int(pid)
@@ -774,9 +792,9 @@
774 model = self.pool.get(rec_model)792 model = self.pool.get(rec_model)
775 assert model, "The model %s does not exist !" % (rec_model,)793 assert model, "The model %s does not exist !" % (rec_model,)
776 rec_id = rec.get("id",'').encode('ascii')794 rec_id = rec.get("id",'').encode('ascii')
777 rec_context = rec.get("context", None)795 rec_context = self.context.copy()
778 if rec_context:796 if rec.get("context", None):
779 rec_context = unsafe_eval(rec_context)797 rec_context.update(unsafe_eval(rec.get('context')))
780 self._test_xml_id(rec_id)798 self._test_xml_id(rec_id)
781 if self.isnoupdate(data_node) and self.mode != 'init':799 if self.isnoupdate(data_node) and self.mode != 'init':
782 # check if the xml record has an id string800 # check if the xml record has an id string
@@ -849,7 +867,11 @@
849 f_val = int(f_val)867 f_val = int(f_val)
850 res[f_name] = f_val868 res[f_name] = f_val
851869
852 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 )870 id = self.pool.get('ir.model.data')._update(cr, self.uid,
871 rec_model, self.module, res, rec_id or False,
872 not self.isnoupdate(data_node),
873 noupdate=self.isnoupdate(data_node),
874 mode=self.mode, context=rec_context )
853 if rec_id:875 if rec_id:
854 self.idref[rec_id] = int(id)876 self.idref[rec_id] = int(id)
855 if config.get('import_partial', False):877 if config.get('import_partial', False):
@@ -892,7 +914,7 @@
892 raise914 raise
893 return True915 return True
894916
895 def __init__(self, cr, module, idref, mode, report=None, noupdate=False):917 def __init__(self, cr, module, idref, mode, report=None, noupdate=False, context=None):
896918
897 self.logger = logging.getLogger('init')919 self.logger = logging.getLogger('init')
898 self.mode = mode920 self.mode = mode
@@ -905,6 +927,7 @@
905 report = assertion_report()927 report = assertion_report()
906 self.assert_report = report928 self.assert_report = report
907 self.noupdate = noupdate929 self.noupdate = noupdate
930 self.context = context or {}
908 self._tags = {931 self._tags = {
909 'menuitem': self._tag_menuitem,932 'menuitem': self._tag_menuitem,
910 'record': self._tag_record,933 'record': self._tag_record,
@@ -920,7 +943,7 @@
920 }943 }
921944
922def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',945def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
923 noupdate=False):946 noupdate=False, context=None):
924 '''Import csv file :947 '''Import csv file :
925 quote: "948 quote: "
926 delimiter: ,949 delimiter: ,
@@ -964,7 +987,8 @@
964 datas.append(map(lambda x: misc.ustr(x), line))987 datas.append(map(lambda x: misc.ustr(x), line))
965 except:988 except:
966 logger.error("Cannot import the line: %s", line)989 logger.error("Cannot import the line: %s", line)
967 result, rows, warning_msg, dummy = pool.get(model).import_data(cr, uid, fields, datas,mode, module, noupdate, filename=fname_partial)990 result, rows, warning_msg, dummy = pool.get(model).import_data(cr, uid,
991 fields, datas,mode, module, noupdate, filename=fname_partial, context=context)
968 if result < 0:992 if result < 0:
969 # Report failed import and abort module install993 # Report failed import and abort module install
970 raise Exception(_('Module loading failed: file %s/%s could not be processed:\n %s') % (module, fname, warning_msg))994 raise Exception(_('Module loading failed: file %s/%s could not be processed:\n %s') % (module, fname, warning_msg))
@@ -977,7 +1001,7 @@
977#1001#
978# xml import/export1002# xml import/export
979#1003#
980def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None):1004def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None, context=None):
981 doc = etree.parse(xmlfile)1005 doc = etree.parse(xmlfile)
982 relaxng = etree.RelaxNG(1006 relaxng = etree.RelaxNG(
983 etree.parse(os.path.join(config['root_path'],'import_xml.rng' )))1007 etree.parse(os.path.join(config['root_path'],'import_xml.rng' )))
@@ -991,7 +1015,7 @@
9911015
992 if idref is None:1016 if idref is None:
993 idref={}1017 idref={}
994 obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate)1018 obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate, context=context)
995 obj.parse(doc.getroot())1019 obj.parse(doc.getroot())
996 return True1020 return True
9971021
9981022
=== 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:47:26 +0000
@@ -132,7 +132,7 @@
132 self.logger = logging.getLogger("%s.%s" % (logger_channel, self.module))132 self.logger = logging.getLogger("%s.%s" % (logger_channel, self.module))
133 self.pool = pooler.get_pool(cr.dbname)133 self.pool = pooler.get_pool(cr.dbname)
134 self.uid = 1134 self.uid = 1
135 self.context = {} # opererp context135 self.context = kwargs.get('context', {})
136 self.eval_context = {'ref': self._ref(),136 self.eval_context = {'ref': self._ref(),
137 '_ref': self._ref(), # added '_ref' so that record['ref'] is possible137 '_ref': self._ref(), # added '_ref' so that record['ref'] is possible
138 'time': time,138 'time': time,
@@ -792,7 +792,7 @@
792 is_preceded_by_comment = False792 is_preceded_by_comment = False
793 return is_preceded_by_comment793 return is_preceded_by_comment
794794
795def yaml_import(cr, module, yamlfile, idref=None, mode='init', noupdate=False):795def yaml_import(cr, module, yamlfile, idref=None, mode='init', noupdate=False, context=None):
796 if idref is None:796 if idref is None:
797 idref = {}797 idref = {}
798 yaml_string = yamlfile.read()798 yaml_string = yamlfile.read()