[FIX] base, tools: add pre_locate to apply_inheritance_specs

Revision on https://github.com/odoo/odoo/commit/fc5878ecc668ee83cd1a374474f0b21bf6a51940

Commit above introduced server-side inheritance of static XML.
To do so, it made some changes to the way inheritance of view
templates is applied, such as moving this logic outside of the record
`ir.ui.view`.

This change, however, removed the feature to overwrite these methods.
Studio did that in order to correctly apply `group_ids`[1][2].

This commit fixes the issue by introducing an optional callback
`pre_locate` as parameter of the methods `apply_inheritance_specs`.
When set, this function is called just before locating a node during
the application of inheritance of the view. Studio can make use of
this callback to handle group_ids properly, again.

[1] https://github.com/odoo/enterprise/commit/b56101200ac35dae3eadbc0bdf4ba17461f33907
[2] https://github.com/odoo/enterprise/commit/38f7eb8153df8406498fa58eb809271db778e6d8

Related to: https://github.com/odoo/enterprise/pull/5321

Task-Id 2047439

closes odoo/odoo#36200

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2019-08-30 11:41:12 +00:00
parent ec9b365b18
commit dc31884dcf
2 changed files with 11 additions and 3 deletions
+5 -2
View File
@@ -614,7 +614,7 @@ actual arch.
return specs_tree
@api.model
def apply_inheritance_specs(self, source, specs_tree, inherit_id):
def apply_inheritance_specs(self, source, specs_tree, inherit_id, pre_locate=lambda s: True):
""" Apply an inheriting view (a descendant of the base view)
Apply to a source architecture all the spec nodes (i.e. nodes
@@ -624,6 +624,8 @@ actual arch.
:param Element source: a parent architecture to modify
:param Elepect specs_tree: a modifying architecture in an inheriting view
:param inherit_id: the database id of specs_arch
:param (optional) pre_locate: function that is execute before locating a node.
This function receives an arch as argument.
:return: a modified source where the specs are applied
:rtype: Element
"""
@@ -631,7 +633,8 @@ actual arch.
# changes to apply to some parent architecture).
try:
source = apply_inheritance_specs(source, specs_tree,
inherit_branding=self._context.get('inherit_branding'))
inherit_branding=self._context.get('inherit_branding'),
pre_locate=pre_locate)
except ValueError as e:
self.raise_view_error(str(e), inherit_id)
return source
+6 -1
View File
@@ -74,7 +74,7 @@ def locate_node(arch, spec):
return None
def apply_inheritance_specs(source, specs_tree, inherit_branding=False):
def apply_inheritance_specs(source, specs_tree, inherit_branding=False, pre_locate=lambda s: True):
""" Apply an inheriting view (a descendant of the base view)
Apply to a source architecture all the spec nodes (i.e. nodes
@@ -82,6 +82,9 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False):
architecture) given by an inheriting view.
:param Element source: a parent architecture to modify
:param pre_locate: function that is executed before locating a node.
This function receives an arch as argument.
This is required by studio to properly handle group_ids.
:return: a modified source where the specs are applied
:rtype: Element
"""
@@ -99,6 +102,7 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False):
_("Invalid specification for moved nodes: '%s'") %
etree.tostring(spec)
)
pre_locate(spec)
to_extract = locate_node(source, spec)
if to_extract is not None:
remove_element(to_extract)
@@ -116,6 +120,7 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False):
if spec.tag == 'data':
specs += [c for c in spec]
continue
pre_locate(spec)
node = locate_node(source, spec)
if node is not None:
pos = spec.get('position', 'inside')