[FIX] base: use better view inheritance (secondary) order

Currently, the view inheritance order is 'priority,name,id', the
default order for the 'ir.ui.view' model.

This commit changes the order to 'priority,id' while computing
inheritance. This make views chronologically ordered according to their
installation order, after the primary sorting on `priority`.

This helps to automatically solve some inheritance order bugs that would
have traditionally required explicit view priorities.

Considering this example: an app C depends on two others apps A and B.
We want the LESS files of C to come after the LESS files of A and B as
CSS rules order matter. The only solution to make sure of that with the
current implementation is to change priority field of C to be higher
than 16 (default of A and B). With a complex hierarchy, that will induce
errors. Ordering by 'priority,id' solves the problem, indeed views' ids
of apps A and B will be lower than views' ids of app C. The "name"
ordering is fine for list views display but not for views inheritance.

Closes #19658
This commit is contained in:
qsm-odoo
2017-09-25 12:03:55 +02:00
committed by Olivier Dony
parent f565a18cad
commit dbb931976f
+7 -2
View File
@@ -35,6 +35,10 @@ _logger = logging.getLogger(__name__)
MOVABLE_BRANDING = ['data-oe-model', 'data-oe-id', 'data-oe-field', 'data-oe-xpath', 'data-oe-source-id']
# First sort criterion for inheritance is priority, second is chronological order of installation
# Note: natural _order has `name`, but only because that makes list browsing easier
INHERIT_ORDER = 'priority,id'
def keep_query(*keep_params, **additional_params):
"""
@@ -455,9 +459,10 @@ actual arch.
# used to implement it.
modules = tuple(self.pool._init_modules) + (self._context.get('install_mode_data', {}).get('module'),)
views = self.search(conditions + [('model_ids.module', 'in', modules)])
views = self.search(conditions + [('id', 'in', list(self._context.get('check_view_ids') or (0,)) + views.ids)])
views_cond = [('id', 'in', list(self._context.get('check_view_ids') or (0,)) + views.ids)]
views = self.search(conditions + views_cond, order=INHERIT_ORDER)
else:
views = self.search(conditions)
views = self.search(conditions, order=INHERIT_ORDER)
return [(view.arch, view.id)
for view in views.sudo()