From e3246845c398eb052e578d38431a2a783cbc0a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Tue, 11 Dec 2018 15:30:51 +0000 Subject: [PATCH] [FIX] web: fix KanbanRenderer state management for date/datetime fields In the KanbanRenderer, the _setState method extracts the groupBy field name and tries to get the field information from that string. When the field is a date/datetime grouped by day/week/month/..., the field name becomes "my_date:month". This prevents the gathering of state information since those information are stored in a dictionary with a 'my_date' key. This commit will detect if the field has additional grouping info (:month, :week, ...) and clean the name with a substring before accessing the state dictionary. --- .../src/js/views/kanban/kanban_renderer.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_renderer.js b/addons/web/static/src/js/views/kanban/kanban_renderer.js index ff2ba753e89..316fb9114cd 100644 --- a/addons/web/static/src/js/views/kanban/kanban_renderer.js +++ b/addons/web/static/src/js/views/kanban/kanban_renderer.js @@ -441,8 +441,9 @@ var KanbanRenderer = BasicRenderer.extend({ this.state = state; var groupByField = state.groupedBy[0]; - var groupByFieldAttrs = state.fields[groupByField]; - var groupByFieldInfo = state.fieldsInfo.kanban[groupByField]; + var cleanGroupByField = this._cleanGroupByField(groupByField); + var groupByFieldAttrs = state.fields[cleanGroupByField]; + var groupByFieldInfo = state.fieldsInfo.kanban[cleanGroupByField]; // Deactivate the drag'n'drop if the groupedBy field: // - is a date or datetime since we group by month or // - is readonly (on the field attrs or in the view) @@ -472,6 +473,22 @@ var KanbanRenderer = BasicRenderer.extend({ }); this.createColumnEnabled = this.groupedByM2O && this.columnOptions.group_creatable; }, + /** + * Remove date/datetime magic grouping info to get proper field attrs/info from state + * ex: sent_date:month will become sent_date + * + * @private + * @param {string} groupByField + * @returns {string} + */ + _cleanGroupByField: function (groupByField) { + var cleanGroupByField = groupByField; + if (cleanGroupByField && cleanGroupByField.indexOf(':') > -1) { + cleanGroupByField = cleanGroupByField.substring(0, cleanGroupByField.indexOf(':')); + } + + return cleanGroupByField; + }, /** * Moves the focus on the first card of the next column in a given direction * This ignores the folded columns and skips over the empty columns.