From 5d82725f62bba3f06ba0bb881614f1ae91afa5c5 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Thu, 29 Aug 2019 13:42:38 +0000 Subject: [FIX] web: stop defaulting on empty kanbans when you should not MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1/ Write a form view with a o2m field that has its own inline tree view (no other view exist in db for the target model) 2/ Open that view in a mobile environment 3/ Instead of having a list view, you get a kanban view. No luck for you, since the default kanban generated by `models.py` is an empty one, your records are *invisible* \o/ From what I can tell, the previous condition made no sense: ``` if (there is a list view and a kanban view) <-- this seems absurd then (use the list mode) elif (there is no list view but a kanban view) then (use the kanban mode) else (use both modes) ``` The first condition seems absurd: it *actively* ignores a kanban view if there is one. Even better, the list view whose existence it checks is never there: it checks for a `tree` when it should be checking for a `list`. In short, the first condition was *never* met, and you ended up either with exclusive kanban mode or with both modes - even if you had no existing kanban view for the target model... This commit moves the normalization of `tree` into `list` before attempting to process the x2many field's subviews. It clarify the usage of `tree` vs `list` (cf. only use `list`) which prevents weird edge cases like described above. closes odoo/odoo#36237 Signed-off-by: Adrien Dieudonné (adr) Co-authored-by: Adrien Dieudonné Co-authored-by: Pierre Paridans --- addons/web/static/src/js/views/basic/basic_view.js | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_view.js') diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js index 38d2f220c2f..5cb293e866b 100644 --- a/addons/web/static/src/js/views/basic/basic_view.js +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -282,29 +282,28 @@ var BasicView = AbstractView.extend({ }); } + attrs.views = attrs.views || {}; + + // Keep compatibility with 'tree' syntax + attrs.mode = attrs.mode === 'tree' ? 'list' : attrs.mode; + if (!attrs.views.list && attrs.views.tree) { + attrs.views.list = attrs.views.tree; + } + if (field.type === 'one2many' || field.type === 'many2many') { if (attrs.Widget.prototype.useSubview) { - if (!attrs.views) { - attrs.views = {}; - } var mode = attrs.mode; if (!mode) { - if (attrs.views.tree && attrs.views.kanban) { - mode = 'tree'; - } else if (!attrs.views.tree && attrs.views.kanban) { + if (attrs.views.list && !attrs.views.kanban) { + mode = 'list'; + } else if (!attrs.views.list && attrs.views.kanban) { mode = 'kanban'; } else { - mode = 'tree,kanban'; + mode = 'list,kanban'; } } if (mode.indexOf(',') !== -1) { - mode = config.device.isMobile ? 'kanban' : 'tree'; - } - if (mode === 'tree') { - mode = 'list'; - if (!attrs.views.list && attrs.views.tree) { - attrs.views.list = attrs.views.tree; - } + mode = config.device.isMobile ? 'kanban' : 'list'; } attrs.mode = mode; if (mode in attrs.views) { -- cgit v1.2.3