Skip to content

Commit acc94d7

Browse files
committed
[FIX] web_timeline: Allow groupby m2m fields
1 parent d2dcca1 commit acc94d7

File tree

7 files changed

+123
-40
lines changed

7 files changed

+123
-40
lines changed

web_timeline/README.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Web timeline
1414
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1515
:alt: License: AGPL-3
1616
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
17-
:target: https://github.com/OCA/web/tree/14.0/web_timeline
17+
:target: https://github.com/OCA/web/tree/15.0/web_timeline
1818
:alt: OCA/web
1919
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20-
:target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_timeline
20+
:target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_timeline
2121
:alt: Translate me on Weblate
2222
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/162/14.0
23+
:target: https://runbot.odoo-community.org/runbot/162/15.0
2424
:alt: Try me on Runbot
2525

2626
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -152,14 +152,20 @@ Known issues / Roadmap
152152
* Implement a more efficient way of refreshing timeline after a record update;
153153
* Make `attrs` attribute work;
154154
* Make action attributes work (create, edit, delete) like in form and tree views.
155+
* When grouping by m2m and more than one record is set, the timeline item appears only
156+
on one group. Allow showing in both groups.
157+
* When grouping by m2m and dragging for changing the time or the group, the changes on
158+
the group will not be set, because it could make disappear the records not related
159+
with the changes that we want to make. When the item is showed in all groups change
160+
the value according the group of the dragged item.
155161

156162
Bug Tracker
157163
===========
158164

159165
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
160166
In case of trouble, please check there if your issue has already been reported.
161167
If you spotted it first, help us smashing it by providing a detailed and welcomed
162-
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
168+
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
163169

164170
Do not contact contributors directly about support or help with technical issues.
165171

@@ -180,14 +186,17 @@ Contributors
180186

181187
* Laurent Mignon <[email protected]>
182188
* Adrien Peiffer <[email protected]>
183-
* Pedro M. Baeza <[email protected]>
184189
* Leonardo Donelli <[email protected]>
185190
* Adrien Didenot <[email protected]>
186191
* Dennis Sluijk <[email protected]>
187192
* Thong Nguyen Van <[email protected]>
188-
* Alexandre Díaz <[email protected]>
189193
* Murtaza Mithaiwala <[email protected]>
190194
* Ammar Officewala <[email protected]>
195+
* `Tecnativa <https://www.tecnativa.com>`_:
196+
197+
* Pedro M. Baeza
198+
* Alexandre Díaz
199+
* César A. Sánchez
191200

192201
Maintainers
193202
~~~~~~~~~~~
@@ -210,6 +219,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
210219

211220
|maintainer-tarteo|
212221

213-
This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_timeline>`_ project on GitHub.
222+
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_timeline>`_ project on GitHub.
214223

215224
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

web_timeline/__manifest__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"license": "AGPL-3",
1717
"website": "https://github.com/OCA/web",
1818
"depends": ["web"],
19-
"qweb": ["static/src/xml/web_timeline.xml"],
2019
"data": [],
2120
"maintainers": ["tarteo"],
2221
"application": False,
@@ -29,6 +28,9 @@
2928
"web_timeline/static/src/js/timeline_controller.js",
3029
"web_timeline/static/src/js/timeline_model.js",
3130
"web_timeline/static/src/js/timeline_canvas.js",
32-
]
31+
],
32+
"web.assets_qweb": [
33+
"web_timeline/static/src/xml/web_timeline.xml",
34+
],
3335
},
3436
}

web_timeline/readme/ROADMAP.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
* Implement a more efficient way of refreshing timeline after a record update;
22
* Make `attrs` attribute work;
33
* Make action attributes work (create, edit, delete) like in form and tree views.
4+
* When grouping by m2m and more than one record is set, the timeline item appears only
5+
on one group. Allow showing in both groups.
6+
* When grouping by m2m and dragging for changing the time or the group, the changes on
7+
the group will not be set, because it could make disappear the records not related
8+
with the changes that we want to make. When the item is showed in all groups change
9+
the value according the group of the dragged item.

web_timeline/static/description/index.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
6+
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
77
<title>Web timeline</title>
88
<style type="text/css">
99

