[FIX] web: correct column title when kanban grouped

Before this commit, when a kanban view was grouped by a selection field, the
column were named with the raw value of the selection instead of the display
string.

Furthermore, fix the fact that when the column title was 0 or False,
'undefined' was displayed instead.
This commit is contained in:
fwi-odoo
2017-05-03 13:41:13 +02:00
parent a53335fdb2
commit 1af7864fdf
3 changed files with 12 additions and 26 deletions
@@ -2470,6 +2470,15 @@ var BasicModel = AbstractModel.extend({
aggregateValues[key] = value;
}
});
// When a view is grouped, we need to display the name of each group in
// the 'title'.
var value = group[rawGroupBy];
if (list.fields[rawGroupBy].type === "selection") {
var choice = _.find(list.fields[rawGroupBy].selection, function (c) {
return c[0] === value;
});
value = choice[1];
}
var newGroup = self._makeDataPoint({
modelName: list.model,
count: group[rawGroupBy + '_count'],
@@ -2477,7 +2486,7 @@ var BasicModel = AbstractModel.extend({
context: list.context,
fields: list.fields,
fieldsInfo: list.fieldsInfo,
value: group[rawGroupBy],
value: value,
aggregateValues: aggregateValues,
groupedBy: list.groupedBy.slice(1),
orderedBy: list.orderedBy,
@@ -39,12 +39,8 @@ var KanbanColumn = Widget.extend({
var value = data.value;
this.id = data.res_id || value;
var field = data.fields[data.groupedBy[0]]; // fixme: grouped by field might not be in the fvg
if (field && field.type === "selection") {
value = _.find(field.selection, function (s) { return s[0] === data.value; })[1]; // fixme: same process done in list_renderer
}
// todo: handle group_by_m2o (nameget)
this.title = value || _t('Undefined');
this.title = value === undefined ? _t('Undefined') : value;
this.folded = !data.isOpen;
this.has_active_field = 'active' in data.fields;
this.size = data.count;
@@ -172,24 +172,6 @@ var ListRenderer = BasicRenderer.extend({
return decoration.replace('decoration', 'text');
}).value();
},
/**
* When a list view is grouped, we need to display the name of each group in
* the 'title' row. This is the purpose of this method.
*
* @private
* @param {any} value
* @param {Object} field a field description
* @returns {string}
*/
_formatValue: function (value, field) {
if (field && field.type === 'selection') {
var choice = _.find(field.selection, function (c) {
return c[0] === value;
});
return choice[1];
}
return value || _t('Undefined');
},
/**
* return the number of visible columns. Note that this number depends on
* the state of the renderer. For example, in editable mode, it could be
@@ -409,8 +391,7 @@ var ListRenderer = BasicRenderer.extend({
if (this.hasSelectors) {
$cells.unshift($('<td>'));
}
var field = this.state.fields[this.state.groupedBy[groupLevel]];
var name = this._formatValue(group.value, field);
var name = group.value === undefined ? _t('Undefined') : group.value;
var $th = $('<th>')
.addClass('o_group_name')
.text(name + ' (' + group.count + ')');