[FIX] web_timeline: Allow groupby m2m fields

This commit is contained in:
CarlosRoca13
2022-08-02 14:31:54 +02:00
parent d2dcca18ff
commit acc94d74c3
7 changed files with 123 additions and 40 deletions

View File

@@ -175,20 +175,29 @@ odoo.define("web_timeline.TimelineController", function (require) {
);
data[this.date_delay] = diff_seconds / 3600;
}
if (
this.renderer.last_group_bys &&
this.renderer.last_group_bys instanceof Array
) {
data[this.renderer.last_group_bys[0]] = group;
}
const grouped_field = this.renderer.last_group_bys[0];
this._rpc({
model: this.modelName,
method: "fields_get",
args: [grouped_field],
context: this.getSession().user_context,
}).then(async (fields_processed) => {
if (
this.renderer.last_group_bys &&
this.renderer.last_group_bys instanceof Array &&
fields_processed[grouped_field].type !== "many2many"
) {
data[this.renderer.last_group_bys[0]] = group;
}
this.moveQueue.push({
id: event.data.item.id,
data: data,
event: event,
this.moveQueue.push({
id: event.data.item.id,
data: data,
event: event,
});
this.debouncedInternalMove();
});
this.debouncedInternalMove();
},
/**

View File

@@ -353,14 +353,15 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
data.push(this.event_data_transform(evt));
}
}
const groups = this.split_groups(events, group_bys);
this.timeline.setGroups(groups);
this.timeline.setItems(data);
const mode = !this.mode || this.mode === "fit";
const adjust = _.isUndefined(adjust_window) || adjust_window;
if (mode && adjust) {
this.timeline.fit();
}
this.split_groups(events, group_bys).then((groups) => {
this.timeline.setGroups(groups);
this.timeline.setItems(data);
const mode = !this.mode || this.mode === "fit";
const adjust = _.isUndefined(adjust_window) || adjust_window;
if (mode && adjust) {
this.timeline.fit();
}
});
},
/**
@@ -371,14 +372,15 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
* @private
* @returns {Array}
*/
split_groups: function (events, group_bys) {
split_groups: async function (events, group_bys) {
if (group_bys.length === 0) {
return events;
}
const groups = [];
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>")});
for (const evt of events) {
const group_name = evt[_.first(group_bys)];
const grouped_field = _.first(group_bys);
const group_name = evt[grouped_field];
if (group_name) {
if (group_name instanceof Array) {
const group = _.find(
@@ -386,9 +388,38 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
(existing_group) => existing_group.id === group_name[0]
);
if (_.isUndefined(group)) {
groups.push({
id: group_name[0],
content: group_name[1],
// Check if group is m2m in this case add id -> value of all
// found entries.
await this._rpc({
model: this.modelName,
method: "fields_get",
args: [grouped_field],
context: this.getSession().user_context,
}).then(async (fields) => {
if (fields[grouped_field].type === "many2many") {
const list_values =
await this.get_m2m_grouping_datas(
fields[grouped_field].relation,
group_name
);
for (const vals of list_values) {
let is_inside = false;
for (const gr of groups) {
if (vals.id === gr.id) {
is_inside = true;
break;
}
}
if (!is_inside) {
groups.push(vals);
}
}
} else {
groups.push({
id: group_name[0],
content: group_name[1],
});
}
});
}
}
@@ -397,6 +428,21 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
return groups;
},
get_m2m_grouping_datas: async function (model, group_name) {
const groups = [];
for (const gr of group_name) {
await this._rpc({
model: model,
method: "name_get",
args: [gr],
context: this.getSession().user_context,
}).then((name) => {
groups.push({id: name[0][0], content: name[0][1]});
});
}
return groups;
},
/**
* Get dates from given event
*

View File

@@ -31,6 +31,7 @@ odoo.define("web_timeline.TimelineView", function (require) {
Controller: TimelineController,
Renderer: TimelineRenderer,
}),
viewType: "timeline",
/**
* @override