From 6c8ed08bf3457838d06c49ef4bc40e786124aaee Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 1 Oct 2012 16:27:35 +0200 Subject: [PATCH 01/15] [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/15] [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/15] [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/15] [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/15] [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/15] [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/15] [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/15] [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/15] [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/15] =?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 dcb8a9e44182e766d80f5a36ea368a66654a23fd Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Fri, 5 Oct 2012 13:30:46 +0200 Subject: [PATCH 11/15] [FIX] Fixed more r.result issues. bzr revid: vta@openerp.com-20121005113046-mwgb0pvm4bcgf875 --- addons/web/controllers/main.py | 2 +- addons/web/static/src/js/chrome.js | 8 ++++---- addons/web/static/src/js/views.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index d1feb19e3d1..d93aef6526c 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1622,7 +1622,7 @@ class Action(openerpweb.Controller): action = req.session.model(action_type).read([action_id], False, ctx) if action: value = clean_action(req, action[0], do_not_eval) - return {'result': value} + return value @openerpweb.jsonrequest def run(self, req, action_id): diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 01bfb63a580..fe5812a9dd9 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -886,8 +886,8 @@ instance.web.UserMenu = instance.web.Widget.extend({ var self = this; if (!this.getParent().has_uncommitted_changes()) { self.rpc("/web/action/load", { action_id: "base.action_res_users_my" }, function(result) { - result.result.res_id = instance.session.uid; - self.getParent().action_manager.do_action(result.result); + result.res_id = instance.session.uid; + self.getParent().action_manager.do_action(result); }); } }, @@ -1121,7 +1121,7 @@ instance.web.WebClient = instance.web.Client.extend({ var self = this; return this.rpc("/web/action/load", { action_id: options.action_id }) .pipe(function (result) { - var action = result.result; + var action = result; if (options.needaction) { action.context.search_default_needaction_pending = true; } @@ -1166,7 +1166,7 @@ instance.web.EmbeddedClient = instance.web.Client.extend({ return $.when(this._super()).pipe(function() { return instance.session.session_authenticate(self.dbname, self.login, self.key, true).pipe(function() { return self.rpc("/web/action/load", { action_id: self.action_id }, function(result) { - var action = result.result; + var action = result; action.flags = _.extend({ //views_switcher : false, search_view : false, diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 99f4d3e35e8..a166865476a 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -231,7 +231,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ } else if (_.isNumber(action) || _.isString(action)) { var self = this; return self.rpc("/web/action/load", { action_id: action }).pipe(function(result) { - return self.do_action(result.result, on_close, clear_breadcrumbs, on_reverse_breadcrumb); + return self.do_action(result, on_close, clear_breadcrumbs, on_reverse_breadcrumb); }); } if (!action.type) { @@ -1223,7 +1223,7 @@ instance.web.View = instance.web.Widget.extend({ }; if (action_data.special) { - return handler({result: {"type":"ir.actions.act_window_close"}}); + return handler({"type":"ir.actions.act_window_close"}); } else if (action_data.type=="object") { var args = [[record_id]], additional_args = []; if (action_data.args) { From 5677716100f81621f1b16300dd2fa972dd377dbd Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 5 Oct 2012 11:19:13 +0200 Subject: [PATCH 12/15] [IMP] minor modification in field reference bzr revid: nicolas.vanhoren@openerp.com-20121005091913-35dxdxb3q315mcp1 --- addons/web/static/src/js/view_form.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 4d69e07489a..23077d19ad3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4601,18 +4601,14 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(instan } }, destroy_content: function() { - if (this.selection) { - this.selection.destroy(); - this.selection = undefined; - } - if (this.m2o) { - this.m2o.destroy(); - this.m2o = undefined; + if (this.fm) { + this.fm.destroy(); } }, initialize_content: function() { var self = this; var fm = new instance.web.form.DefaultFieldManager(this); + this.fm = fm; fm.extend_field_desc({ "selection": { selection: this.field_manager.get_field_desc(this.name).selection, From 3d6a06a319883c3ebb6255a1cac981592f5cb296 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 5 Oct 2012 12:12:35 +0200 Subject: [PATCH 13/15] [IMP] small improvement to default field manager bzr revid: nicolas.vanhoren@openerp.com-20121005101235-w3n66pjia6crxxq0 --- addons/web/static/src/js/view_form.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 23077d19ad3..b9612eba65d 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1578,6 +1578,10 @@ instance.web.form.DefaultFieldManager = instance.web.Widget.extend({ this._super(parent); this.field_descs = {}; this.eval_context = eval_context || {}; + this.set({ + display_invalid_fields: false, + actual_mode: 'create', + }); }, get_field_desc: function(field_name) { if (this.field_descs[field_name] === undefined) { From a4fbe4dec890a208250cd506b0add6eb0afd0292 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 5 Oct 2012 13:48:46 +0200 Subject: [PATCH 14/15] [IMP] improved modifiers calculus bzr revid: nicolas.vanhoren@openerp.com-20121005114846-ddc3fqpftu3k8iob --- addons/web/static/src/js/view_form.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index b9612eba65d..3fbd089e166 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1784,11 +1784,13 @@ instance.web.form.FormWidget = instance.web.Widget.extend(instance.web.form.Invi this.field_manager.on("view_content_has_changed", this, this.process_modifiers); - this.set({required: this.modifiers['required'] === true}); + this.set({ + required: false, + readonly: false, + }); // some events to make the property "effective_readonly" sync automatically with "readonly" and // "mode" on field_manager var self = this; - this.set({"readonly": this.modifiers['readonly'] === true}); var test_effective_readonly = function() { self.set({"effective_readonly": self.get("readonly") || self.field_manager.get("actual_mode") === "view"}); }; @@ -1797,6 +1799,7 @@ instance.web.form.FormWidget = instance.web.Widget.extend(instance.web.form.Invi test_effective_readonly.call(this); }, renderElement: function() { + this.process_modifiers(); this._super(); this.$el.addClass(this.node.attrs["class"] || ""); }, @@ -3979,6 +3982,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ disable_utility_classes: true, init: function(field_manager, node) { this._super(field_manager, node); + this.set({"value": []}); this.is_loaded = $.Deferred(); this.initial_is_loaded = this.is_loaded; this.is_setted = $.Deferred(); From 6046f9f226691d4a9fa65465f7e859b288e652b1 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 5 Oct 2012 14:06:53 +0200 Subject: [PATCH 15/15] [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])