Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Do not display hours into cell in gantt planning view

形象
odoo
形象
丢弃
2 答案
0
形象
odoo
最佳答案

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

1 备注
形象
丢弃
形象
odoo
-

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(' - ');
}); } }); });

0
形象
odoo
最佳答案

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 ;-)

1 备注
形象
丢弃
形象
odoo
-

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