@@ -367,7 +367,7 @@ <h1 class="title">Web timeline</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_timeline"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_timeline"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
370+
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_timeline"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_timeline"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
371371
<p>Define a new view displaying events in an interactive visualization chart.</p>
372372
<p>The widget is based on the external library
373373
<a class="reference external" href="https://visjs.github.io/vis-timeline/examples/timeline">https://visjs.github.io/vis-timeline/examples/timeline</a></p>
@@ -526,14 +526,20 @@ <h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
526526
<li>Implement a more efficient way of refreshing timeline after a record update;</li>
527527
<li>Make <cite>attrs</cite> attribute work;</li>
528528
<li>Make action attributes work (create, edit, delete) like in form and tree views.</li>
529+
<li>When grouping by m2m and more than one record is set, the timeline item appears only
530+
on one group. Allow showing in both groups.</li>
531+
<li>When grouping by m2m and dragging for changing the time or the group, the changes on
532+
the group will not be set, because it could make disappear the records not related
533+
with the changes that we want to make. When the item is showed in all groups change
534+
the value according the group of the dragged item.</li>
529535
</ul>
530536
</div>
531537
<div class="section" id="bug-tracker">
532538
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
533539
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
534540
In case of trouble, please check there if your issue has already been reported.
535541
If you spotted it first, help us smashing it by providing a detailed and welcomed
536-
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
542+
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
537543
<p>Do not contact contributors directly about support or help with technical issues.</p>
538544
</div>
539545
<div class="section" id="credits">
@@ -553,14 +559,18 @@ <h2><a class="toc-backref" href="#id7">Contributors</a></h2>
553559
<ul class="simple">
554560
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
555561
<li>Adrien Peiffer &lt;<a class="reference external" href="mailto:adrien.peiffer&#64;acsone.eu">adrien.peiffer&#64;acsone.eu</a>&gt;</li>
556-
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;tecnativa.com">pedro.baeza&#64;tecnativa.com</a>&gt;</li>
557562
<li>Leonardo Donelli &lt;<a class="reference external" href="mailto:donelli&#64;webmonks.it">donelli&#64;webmonks.it</a>&gt;</li>
558563
<li>Adrien Didenot &lt;<a class="reference external" href="mailto:adrien.didenot&#64;horanet.com">adrien.didenot&#64;horanet.com</a>&gt;</li>
559564
<li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li>
560565
<li>Thong Nguyen Van &lt;<a class="reference external" href="mailto:thongnv&#64;trobz.com">thongnv&#64;trobz.com</a>&gt;</li>
561-
<li>Alexandre Díaz &lt;<a class="reference external" href="mailto:alexandre.diaz&#64;tecnativa.com">alexandre.diaz&#64;tecnativa.com</a>&gt;</li>
562566
<li>Murtaza Mithaiwala &lt;<a class="reference external" href="mailto:mmithaiwala&#64;opensourceintegrators.com">mmithaiwala&#64;opensourceintegrators.com</a>&gt;</li>
563567
<li>Ammar Officewala &lt;<a class="reference external" href="mailto:aofficewala&#64;opensourceintegrators.com">aofficewala&#64;opensourceintegrators.com</a>&gt;</li>
568+
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
569+
<li>Pedro M. Baeza</li>
570+
<li>Alexandre Díaz</li>
571+
<li>César A. Sánchez</li>
572+
</ul>
573+
</li>
564574
</ul>
565575
</div>
566576
<div class="section" id="maintainers">
@@ -572,7 +582,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
572582
promote its widespread use.</p>
573583
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
574584
<p><a class="reference external" href="https://github.com/tarteo"><img alt="tarteo" src="https://github.com/tarteo.png?size=40px" /></a></p>
575-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_timeline">OCA/web</a> project on GitHub.</p>
585+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_timeline">OCA/web</a> project on GitHub.</p>
576586
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
577587
</div>
578588
</div>

