From 6c8ed08bf3457838d06c49ef4bc40e786124aaee Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 1 Oct 2012 16:27:35 +0200 Subject: [PATCH 01/11] [IMP] yaml processing: fixed the creation of record through yaml files in order to use the views and on_change() functions that match the initial fields_view_get(). bzr revid: qdp-launchpad@openerp.com-20121001142735-bvqx48fbt9lyesjw --- openerp/tools/yaml_import.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 14b857cd658..f88f253c0f2 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -313,13 +313,14 @@ class YamlInterpreter(object): #context = self.get_context(record, self.eval_context) #TOFIX: record.context like {'withoutemployee':True} should pass from self.eval_context. example: test_project.yml in project module context = record.context + fields_view_get_result = False if view_id: varg = view_id if view_id is True: varg = False - view = model.fields_view_get(self.cr, SUPERUSER_ID, varg, 'form', context) - view_id = etree.fromstring(view['arch'].encode('utf-8')) + fields_view_get_result = model.fields_view_get(self.cr, SUPERUSER_ID, varg, 'form', context) + view_id = etree.fromstring(fields_view_get_result['arch'].encode('utf-8')) - record_dict = self._create_record(model, fields, view_id, default=default) + record_dict = self._create_record(model, fields, view_id, default=default, fields_view_get=fields_view_get_result) _logger.debug("RECORD_DICT %s" % record_dict) id = self.pool.get('ir.model.data')._update(self.cr, SUPERUSER_ID, record.model, \ self.module, record_dict, record.id, noupdate=self.isnoupdate(record), mode=self.mode, context=context) @@ -327,7 +328,7 @@ class YamlInterpreter(object): if config.get('import_partial'): self.cr.commit() - def _create_record(self, model, fields, view=False, parent={}, default=True): + def _create_record(self, model, fields, view=False, parent={}, default=True, fields_view_get=None): if view is not False: defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, {}, context=self.context) or {} fg = model.fields_get(self.cr, SUPERUSER_ID, context=self.context) @@ -359,12 +360,14 @@ class YamlInterpreter(object): view2 = None # if the form view is not inline, we call fields_view_get if (view is not False) and (fg[field_name]['type']=='one2many'): - view2 = view.find("field[@name='%s']/form"%(field_name,)) + tmp = fields_view_get['fields'][field_name]['views'] + if tmp.has_key('form'): + view2 = tmp.get('form') if not view2: view2 = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) - view2 = etree.fromstring(view2['arch'].encode('utf-8')) + view2 = etree.fromstring(view2['arch'].encode('utf-8')) - field_value = self._eval_field(model, field_name, fields[field_name], view2, parent=record_dict, default=default) + field_value = self._eval_field(model, field_name, fields[field_name], view2, parent=record_dict, default=default, fields_view_get=fields_view_get) record_dict[field_name] = field_value #if (field_name in defaults) and defaults[field_name] == field_value: # print '*** You can remove these lines:', field_name, field_value @@ -409,7 +412,7 @@ class YamlInterpreter(object): for field_name, expression in fields.items(): if field_name in record_dict: continue - field_value = self._eval_field(model, field_name, expression, default=False) + field_value = self._eval_field(model, field_name, expression, default=False, fields_view_get=fields_view_get) record_dict[field_name] = field_value return record_dict @@ -440,7 +443,7 @@ class YamlInterpreter(object): def process_eval(self, node): return eval(node.expression, self.eval_context) - def _eval_field(self, model, field_name, expression, view=False, parent={}, default=True): + def _eval_field(self, model, field_name, expression, view=False, parent={}, default=True, fields_view_get=None): # TODO this should be refactored as something like model.get_field() in bin/osv if field_name in model._columns: column = model._columns[field_name] @@ -461,7 +464,7 @@ class YamlInterpreter(object): value = self.get_id(expression) elif column._type == "one2many": other_model = self.get_model(column._obj) - value = [(0, 0, self._create_record(other_model, fields, view, parent, default=default)) for fields in expression] + value = [(0, 0, self._create_record(other_model, fields, view, parent, default=default, fields_view_get=fields_view_get)) for fields in expression] elif column._type == "many2many": ids = [self.get_id(xml_id) for xml_id in expression] value = [(6, 0, ids)] From 7812c73354d9ca924c109b3c6331bfbe1986f388 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 1 Oct 2012 17:38:06 +0200 Subject: [PATCH 02/11] [IMP] yaml processing: improved previous patch by replacing the old parameter view with the result of fields_view_get() directly, to avoid having an extra parameter a bit useless bzr revid: qdp-launchpad@openerp.com-20121001153806-k40ly5vdzh1v3hv3 --- openerp/tools/yaml_import.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index f88f253c0f2..a5de5873908 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -313,14 +313,13 @@ class YamlInterpreter(object): #context = self.get_context(record, self.eval_context) #TOFIX: record.context like {'withoutemployee':True} should pass from self.eval_context. example: test_project.yml in project module context = record.context - fields_view_get_result = False + view_info = False if view_id: varg = view_id if view_id is True: varg = False - fields_view_get_result = model.fields_view_get(self.cr, SUPERUSER_ID, varg, 'form', context) - view_id = etree.fromstring(fields_view_get_result['arch'].encode('utf-8')) + view_info = model.fields_view_get(self.cr, SUPERUSER_ID, varg, 'form', context) - record_dict = self._create_record(model, fields, view_id, default=default, fields_view_get=fields_view_get_result) + record_dict = self._create_record(model, fields, view_info, default=default) _logger.debug("RECORD_DICT %s" % record_dict) id = self.pool.get('ir.model.data')._update(self.cr, SUPERUSER_ID, record.model, \ self.module, record_dict, record.id, noupdate=self.isnoupdate(record), mode=self.mode, context=context) @@ -328,7 +327,8 @@ class YamlInterpreter(object): if config.get('import_partial'): self.cr.commit() - def _create_record(self, model, fields, view=False, parent={}, default=True, fields_view_get=None): + def _create_record(self, model, fields, view_info=False, parent={}, default=True): + view = view_info and etree.fromstring(view_info['arch'].encode('utf-8')) or False if view is not False: defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, {}, context=self.context) or {} fg = model.fields_get(self.cr, SUPERUSER_ID, context=self.context) @@ -357,17 +357,15 @@ class YamlInterpreter(object): field_name = el.attrib['name'] assert field_name in fg, "The field '%s' is defined in the form view but not on the object '%s'!" % (field_name, model._name) if field_name in fields: - view2 = None + one2many_form_view = None # if the form view is not inline, we call fields_view_get if (view is not False) and (fg[field_name]['type']=='one2many'): - tmp = fields_view_get['fields'][field_name]['views'] - if tmp.has_key('form'): - view2 = tmp.get('form') - if not view2: - view2 = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) - view2 = etree.fromstring(view2['arch'].encode('utf-8')) + one2many_form_view = view_info['fields'][field_name]['views'].get('form') + if not one2many_form_view: + one2many_form_view = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) - field_value = self._eval_field(model, field_name, fields[field_name], view2, parent=record_dict, default=default, fields_view_get=fields_view_get) + view_info = one2many_form_view or view_info + field_value = self._eval_field(model, field_name, fields[field_name], view_info, parent=record_dict, default=default) record_dict[field_name] = field_value #if (field_name in defaults) and defaults[field_name] == field_value: # print '*** You can remove these lines:', field_name, field_value @@ -412,7 +410,7 @@ class YamlInterpreter(object): for field_name, expression in fields.items(): if field_name in record_dict: continue - field_value = self._eval_field(model, field_name, expression, default=False, fields_view_get=fields_view_get) + field_value = self._eval_field(model, field_name, expression, default=False) record_dict[field_name] = field_value return record_dict @@ -443,7 +441,7 @@ class YamlInterpreter(object): def process_eval(self, node): return eval(node.expression, self.eval_context) - def _eval_field(self, model, field_name, expression, view=False, parent={}, default=True, fields_view_get=None): + def _eval_field(self, model, field_name, expression, view_info=False, parent={}, default=True): # TODO this should be refactored as something like model.get_field() in bin/osv if field_name in model._columns: column = model._columns[field_name] @@ -464,7 +462,7 @@ class YamlInterpreter(object): value = self.get_id(expression) elif column._type == "one2many": other_model = self.get_model(column._obj) - value = [(0, 0, self._create_record(other_model, fields, view, parent, default=default, fields_view_get=fields_view_get)) for fields in expression] + value = [(0, 0, self._create_record(other_model, fields, view_info, parent, default=default)) for fields in expression] elif column._type == "many2many": ids = [self.get_id(xml_id) for xml_id in expression] value = [(6, 0, ids)] From fa852bab333fba81f8665a89ba15e55a2a801c48 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Tue, 2 Oct 2012 14:04:05 +0200 Subject: [PATCH 03/11] [FIX] yaml_import: don't erase the initial fields_view_get() result with the fields_view get of the first one2many fiel, other wise things get wrong -_- bzr revid: qdp-launchpad@openerp.com-20121002120405-hvy4ltgrjzesndox --- openerp/tools/yaml_import.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index a5de5873908..9ab034e55e6 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -364,8 +364,7 @@ class YamlInterpreter(object): if not one2many_form_view: one2many_form_view = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) - view_info = one2many_form_view or view_info - field_value = self._eval_field(model, field_name, fields[field_name], view_info, parent=record_dict, default=default) + field_value = self._eval_field(model, field_name, fields[field_name], one2many_form_view or view_info, parent=record_dict, default=default) record_dict[field_name] = field_value #if (field_name in defaults) and defaults[field_name] == field_value: # print '*** You can remove these lines:', field_name, field_value From 261e33f74092373052b3ed0af385bb63e228f5e9 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Tue, 2 Oct 2012 18:00:55 +0200 Subject: [PATCH 04/11] [FIX] yaml_import: the parent default values must be complete before calling the onchanges() bzr revid: qdp-launchpad@openerp.com-20121002160055-ew4377e7jcqlgzv7 --- openerp/tools/yaml_import.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 9ab034e55e6..45e8f1f627f 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -335,7 +335,7 @@ class YamlInterpreter(object): else: defaults = {} fg = {} - record_dict = {} + record_dict = defaults.copy() fields = fields or {} def process_val(key, val): @@ -368,9 +368,6 @@ class YamlInterpreter(object): record_dict[field_name] = field_value #if (field_name in defaults) and defaults[field_name] == field_value: # print '*** You can remove these lines:', field_name, field_value - elif (field_name in defaults): - if (field_name not in record_dict): - record_dict[field_name] = process_val(field_name, defaults[field_name]) else: continue From bc0e25938a67680852cfed187e0ec0270aacb957 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 3 Oct 2012 10:23:06 +0200 Subject: [PATCH 05/11] [FIX] yaml import: if a field has a default value, we must call its on_change() bzr revid: qdp-launchpad@openerp.com-20121003082306-ml0nodz6ubriwtpi --- openerp/tools/yaml_import.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 45e8f1f627f..e11347763d2 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -368,7 +368,9 @@ class YamlInterpreter(object): record_dict[field_name] = field_value #if (field_name in defaults) and defaults[field_name] == field_value: # print '*** You can remove these lines:', field_name, field_value - else: + + #if field_name has a default value or a value is given in the yaml file, we must call its on_change() + elif field_name not in defaults: continue if not el.attrib.get('on_change', False): @@ -385,7 +387,7 @@ class YamlInterpreter(object): ctx = record_dict.copy() ctx['context'] = self.context - ctx['uid'] = 1 + ctx['uid'] = SUPERUSER_ID ctx['parent'] = parent2(parent) for a in fg: if a not in ctx: From 3d1b4398bfe3d3c27988f9e27f0d856c6f2ef154 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 4 Oct 2012 13:56:17 +0200 Subject: [PATCH 06/11] [REf] yaml_import.py: refactoring of _create_record() bzr revid: qdp-launchpad@openerp.com-20121004115617-ihb4j3tdeco68vob --- openerp/tools/yaml_import.py | 111 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index f7f5f63173a..9c7b8721a1d 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -328,16 +328,6 @@ class YamlInterpreter(object): self.cr.commit() def _create_record(self, model, fields, view_info=False, parent={}, default=True): - view = view_info and etree.fromstring(view_info['arch'].encode('utf-8')) or False - if view is not False: - defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, {}, context=self.context) or {} - fg = model.fields_get(self.cr, SUPERUSER_ID, context=self.context) - else: - defaults = {} - fg = {} - record_dict = defaults.copy() - fields = fields or {} - def process_val(key, val): if fg[key]['type']=='many2one': if type(val) in (tuple,list): @@ -349,61 +339,70 @@ class YamlInterpreter(object): val = map(lambda x: (0,0,x), val) return val - # Process all on_change calls - nodes = (view is not False) and [view] or [] - while nodes: - el = nodes.pop(0) - if el.tag=='field': - field_name = el.attrib['name'] - assert field_name in fg, "The field '%s' is defined in the form view but not on the object '%s'!" % (field_name, model._name) - if field_name in fields: - one2many_form_view = None - # if the form view is not inline, we call fields_view_get - if (view is not False) and (fg[field_name]['type']=='one2many'): - one2many_form_view = view_info['fields'][field_name]['views'].get('form') - if not one2many_form_view: - one2many_form_view = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) + view = view_info and etree.fromstring(view_info['arch'].encode('utf-8')) or False + fields = fields or {} + if view is not False: + defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, fields, context=self.context) or {} + fg = view_info['fields'] + # copy the default values in record_dict, only if they are in the view (because that's what the client does) + # the other default values will be added later on by the create(). + record_dict = dict([(key, val) for key, val in defaults.items() if key in fg]) + # Process all on_change calls + nodes = [view] + while nodes: + el = nodes.pop(0) + if el.tag=='field': + field_name = el.attrib['name'] + assert field_name in fg, "The field '%s' is defined in the form view but not on the object '%s'!" % (field_name, model._name) + if field_name in fields: + one2many_form_view = None + # if the form view is not inline, we call fields_view_get + if (view is not False) and (fg[field_name]['type']=='one2many'): + one2many_form_view = view_info['fields'][field_name]['views'].get('form') + if not one2many_form_view: + one2many_form_view = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) - field_value = self._eval_field(model, field_name, fields[field_name], one2many_form_view or view_info, parent=record_dict, default=default) - record_dict[field_name] = field_value - #if (field_name in defaults) and defaults[field_name] == field_value: - # print '*** You can remove these lines:', field_name, field_value + field_value = self._eval_field(model, field_name, fields[field_name], one2many_form_view or view_info, parent=record_dict, default=default) + record_dict[field_name] = field_value + #if (field_name in defaults) and defaults[field_name] == field_value: + # print '*** You can remove these lines:', field_name, field_value - #if field_name has a default value or a value is given in the yaml file, we must call its on_change() - elif field_name not in defaults: - continue + #if field_name has a default value or a value is given in the yaml file, we must call its on_change() + elif field_name not in defaults: + continue - if not el.attrib.get('on_change', False): - continue - match = re.match("([a-z_1-9A-Z]+)\((.*)\)", el.attrib['on_change']) - assert match, "Unable to parse the on_change '%s'!" % (el.attrib['on_change'], ) + if not el.attrib.get('on_change', False): + continue + match = re.match("([a-z_1-9A-Z]+)\((.*)\)", el.attrib['on_change']) + assert match, "Unable to parse the on_change '%s'!" % (el.attrib['on_change'], ) - # creating the context - class parent2(object): - def __init__(self, d): - self.d = d - def __getattr__(self, name): - return self.d.get(name, False) + # creating the context + class parent2(object): + def __init__(self, d): + self.d = d + def __getattr__(self, name): + return self.d.get(name, False) - ctx = record_dict.copy() - ctx['context'] = self.context - ctx['uid'] = SUPERUSER_ID - ctx['parent'] = parent2(parent) - for a in fg: - if a not in ctx: - ctx[a]=process_val(a, defaults.get(a, False)) + ctx = record_dict.copy() + ctx['context'] = self.context + ctx['uid'] = SUPERUSER_ID + ctx['parent'] = parent2(parent) + for a in fg: + if a not in ctx: + ctx[a]=process_val(a, defaults.get(a, False)) - # Evaluation args - args = map(lambda x: eval(x, ctx), match.group(2).split(',')) - result = getattr(model, match.group(1))(self.cr, SUPERUSER_ID, [], *args) - for key, val in (result or {}).get('value', {}).items(): - if key not in fields: - assert key in fg, "The returning field '%s' from your on_change call '%s' does not exist on the object '%s'" % (key, match.group(1), model._name) + # Evaluation args + args = map(lambda x: eval(x, ctx), match.group(2).split(',')) + result = getattr(model, match.group(1))(self.cr, SUPERUSER_ID, [], *args) + for key, val in (result or {}).get('value', {}).items(): + assert key in fg, "The returning field '%s' from your on_change call '%s' does not exist on the object '%s' or in its view named '%s'" % (key, match.group(1), model._name, view_info['name']) record_dict[key] = process_val(key, val) #if (key in fields) and record_dict[key] == process_val(key, val): # print '*** You can remove these lines:', key, val - else: - nodes = list(el) + nodes + else: + nodes = list(el) + nodes + else: + record_dict = {} for field_name, expression in fields.items(): if field_name in record_dict: From 74f061ebee8d0cb07f979ae920702cc2dd674f6c Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 4 Oct 2012 14:15:22 +0200 Subject: [PATCH 07/11] [IMP] yaml_import.py: comments and documentation improved for _create_record() bzr revid: qdp-launchpad@openerp.com-20121004121522-ytttm7xulvo8i1wz --- openerp/tools/yaml_import.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 9c7b8721a1d..4132e5d9e9c 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -328,6 +328,18 @@ class YamlInterpreter(object): self.cr.commit() def _create_record(self, model, fields, view_info=False, parent={}, default=True): + """ + This function process the !record tag in yalm files. It simulates the record creation through an xml + view (either specified on the !record tag or the default one for this object), including the calls to + on_change() functions. + :param model: browseable object + :param fields: dictonary mapping the field names and their values + :param view_info: result of fields_view_get() called on the object + :param parent: dictionary containing the values already computed for the parent, in case of one2many fields + :param default: boolean flag depicting if the default values must be added to the process or not + :return: dictionary mapping the field names and their values to use when calling the create() function + :rtype: dict + """ def process_val(key, val): if fg[key]['type']=='many2one': if type(val) in (tuple,list): @@ -347,6 +359,7 @@ class YamlInterpreter(object): # copy the default values in record_dict, only if they are in the view (because that's what the client does) # the other default values will be added later on by the create(). record_dict = dict([(key, val) for key, val in defaults.items() if key in fg]) + # Process all on_change calls nodes = [view] while nodes: @@ -356,9 +369,10 @@ class YamlInterpreter(object): assert field_name in fg, "The field '%s' is defined in the form view but not on the object '%s'!" % (field_name, model._name) if field_name in fields: one2many_form_view = None - # if the form view is not inline, we call fields_view_get if (view is not False) and (fg[field_name]['type']=='one2many'): + # for one2many fields, we want to eval them using the inline form view defined on the parent one2many_form_view = view_info['fields'][field_name]['views'].get('form') + # if the form view is not defined inline, we call fields_view_get() if not one2many_form_view: one2many_form_view = self.pool.get(fg[field_name]['relation']).fields_view_get(self.cr, SUPERUSER_ID, False, 'form', self.context) From 9255d5d3ef5feef89156634816705db160e21261 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 4 Oct 2012 14:24:18 +0200 Subject: [PATCH 08/11] [REF] yaml_import.py: some doc and error messagse improved bzr revid: qdp-launchpad@openerp.com-20121004122418-a93kll1v7kqfrfc2 --- openerp/tools/yaml_import.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 4132e5d9e9c..a6642fd5fd4 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -336,8 +336,8 @@ class YamlInterpreter(object): :param fields: dictonary mapping the field names and their values :param view_info: result of fields_view_get() called on the object :param parent: dictionary containing the values already computed for the parent, in case of one2many fields - :param default: boolean flag depicting if the default values must be added to the process or not - :return: dictionary mapping the field names and their values to use when calling the create() function + :param default: boolean flag depicting if the default values must be processed too or not + :return: dictionary mapping the field names and their values, ready to use when calling the create() function :rtype: dict """ def process_val(key, val): @@ -409,7 +409,7 @@ class YamlInterpreter(object): args = map(lambda x: eval(x, ctx), match.group(2).split(',')) result = getattr(model, match.group(1))(self.cr, SUPERUSER_ID, [], *args) for key, val in (result or {}).get('value', {}).items(): - assert key in fg, "The returning field '%s' from your on_change call '%s' does not exist on the object '%s' or in its view named '%s'" % (key, match.group(1), model._name, view_info['name']) + assert key in fg, "The returning field '%s' from your on_change call '%s' does not exist either on the object '%s', either in the view '%s' used for the creation" % (key, match.group(1), model._name, view_info['name']) record_dict[key] = process_val(key, val) #if (key in fields) and record_dict[key] == process_val(key, val): # print '*** You can remove these lines:', key, val From 154675f4ad07ee2afa958abbe822c41298eb0ac6 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 4 Oct 2012 15:02:24 +0200 Subject: [PATCH 09/11] [FIX] base: onchange_type should return only the big image, not the medium or the small bzr revid: qdp-launchpad@openerp.com-20121004130224-t9wcp1bn0014px3f --- openerp/addons/base/res/res_partner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index bb698c2d212..c5c95276b16 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -301,7 +301,7 @@ class res_partner(osv.osv, format_address): def onchange_type(self, cr, uid, ids, is_company, context=None): # get value as for an onchange on the image - value = tools.image_get_resized_images(self._get_default_image(cr, uid, is_company, context), return_big=True) + value = tools.image_get_resized_images(self._get_default_image(cr, uid, is_company, context), return_big=True, return_medium=False, return_small=False) value['title'] = False if is_company: value['parent_id'] = False From e143ca2a5b953f7c9ead480089b501c4982b9424 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 4 Oct 2012 17:40:32 +0200 Subject: [PATCH 10/11] =?UTF-8?q?[FIX]=20yaml=5Fimport:=20on=20=5Fcreate?= =?UTF-8?q?=5Frecord,=20when=20we=20gather=20the=20default=20values=20on?= =?UTF-8?q?=20the=20object=20we=20can't=20use=20base.main=5Fcompany=C2=B4?= =?UTF-8?q?=20in=20the=20yaml=20file=20and=20it's=20not=20compatible=20wit?= =?UTF-8?q?h=20the=20function)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bzr revid: qdp-launchpad@openerp.com-20121004154032-qyq5gdur383bfxl9 --- openerp/tools/yaml_import.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index a6642fd5fd4..029e6d2c798 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -354,8 +354,10 @@ class YamlInterpreter(object): view = view_info and etree.fromstring(view_info['arch'].encode('utf-8')) or False fields = fields or {} if view is not False: - defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, fields, context=self.context) or {} fg = view_info['fields'] + # gather the default values on the object. (Can't use `fields´ as parameter instead of {} because we may + # have references like `base.main_company´ in the yaml file and it's not compatible with the function) + defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, {}, context=self.context) or {} # copy the default values in record_dict, only if they are in the view (because that's what the client does) # the other default values will be added later on by the create(). record_dict = dict([(key, val) for key, val in defaults.items() if key in fg]) From 6046f9f226691d4a9fa65465f7e859b288e652b1 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 5 Oct 2012 14:06:53 +0200 Subject: [PATCH 11/11] [REF] yaml_import: comments refactoring bzr revid: qdp-launchpad@openerp.com-20121005120653-jyq8352trvki24uc --- openerp/tools/yaml_import.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 029e6d2c798..7e1c7152b0f 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -328,17 +328,16 @@ class YamlInterpreter(object): self.cr.commit() def _create_record(self, model, fields, view_info=False, parent={}, default=True): - """ - This function process the !record tag in yalm files. It simulates the record creation through an xml - view (either specified on the !record tag or the default one for this object), including the calls to - on_change() functions. - :param model: browseable object - :param fields: dictonary mapping the field names and their values - :param view_info: result of fields_view_get() called on the object - :param parent: dictionary containing the values already computed for the parent, in case of one2many fields - :param default: boolean flag depicting if the default values must be processed too or not - :return: dictionary mapping the field names and their values, ready to use when calling the create() function - :rtype: dict + """This function processes the !record tag in yalm files. It simulates the record creation through an xml + view (either specified on the !record tag or the default one for this object), including the calls to + on_change() functions. + :param model: model instance + :param fields: dictonary mapping the field names and their values + :param view_info: result of fields_view_get() called on the object + :param parent: dictionary containing the values already computed for the parent, in case of one2many fields + :param default: if True, the default values must be processed too or not + :return: dictionary mapping the field names and their values, ready to use when calling the create() function + :rtype: dict """ def process_val(key, val): if fg[key]['type']=='many2one': @@ -358,6 +357,7 @@ class YamlInterpreter(object): # gather the default values on the object. (Can't use `fields´ as parameter instead of {} because we may # have references like `base.main_company´ in the yaml file and it's not compatible with the function) defaults = default and model._add_missing_default_values(self.cr, SUPERUSER_ID, {}, context=self.context) or {} + # copy the default values in record_dict, only if they are in the view (because that's what the client does) # the other default values will be added later on by the create(). record_dict = dict([(key, val) for key, val in defaults.items() if key in fg])