Skip to content

Instantly share code, notes, and snippets.

@ofelix03
Last active April 30, 2025 15:36
Show Gist options
  • Save ofelix03/0afbf4643ad2678e0afbc0caedd24c6b to your computer and use it in GitHub Desktop.
Save ofelix03/0afbf4643ad2678e0afbc0caedd24c6b to your computer and use it in GitHub Desktop.
Medium Article - Gantt Renderer JS - Fetch Employee Time-off Periods
patch(GanttRenderer.prototype, {
getEmployeeTimeOffType(row, column) {
column.leaveType = null;
column.leaveTypeIcon = null;
column.showLeaveTypeText = false;
if (!row.isGroup) {
const {resId} = row;
const start = column.start.toISODate();
const stop = column.stop.toISODate();
if (resId) {
if (this.timeOffPeriodsPerEmployee.data[resId]) {
const timeOffs = this.timeOffPeriodsPerEmployee.data[resId].filter(
(data) => {
let [timeOffStart, timeOffEnd, leaveType, leaveTypeIcon] =
data;
timeOffStart = DateTime.fromFormat(
timeOffStart,
"yyyy-MM-dd"
).toISODate();
timeOffEnd = DateTime.fromFormat(
timeOffEnd,
"yyyy-MM-dd"
).toISODate();
const isWithinTimeOff =
start >= timeOffStart &&
start <= timeOffEnd &&
stop >= timeOffStart &&
stop <= timeOffEnd;
return isWithinTimeOff;
}
);
if (timeOffs.length >= 1) {
const {id, interval} = this.model.metaData.scale;
if (column.leaveType != timeOffs[0][2]) {
column.leaveType = timeOffs[0][2];
column.leaveTypeIcon = timeOffs[0][3];
column.showLeaveTypeText =
column.leaveTypeIcon &&
id == "week" &&
interval == "day";
}
}
}
}
}
},
async getEmployeesTimeOfffPeriods() {
let resIds = [];
this.rowsToRender.forEach((row) => resIds.push(row.resId));
resIds = resIds.filter((empId) => empId != false);
const {resModel} = this.model.metaData;
this.timeOffPeriodsPerEmployee.data = await this.model.orm.call(
"hr.leave",
"get_employee_timeoff_periods",
[resModel, resIds]
);
},
computeVisiblePills() {
super.computeVisiblePills();
this.getEmployeesTimeOfffPeriods();
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment