From dbb931976fd102a1eceea4ebf195efea7576f260 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 25 Sep 2017 11:33:12 +0200 Subject: [PATCH] [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 --- odoo/addons/base/ir/ir_ui_view.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/ir/ir_ui_view.py b/odoo/addons/base/ir/ir_ui_view.py index 7279f5b6c5f..6853b5e2037 100644 --- a/odoo/addons/base/ir/ir_ui_view.py +++ b/odoo/addons/base/ir/ir_ui_view.py @@ -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()