def _allowance_days(self, yearoffset=0): yearstart, yearend = get_year_start_end(yearoffset) if self.start_date > yearstart or (self.end_date and self.end_date < yearend): if self.end_date: if self.end_date < yearstart: return 0 #always zero elif self.end_date < yearend and self.start_date > yearstart: time_diff = self.end_date - self.start_date elif self.end_date < yearend: time_diff = self.end_date - yearstart else: # self.start_date > yearstart: time_diff = yearend - self.start_date # Added 1 day to the time difference, as you work both your first and last day. # (eg the datedifference of today - yesterday is 1, but you've worked two days) return ((time_diff.days +1) / 365.25) * self.holiday_per_annum else: return self.holiday_per_annum
def _accepted_days(self, yearoffset=0): yearstart, yearend = get_year_start_end(yearoffset) qs = Holiday.objects.filter(holiday_request__employee__exact=self, holiday_request__status__exact=1, date__gte=yearstart, date__lt=yearend).distinct() return qs