timeoff-management/timeoff-management-application

No overlapping error is thrown when booking a leave within another leave date range.

inwebgames opened this issue · 1 comments

Hello, thank you first for this application which is very useful,
I found a problem in the application and also within the cloud hosted app, it concerns the overlapping of leaves, assuming we have two leaves of types 'holiday' and 'sick leave' both with x days in limit and both are using allowance, for example, when your book a leave for type 'holiday' let says for start_date 08/02/2021 to end_date 12/02/2021 it get inserted.

Then when your book a leave for any type 'holiday' or 'sick leave' let says for start_date 09/02/2021 to end_date 11/02/2021 or any dates between those dates it get also inserted and no overlapping error is thrown, after many test i found that booking leaves is possible between the second day of the start date of the previous request and before last day of the end date of that request. (The algorithm is checking only the start_date and the end_date not the days between)

I don't know if this policy is part of the system or a bug, but logically it doesn't make sense to accept a leave request within another leave date range.
Please correct me if misunderstand something.

Note: using allowance or not doesn't change anything about this problem also the status (whether the request is approved or still open)

Hello everyone,
For all the people who are considering this problem, and looking for a solution, this is how i managed to solve it :
In lib/model/mixin/user/absence_aware.js ( From line 122) this is the changes :
In the validate_overlapping function,

var this_user = this;

var start_date_filter = {
  $lte : moment.utc(new_leave_attributes.to_date).add(1,'days').format('YYYY-MM-DD'),
};

var end_date_filter = {
  $gte : new_leave_attributes.from_date
};

// Where condition : (`Leave`.`date_start` <= date_end AND `Leave`.`date_end` >= date_start)
return this_user.getMy_leaves({
  logging: console.log,
  where : {
    $and : [
      { status : { $ne : sequelize.models.Leave.status_rejected() } },
      { status : { $ne : sequelize.models.Leave.status_canceled() } },
      { date_start : start_date_filter },
      { date_end : end_date_filter },
    ],
  },
})

.then(function(overlapping_leaves){

  // Check there are overlapping leaves
  if (overlapping_leaves.length === 0){
      return Promise.resolve(1);
  }

  //Deactivate fit_with_leave_request check
  //var overlapping_leave = overlapping_leaves[0];
  //if (overlapping_leave.fit_with_leave_request(
  //      new_leave_attributes
  //)){
  //    return Promise.resolve(1);
  //}

  // Otherwise it is overlapping!
  var error = new Error('Overlapping booking!');
  error.user_message = 'Les dates choisis se chevauchent avec d\'autres dates!';
  throw error;

});