Last active
April 30, 2025 15:36
-
-
Save ofelix03/0afbf4643ad2678e0afbc0caedd24c6b to your computer and use it in GitHub Desktop.
Medium Article - Gantt Renderer JS - Fetch Employee Time-off Periods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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