diff options
| author | Xavier Morel <xmo@odoo.com> | 2018-02-13 17:31:40 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim-odoo@users.noreply.github.com> | 2018-02-19 10:43:15 +0100 |
| commit | a583a56324c615379e80952ae31a59efcd28d205 (patch) | |
| tree | 94f5c8f843bf4f04901cf6e41a3fc8b59c106785 /odoo/addons/test_impex | |
| parent | 906a9af8f22eb46bf806d624c69799750fc3a78c (diff) | |
[FIX] base, web: don't fold M2M when not in import compatible mode
Before this commit, if the first exported field of an M2M is `id` (the
xid) the entire M2M is folded into a single cell with comma-separated
xids and any following field is ignored. If `id` is any but the first
field, the export behaves normally (with the m2m exported as a "table"
inside the parent record).
This behaviour makes sense for import-compatible exports where the id
is the only thing which can be exported anyway, but it is troublesome
outside of that mode as the behaviour of m2m under export becomes
incoherent/unpredictable (ish) as it depends on the position of the
m2m's `id` in the exports list.
Change it so we only perform folding in import-compatible mode (which
is the default for backwards compatibility with e.g. API calling
export_data directly & the like).
opw-813361
Fixes #22600
Diffstat (limited to 'odoo/addons/test_impex')
| -rw-r--r-- | odoo/addons/test_impex/tests/test_export.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/odoo/addons/test_impex/tests/test_export.py b/odoo/addons/test_impex/tests/test_export.py index 74f62bf7189..974d20e223f 100644 --- a/odoo/addons/test_impex/tests/test_export.py +++ b/odoo/addons/test_impex/tests/test_export.py @@ -600,7 +600,54 @@ class test_m2m(CreatorCase): ['', u'export.many2many.other:13'], ]) - # essentially same as o2m, so boring + def test_multiple_records_subfield(self): + r = self.make(self.commands) + xid = self.env['ir.model.data'].create({ + 'name': 'whopwhopwhop', + 'module': '__t__', + 'model': r._name, + 'res_id': r.id, + }).complete_name + sids = [ + self.env['ir.model.data'].create({ + 'name': sub.str, + 'module': '__t__', + 'model': sub._name, + 'res_id': sub.id, + }).complete_name + for sub in r.value + ] + r.invalidate_cache() + + self.assertEqual( + r._export_rows([['value', 'id']]), + [['__t__.record000,__t__.record001,__t__.record010,__t__.record011,__t__.record100']] + ) + self.assertEqual( + r.with_context(import_compat=True)._export_rows([['value', 'id']]), + [['__t__.record000,__t__.record001,__t__.record010,__t__.record011,__t__.record100']] + ) + + self.assertEqual( + r.with_context(import_compat=False)._export_rows([['id'], ['value', 'id'], ['value', 'value']]), + [ + [xid, u'__t__.record000', u'4'], + [u'', u'__t__.record001', u'42'], + [u'', u'__t__.record010', u'36'], + [u'', u'__t__.record011', u'4'], + [u'', u'__t__.record100', u'13'] + ] + ) + self.assertEqual( + r.with_context(import_compat=False)._export_rows([['id'], ['value', 'value'], ['value', 'id']]), + [ + [xid, u'4', u'__t__.record000'], + [u'', u'42', u'__t__.record001'], + [u'', u'36', u'__t__.record010'], + [u'', u'4', u'__t__.record011'], + [u'', u'13', u'__t__.record100'] + ] + ) class test_function(CreatorCase): |
