Skip to Content
Menu
This question has been flagged
3 Replies
1944 Views

Hello,

I use Odoo v15 enterprise dition and I would like to modify the task cell display in gantt view of the planning module.

My goal is to hide Hours  : Start hour - End Hour (duration) and only see the task name.

Here is an example vidéo : https://watch.screencastify.com/v/Y3W7l2aDazHzYj0jEGx4

Could someone help me?


Avatar
Discard
Best Answer

Hello Richard Garcia,

- To display only Task name and to hide the Start Hour -End Hour, you need to inherit the JS Class: PlanningGanttRenderer.
- After inheriting the JS class , then you need to overwrite the whole method : “_generatePillLabels” as by inheriting the method the goal cannot be achieved.
- Inside the condition of “!==month” ,first you need to empty all the list elements from labelElements and need to push that you need.

Please find code in comment.

I hope this will help you. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Please refer to the below code for your reference.

odoo.define('planning_gantt.PlanningGanttView', function (require) {
'use strict';

const PlanningGanttRenderer = require('planning.PlanningGanttRenderer');
const fieldUtils = require('web.field_utils');
const { patch } = require('web.utils');
const utils = require('web.utils');

patch(PlanningGanttRenderer.prototype, 'PlanningGanttLabels', {
_generatePillLabels: function (pills, scale) {
const dateFormat = moment.localeData().longDateFormat('l');
const yearlessDateFormat = dateFormat.replace(/Y/gi, '').replace(/(\W)\1+/g, '$1').replace(/^\W|\W$/, '');
pills.filter(pill => !pill.consolidated).forEach(pill => {
const localStartDateTime = (pill.start_datetime || pill.startDate).clone().local();
const localEndDateTime = (pill.end_datetime || pill.stopDate).clone().local();
const spanAccrossDays = localStartDateTime.clone().startOf('day')
.diff(localEndDateTime.clone().startOf('day'), 'days') != 0;
const spanAccrossWeeks = localStartDateTime.clone().startOf('week')
.diff(localEndDateTime.clone().startOf('week'), 'weeks') != 0;
const spanAccrossMonths = localStartDateTime.clone().startOf('month')
.diff(localEndDateTime.clone().startOf('month'), 'months') != 0;
const labelElements = [];
if (scale === 'year' && !spanAccrossDays) {
labelElements.push(localStartDateTime.format(yearlessDateFormat));
} else if (
(scale === 'day' && spanAccrossDays) ||
(scale === 'week' && spanAccrossWeeks) ||
(scale === 'month' && spanAccrossMonths) ||
(scale === 'year' && spanAccrossDays)
) {
labelElements.push(localStartDateTime.format(yearlessDateFormat));
labelElements.push(localEndDateTime.format(yearlessDateFormat));
}
if (!spanAccrossDays && ['week', 'month'].includes(scale)) {
labelElements.push(
localStartDateTime.format('LT'),
localEndDateTime.format('LT') + ' (' + fieldUtils.format.float_time(pill.allocated_hours, {}, {noLeadingZeroHour: true}).replace(/(:00|:)/g, 'h') + ')'
); }
if (scale !== 'month' || spanAccrossDays) {
labelElements.length = 0;
labelElements.push(pill.display_name);
}
pill.label = labelElements.filter(el => !!el).join(' - ');
}); } }); });

Best Answer

Hi,

I had the same issue (Odoo16) and I could resolve it by changing the attribute pill_label to "" instead of "True" (default value).

If you want a cleaner way to do it, extend the default gantt view with a custom one and use xpath:

ath expr="//gantt" position="attributes">

    <attribute name="pill_label">attribute>

xpath> 

Avatar
Discard
Author Best Answer

Many Thanks  for your answer Jainesh. I have tried to modify directely the _generatePillLabels  method in the Odoo original source file and it works but it is not clean. I don't know how to implement Js inheritance class. Could you give me a little bit more information? I'm really sorry but i'm a newby  on Odoo dev ;-)

Avatar
Discard
Author

I ask my question besouse i have found the solution.
I'm on odoo v15 so i modified my addon manifest to add the custom file in the web_backend js

Related Posts Replies Views Activity
1
Oct 23
7066
0
Sep 24
61
1
Nov 21
1518
1
Mar 21
34999
1
Jul 20
2181