Skip to content

Commit 607da7c

Browse files
alexis-viaCarlosRoca13
authored andcommitted
[FIX] web_timeline: order group_by field
Fix bug OCA#2266: before this fix, the lines of the timeline view were always sorted by alphabetical order, ignoring the native order of the model on which the group_by field points to. Fix duplicate entries in the 'fields' argument when the 'colors' parameters uses the same field in multiple conditions.
1 parent 40b956b commit 607da7c

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

web_timeline/static/src/js/timeline_controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ odoo.define("web_timeline.TimelineController", function (require) {
6666
kwargs: {
6767
fields: fields,
6868
domain: domains,
69+
order: [{name: this.renderer.arch.attrs.default_group_by}],
6970
},
7071
context: this.getSession().user_context,
7172
}).then((data) =>

web_timeline/static/src/js/timeline_model.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ odoo.define("web_timeline.TimelineModel", function (require) {
1111
load: function (params) {
1212
this.modelName = params.modelName;
1313
this.fieldNames = params.fieldNames;
14+
this.default_group_by = params.default_group_by;
1415
if (!this.preload_def) {
1516
this.preload_def = $.Deferred();
1617
$.when(
@@ -55,9 +56,12 @@ odoo.define("web_timeline.TimelineModel", function (require) {
5556
return this._rpc({
5657
model: this.modelName,
5758
method: "search_read",
58-
context: this.data.context,
59-
fields: this.fieldNames,
60-
domain: this.data.domain,
59+
kwargs: {
60+
fields: this.fieldNames,
61+
domain: this.data.domain,
62+
order: [{name: this.default_group_by}],
63+
context: this.data.context,
64+
},
6165
}).then((events) => {
6266
this.data.data = events;
6367
this.data.rights = {

web_timeline/static/src/js/timeline_renderer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
3535
this.date_delay = params.date_delay;
3636
this.colors = params.colors;
3737
this.fieldNames = params.fieldNames;
38+
this.default_group_by = params.default_group_by;
3839
this.dependency_arrow = params.dependency_arrow;
3940
this.modelClass = params.view.model;
4041
this.fields = params.fields;
@@ -377,7 +378,8 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
377378
return events;
378379
}
379380
const groups = [];
380-
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>")});
381+
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>"), order: -1});
382+
var seq = 1;
381383
for (const evt of events) {
382384
const grouped_field = _.first(group_bys);
383385
const group_name = evt[grouped_field];
@@ -411,14 +413,18 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
411413
}
412414
}
413415
if (!is_inside) {
416+
vals.order = seq;
417+
seq += 1;
414418
groups.push(vals);
415419
}
416420
}
417421
} else {
418422
groups.push({
419423
id: group_name[0],
420424
content: group_name[1],
425+
order: seq,
421426
});
427+
seq += 1;
422428
}
423429
});
424430
}
@@ -516,6 +522,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
516522
start: date_start,
517523
content: content,
518524
id: evt.id,
525+
order: evt.order,
519526
group: group,
520527
evt: evt,
521528
style: `background-color: ${this.color};`,

web_timeline/static/src/js/timeline_view.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ odoo.define("web_timeline.TimelineView", function (require) {
7373

7474
const colors = this.parse_colors();
7575
for (const color of colors) {
76-
fieldNames.push(color.field);
76+
if (!fieldNames.includes(color.field)) {
77+
fieldNames.push(color.field);
78+
}
7779
}
7880

7981
if (dependency_arrow) {
@@ -107,11 +109,13 @@ odoo.define("web_timeline.TimelineView", function (require) {
107109
this.rendererParams.date_delay = date_delay;
108110
this.rendererParams.colors = colors;
109111
this.rendererParams.fieldNames = fieldNames;
112+
this.rendererParams.default_group_by = attrs.default_group_by;
110113
this.rendererParams.min_height = min_height;
111114
this.rendererParams.dependency_arrow = dependency_arrow;
112115
this.rendererParams.fields = fields;
113116
this.loadParams.modelName = this.modelName;
114117
this.loadParams.fieldNames = fieldNames;
118+
this.loadParams.default_group_by = attrs.default_group_by;
115119
this.controllerParams.open_popup_action = open_popup_action;
116120
this.controllerParams.date_start = date_start;
117121
this.controllerParams.date_stop = date_stop;
@@ -122,7 +126,7 @@ odoo.define("web_timeline.TimelineView", function (require) {
122126

123127
_preapre_vis_timeline_options: function (attrs) {
124128
return {
125-
groupOrder: this.group_order,
129+
groupOrder: "order",
126130
orientation: "both",
127131
selectable: true,
128132
multiselect: true,
@@ -135,24 +139,6 @@ odoo.define("web_timeline.TimelineView", function (require) {
135139
};
136140
},
137141

138-
/**
139-
* Order function for groups.
140-
* @param {Object} grp1
141-
* @param {Object} grp2
142-
* @returns {Integer}
143-
*/
144-
group_order: function (grp1, grp2) {
145-
// Display non grouped elements first
146-
if (grp1.id === -1) {
147-
return -1;
148-
}
149-
if (grp2.id === -1) {
150-
return 1;
151-
}
152-
153-
return grp1.content.localeCompare(grp2.content);
154-
},
155-
156142
/**
157143
* Parse the colors attribute.
158144
*

0 commit comments

Comments
 (0)