3
0
Fork 0

[FIX] web_timeline: Allow groupby m2m fields

15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
CarlosRoca13 2022-08-02 14:31:54 +02:00
parent d2dcca18ff
commit acc94d74c3
7 changed files with 123 additions and 40 deletions

View File

@ -14,13 +14,13 @@ Web timeline
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/14.0/web_timeline
:target: https://github.com/OCA/web/tree/15.0/web_timeline
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_timeline
:target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_timeline
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/14.0
:target: https://runbot.odoo-community.org/runbot/162/15.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@ -152,6 +152,12 @@ Known issues / Roadmap
* Implement a more efficient way of refreshing timeline after a record update;
* Make `attrs` attribute work;
* Make action attributes work (create, edit, delete) like in form and tree views.
* When grouping by m2m and more than one record is set, the timeline item appears only
on one group. Allow showing in both groups.
* When grouping by m2m and dragging for changing the time or the group, the changes on
the group will not be set, because it could make disappear the records not related
with the changes that we want to make. When the item is showed in all groups change
the value according the group of the dragged item.
Bug Tracker
===========
@ -159,7 +165,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`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**>`_.
`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**>`_.
Do not contact contributors directly about support or help with technical issues.
@ -180,14 +186,17 @@ Contributors
* Laurent Mignon <laurent.mignon@acsone.eu>
* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Leonardo Donelli <donelli@webmonks.it>
* Adrien Didenot <adrien.didenot@horanet.com>
* Dennis Sluijk <d.sluijk@onestein.nl>
* Thong Nguyen Van <thongnv@trobz.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
* Murtaza Mithaiwala <mmithaiwala@opensourceintegrators.com>
* Ammar Officewala <aofficewala@opensourceintegrators.com>
* `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza
* Alexandre Díaz
* César A. Sánchez
Maintainers
~~~~~~~~~~~
@ -210,6 +219,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-tarteo|
This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_timeline>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_timeline>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -16,7 +16,6 @@
"license": "AGPL-3",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"qweb": ["static/src/xml/web_timeline.xml"],
"data": [],
"maintainers": ["tarteo"],
"application": False,
@ -29,6 +28,9 @@
"web_timeline/static/src/js/timeline_controller.js",
"web_timeline/static/src/js/timeline_model.js",
"web_timeline/static/src/js/timeline_canvas.js",
]
],
"web.assets_qweb": [
"web_timeline/static/src/xml/web_timeline.xml",
],
},
}

View File

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

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Web timeline</title>
<style type="text/css">
@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>
<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>
<p>Define a new view displaying events in an interactive visualization chart.</p>
<p>The widget is based on the external library
<a class="reference external" href="https://visjs.github.io/vis-timeline/examples/timeline">https://visjs.github.io/vis-timeline/examples/timeline</a></p>
@ -526,6 +526,12 @@ with the dragged start and end date.</p>
<li>Implement a more efficient way of refreshing timeline after a record update;</li>
<li>Make <cite>attrs</cite> attribute work;</li>
<li>Make action attributes work (create, edit, delete) like in form and tree views.</li>
<li>When grouping by m2m and more than one record is set, the timeline item appears only
on one group. Allow showing in both groups.</li>
<li>When grouping by m2m and dragging for changing the time or the group, the changes on
the group will not be set, because it could make disappear the records not related
with the changes that we want to make. When the item is showed in all groups change
the value according the group of the dragged item.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
@ -533,7 +539,7 @@ with the dragged start and end date.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<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>
<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>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -553,14 +559,18 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Adrien Peiffer &lt;<a class="reference external" href="mailto:adrien.peiffer&#64;acsone.eu">adrien.peiffer&#64;acsone.eu</a>&gt;</li>
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;tecnativa.com">pedro.baeza&#64;tecnativa.com</a>&gt;</li>
<li>Leonardo Donelli &lt;<a class="reference external" href="mailto:donelli&#64;webmonks.it">donelli&#64;webmonks.it</a>&gt;</li>
<li>Adrien Didenot &lt;<a class="reference external" href="mailto:adrien.didenot&#64;horanet.com">adrien.didenot&#64;horanet.com</a>&gt;</li>
<li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li>
<li>Thong Nguyen Van &lt;<a class="reference external" href="mailto:thongnv&#64;trobz.com">thongnv&#64;trobz.com</a>&gt;</li>
<li>Alexandre Díaz &lt;<a class="reference external" href="mailto:alexandre.diaz&#64;tecnativa.com">alexandre.diaz&#64;tecnativa.com</a>&gt;</li>
<li>Murtaza Mithaiwala &lt;<a class="reference external" href="mailto:mmithaiwala&#64;opensourceintegrators.com">mmithaiwala&#64;opensourceintegrators.com</a>&gt;</li>
<li>Ammar Officewala &lt;<a class="reference external" href="mailto:aofficewala&#64;opensourceintegrators.com">aofficewala&#64;opensourceintegrators.com</a>&gt;</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
<li>Alexandre Díaz</li>
<li>César A. Sánchez</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
@ -572,7 +582,7 @@ mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/tarteo"><img alt="tarteo" src="https://github.com/tarteo.png?size=40px" /></a></p>
<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>
<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>
<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>
</div>
</div>

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