[FIX] web_kanban: load grouped field if not in view
In the kanban view, if we try to group by a field that is not defined in the arch, some features (like 'Add a new Column') are not available because the case is not correctly handled. To fix it, a RPC is done to load all fields in this case.
This commit is contained in:
committed by
Martin Geubelle
parent
b5971e417f
commit
0e6eb9687f
@@ -124,19 +124,28 @@ var KanbanView = View.extend({
|
||||
var self = this;
|
||||
var group_by_field = group_by[0] || this.default_group_by;
|
||||
var field = this.fields_view.fields[group_by_field];
|
||||
var grouped_by_m2o = field && (field.type === 'many2one');
|
||||
|
||||
var options = {
|
||||
search_domain: domain,
|
||||
search_context: context,
|
||||
group_by_field: group_by_field,
|
||||
grouped: group_by.length || this.default_group_by,
|
||||
grouped_by_m2o: grouped_by_m2o,
|
||||
relation: (grouped_by_m2o ? field.relation : undefined),
|
||||
};
|
||||
|
||||
var options = {};
|
||||
var fields_def;
|
||||
if (field === undefined) {
|
||||
fields_def = data_manager.load_fields(this.dataset).then(function (fields) {
|
||||
self.fields = fields;
|
||||
field = self.fields[group_by_field];
|
||||
});
|
||||
}
|
||||
var load_def = $.when(fields_def).then(function() {
|
||||
var grouped_by_m2o = field && (field.type === 'many2one');
|
||||
options = _.extend(options, {
|
||||
search_domain: domain,
|
||||
search_context: context,
|
||||
group_by_field: group_by_field,
|
||||
grouped: group_by.length || self.default_group_by,
|
||||
grouped_by_m2o: grouped_by_m2o,
|
||||
relation: (grouped_by_m2o ? field.relation : undefined),
|
||||
});
|
||||
return options.grouped ? self.load_groups(options) : self.load_records();
|
||||
});
|
||||
return this.search_orderer
|
||||
.add(options.grouped ? this.load_groups(options) : this.load_records())
|
||||
.add(load_def)
|
||||
.then(function (data) {
|
||||
_.extend(self, options);
|
||||
if (options.grouped) {
|
||||
@@ -182,14 +191,7 @@ var KanbanView = View.extend({
|
||||
var group_by_field = options.group_by_field;
|
||||
var fields_keys = _.uniq(this.fields_keys.concat(group_by_field));
|
||||
|
||||
var fields_def;
|
||||
if (this.fields_view.fields[group_by_field] === undefined) {
|
||||
fields_def = data_manager.load_fields(this.dataset).then(function (fields) {
|
||||
self.fields = fields;
|
||||
})
|
||||
}
|
||||
|
||||
var load_groups_def = new Model(this.model, options.search_context, options.search_domain)
|
||||
return new Model(this.model, options.search_context, options.search_domain)
|
||||
.query(fields_keys)
|
||||
.group_by([group_by_field])
|
||||
.then(function (groups) {
|
||||
@@ -292,7 +294,6 @@ var KanbanView = View.extend({
|
||||
};
|
||||
});
|
||||
});
|
||||
return $.when(load_groups_def, fields_def);
|
||||
},
|
||||
|
||||
is_action_enabled: function(action) {
|
||||
|
||||
Reference in New Issue
Block a user