[FIX] base: handling of *_view_ref in SSF

The feature was not tested, and as it turns out completely broken:

* the non-raw string means the "backrefs" were really interpreted as
  octal literals
* the second backref was entirely wrong

Also add all loaded views to the field descriptor in case we might
have a use for it (and because inline sub-views are always stored on
the descriptor).

closes odoo/odoo#28194
This commit is contained in:
Xavier Morel
2018-10-26 11:39:53 +00:00
parent bf65793b31
commit 8c9174ff80
2 changed files with 19 additions and 3 deletions
@@ -284,6 +284,20 @@ class TestO2M(TransactionCase):
delegating to a separate form view
"""
f = Form(self.env['test_testing_utilities.parent'], view='test_testing_utilities.o2m_parent_ed')
custom_tree = self.env.ref('test_testing_utilities.editable_external').id
subs_field = f._view['fields']['subs']
tree_view = subs_field['views']['tree']
self.assertEqual(tree_view['type'], 'tree')
self.assertEqual(
tree_view['view_id'], custom_tree,
'check that the tree view is the one referenced by tree_view_ref'
)
self.assertIs(subs_field['views']['edition'], tree_view, "check that the edition view is the tree view")
self.assertEqual(
subs_field['views']['edition']['view_id'],
custom_tree
)
with f.subs.new() as s:
s.value = 1
+5 -3
View File
@@ -989,10 +989,10 @@ def can_import(module):
# TODO: sub-views (o2m, m2m) -> sub-form?
# TODO: domains
ref_re = re.compile("""
ref_re = re.compile(r"""
# first match 'form_view_ref' key, backrefs are used to handle single or
# double quoting of the value
(['"])(?P<view_type>\w+)_view_ref\1
(['"])(?P<view_type>\w+_view_ref)\1
# colon separator (with optional spaces around)
\s*:\s*
# open quote for value
@@ -1003,7 +1003,7 @@ ref_re = re.compile("""
[.\w]+
)
# close with same quote as opening
\2
\3
""", re.VERBOSE)
class Form(object):
""" Server-side form view implementation (partial)
@@ -1119,6 +1119,8 @@ class Form(object):
.load_views([(False, 'tree'), (False, 'form')])['fields_views']
# embedded views should take the priority on externals
views.update(descr['views'])
# re-set all resolved views on the descriptor
descr['views'] = views
# if the default view is a kanban or a non-editable list, the
# "edition controller" is the form view