From 39745a429054aeee7ec64497cb5ea007409ec86c Mon Sep 17 00:00:00 2001 From: Leonardo Rochael Almeida Date: Wed, 3 Jun 2015 03:59:37 +0200 Subject: [PATCH] [FIX] YAML: Add support for `reference` fields in YAML YAML import was missing support for loading values into fields where `field.type == 'reference'`. --- openerp/addons/test_impex/__openerp__.py | 3 ++ .../tests/test_import_reference.yml | 44 +++++++++++++++++++ openerp/tools/yaml_import.py | 11 ++++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 openerp/addons/test_impex/tests/test_import_reference.yml diff --git a/openerp/addons/test_impex/__openerp__.py b/openerp/addons/test_impex/__openerp__.py index 2b52b6ad5fa..9bee558c759 100644 --- a/openerp/addons/test_impex/__openerp__.py +++ b/openerp/addons/test_impex/__openerp__.py @@ -11,5 +11,8 @@ 'data': ['ir.model.access.csv'], 'installable': True, 'auto_install': False, + 'test': [ + 'tests/test_import_reference.yml', + ] } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/test_impex/tests/test_import_reference.yml b/openerp/addons/test_impex/tests/test_import_reference.yml new file mode 100644 index 00000000000..b8c3757e333 --- /dev/null +++ b/openerp/addons/test_impex/tests/test_import_reference.yml @@ -0,0 +1,44 @@ +- | + YAML Import reference scenario: + Check that importing into a "reference" type field works with YAML using + both implicit references and !ref. + +- | + Given records imitating menu entries similar to the following entry from the base module: + + + taken from openerp/addons/base/module/module_view.xml + +- > + A Menu item using !record and implicit xml_id lookup and sequence cast: +- + !record { model: ir.ui.menu, id: test_menu_0 }: + name: "Local Modules 0" + parent_id: base.menu_management + sequence: 90 + action: base.open_module_tree + +- > + A Menu item using !record and explicit !ref and sequence !eval +- + !record { model: ir.ui.menu, id: test_menu_1 }: + name: "Local Modules 1" + parent_id: !refid base.menu_management + sequence: !eval 91 + action: !refid base.open_module_tree +- > + Then these menu items should be present, properly configured and + pointing to the same action. +- + !assert { model: ir.ui.menu, id: test_menu_0, string: menu item 0 is properly configured }: + - name == 'Local Modules 0' + - sequence == 90 + - parent_id.name == 'Modules' + - action.name == 'Local Modules' +- + !assert { model: ir.ui.menu, id: test_menu_1, string: menu item 1 is properly configured }: + - name == 'Local Modules 1' + - sequence == 91 + - parent_id.name == 'Modules' + - action.name == 'Local Modules' diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 65c78ddcc04..f475ccf2e14 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -500,7 +500,11 @@ class YamlInterpreter(object): else: value = ids elif node.id: - value = self.get_id(node.id) + if field and field.type == 'reference': + record = self.get_record(node.id) + value = "%s,%s" % (record._name, record.id) + else: + value = self.get_id(node.id) else: value = None return value @@ -518,7 +522,7 @@ class YamlInterpreter(object): elements = self.process_ref(expression, field) if field.type in ("many2many", "one2many"): value = [(6, 0, elements)] - else: # many2one + else: # many2one or reference if isinstance(elements, (list,tuple)): value = self._get_first_result(elements) else: @@ -539,6 +543,9 @@ class YamlInterpreter(object): # enforce ISO format for string datetime values, to be locale-agnostic during tests time.strptime(expression, misc.DEFAULT_SERVER_DATETIME_FORMAT) value = expression + elif field.type == "reference": + record = self.get_record(expression) + value = "%s,%s" % (record._name, record.id) else: # scalar field if is_eval(expression): value = self.process_eval(expression)