web_timeline/static/src/js/timeline_controller.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,29 @@ odoo.define("web_timeline.TimelineController", function (require) {
175175
);
176176
data[this.date_delay] = diff_seconds / 3600;
177177
}
178-
if (
179-
this.renderer.last_group_bys &&
180-
this.renderer.last_group_bys instanceof Array
181-
) {
182-
data[this.renderer.last_group_bys[0]] = group;
183-
}
178+
const grouped_field = this.renderer.last_group_bys[0];
179+
this._rpc({
180+
model: this.modelName,
181+
method: "fields_get",
182+
args: [grouped_field],
183+
context: this.getSession().user_context,
184+
}).then(async (fields_processed) => {
185+
if (
186+
this.renderer.last_group_bys &&
187+
this.renderer.last_group_bys instanceof Array &&
188+
fields_processed[grouped_field].type !== "many2many"
189+
) {
190+
data[this.renderer.last_group_bys[0]] = group;
191+
}
184192

185-
this.moveQueue.push({
186-
id: event.data.item.id,
187-
data: data,
188-
event: event,
189-
});
193+
this.moveQueue.push({
194+
id: event.data.item.id,
195+
data: data,
196+
event: event,
197+
});
190198

191-
this.debouncedInternalMove();
199+
this.debouncedInternalMove();
200+
});
192201
},
193202

194203
/**

web_timeline/static/src/js/timeline_renderer.js

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,15 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
353353
data.push(this.event_data_transform(evt));
354354
}
355355
}
356-
const groups = this.split_groups(events, group_bys);
357-
this.timeline.setGroups(groups);
358-
this.timeline.setItems(data);
359-
const mode = !this.mode || this.mode === "fit";
360-
const adjust = _.isUndefined(adjust_window) || adjust_window;
361-
if (mode && adjust) {
362-
this.timeline.fit();
363-
}
356+
this.split_groups(events, group_bys).then((groups) => {
357+
this.timeline.setGroups(groups);
358+
this.timeline.setItems(data);
359+
const mode = !this.mode || this.mode === "fit";
360+
const adjust = _.isUndefined(adjust_window) || adjust_window;
361+
if (mode && adjust) {
362+
this.timeline.fit();
363+
}
364+
});
364365
},
365366

366367
/**
@@ -371,24 +372,54 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
371372
* @private
372373
* @returns {Array}
373374
*/
374-
split_groups: function (events, group_bys) {
375+
split_groups: async function (events, group_bys) {
375376
if (group_bys.length === 0) {
376377
return events;
377378
}
378379
const groups = [];
379380
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>")});
380381
for (const evt of events) {
381-
const group_name = evt[_.first(group_bys)];
382+
const grouped_field = _.first(group_bys);
383+
const group_name = evt[grouped_field];
382384
if (group_name) {
383385
if (group_name instanceof Array) {
384386
const group = _.find(
385387
groups,
386388
(existing_group) => existing_group.id === group_name[0]
387389
);
388390
if (_.isUndefined(group)) {
389-
groups.push({
390-
id: group_name[0],
391-
content: group_name[1],
391+
// Check if group is m2m in this case add id -> value of all
392+
// found entries.
393+
await this._rpc({
394+
model: this.modelName,
395+
method: "fields_get",
396+
args: [grouped_field],
397+
context: this.getSession().user_context,
398+
}).then(async (fields) => {
399+
if (fields[grouped_field].type === "many2many") {
400+
const list_values =
401+
await this.get_m2m_grouping_datas(
402+
fields[grouped_field].relation,
403+
group_name
404+
);
405+
for (const vals of list_values) {
406+
let is_inside = false;
407+
for (const gr of groups) {
408+
if (vals.id === gr.id) {
409+
is_inside = true;
410+
break;
411+
}
412+
}
413+
if (!is_inside) {
414+
groups.push(vals);
415+
}
416+
}
417+
} else {
418+
groups.push({
419+
id: group_name[0],
420+
content: group_name[1],
421+
});
422+
}
392423
});
393424
}
394425
}
@@ -397,6 +428,21 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
397428
return groups;
398429
},
399430

431+
get_m2m_grouping_datas: async function (model, group_name) {
432+
const groups = [];
433+
for (const gr of group_name) {
434+
await this._rpc({
435+
model: model,
436+
method: "name_get",
437+
args: [gr],
438+
context: this.getSession().user_context,
439+
}).then((name) => {
440+
groups.push({id: name[0][0], content: name[0][1]});
441+
});
442+
}
443+
return groups;
444+
},
445+
400446
/**
401447
* Get dates from given event
402448
*

web_timeline/static/src/js/timeline_view.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ odoo.define("web_timeline.TimelineView", function (require) {
3131
Controller: TimelineController,
3232
Renderer: TimelineRenderer,
3333
}),
34+
viewType: "timeline",
3435

3536
/**
3637
* @override

0 commit comments

Comments
 (0)