Most Powerful Open Source ERP

How To Use ERP5 Calendar

How To showing how to calculate working days and handle vacation, sick leaves and other absence periods.
  • Last Update:2016-02-09
  • Version:001
  • Language:en

The erp5_calendar business template provides a handy tool for calculating working days, planning and accounting for holidays, vacation, sick leaves and all kinds of absence periods. Here is a quick guide how to configure it and how to use it.

Table of Contents

Group Calendar

This is the place where you can define which days are "working days" in terms of "periodicity", what is a "working day", and which days are "off". Once you've created a Group Calendar object in the module, do the following:

Set periodicity

Most likely it is going to be Monday through Friday, with all the other fields empty. If this is a one-year calendar, fill in "periodicity stop date" field.

Set exceptions

A "Calendar Exception" is a day when you do not have to work - like May 1st, December 24th etc. Also you can use it to mark a time when your company is off for a conference or survival camp.

Set start and stop date

Contrary to what you may think, this is /!\ NOT /!\ a beginning/end date of the calendar. The start/stop date is a definition of a working day, so it should be the start and stop of the first working day in the calendar. Therefore, if you are creating a calendar for, say, 2008, set:

start_date = '2008/01/01 08:00:00'
stop_date = '2008/01/01 16:00:00'

ERP5 will use it to determine how many seconds a working day has.

Validate

Now you can use simulation API to find out how many working days are there between certain dates:

calendar_uid = context.restrictedTraverse('group_calendar_module/1').getUid()
node_list = [calendar_uid]
from_date = DateTime('2008/01/01')
to_date = DateTime('2008/04/01')
seconds = context.portal_simulation.getAvailableTime(node=node_list, from_date=from_date, to_date=to_date)

To recalculate it into days, see what is the length of working days you've set as start_date/stop_date.

Leave Request

Nothing special here - just create, set "destination" (the person filing for a vacation), add a line with start and stop date, validate the whole request.

Working days for a person

ERP5 can calculate how many days a person is going to work over a given period of time by putting together a calendar and a set of validated leave requests. By default, a "Person" object is linked to a calendar through Assignment. Person has an API for checking available time:

person = context.restrictedTraverse('person_module/1')
from_date = DateTime('2008/01/01')
to_date = DateTime('2008/04/01')
seconds = person.getAvailableTime(from_date=from_date, to_date=to_date) 

This uses Assignments to find calendar(s) a person is supposed to "use" (without checking if assignment is open or not). You can write your own script to determine calendar in any other way, and use directly the Calendar's API:

calendar_uid = context.restrictedTraverse('group_calendar_module/1').getUid()
person_uid = context.restrictedTraverse('person_module/1').getUid()
node_list = [calendar_uid, person_uid]
from_date = DateTime('2008/01/01')
to_date = DateTime('2008/04/01')
seconds = context.portal_simulation.getAvailableTime(node=node_list, from_date=from_date, to_date=to_date)

A Word about Dates

The "to_date" is not inclusive, plus the system uses date-time rather then date, and if you use date only, time defaults to 00:00:00. The result is that if you apply for a vacation from 2008/01/14 to 2008/01/15, you will get zero days instead of two days you expect.

Related Articles