Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Adjust hiding of overlapping public holidays and absences
Browse files Browse the repository at this point in the history
Determine by location of employment at the date of absence whether
a public holiday overlaps it.
  • Loading branch information
Oliver Sauder committed Jan 4, 2018
1 parent 4cc9d04 commit 42d013a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions timed/tracking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,23 @@ class Meta:

class AbsenceManager(models.Manager):
def get_queryset(self):
from timed.employment.models import PublicHoliday
"""Return only absences which do not overlap with public holidays."""
from timed.employment.models import Employment, PublicHoliday

# location of employment at the date of absence
location_qs = Employment.objects.filter(
(
models.Q(end_date__gte=models.OuterRef('date')) |
models.Q(end_date__isnull=True)
),
start_date__lte=models.OuterRef('date'),
user_id=models.OuterRef(models.OuterRef('user'))
).values('location')[:1]

queryset = super().get_queryset()
queryset = queryset.exclude(date__in=models.Subquery(
PublicHoliday.objects.filter(
location__employments__user=models.OuterRef('user')
location=models.Subquery(location_qs)
).values('date')
))
return queryset
Expand Down
15 changes: 13 additions & 2 deletions timed/tracking/tests/test_absence.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@


def test_absence_list_authenticated(auth_client):
absence = AbsenceFactory.create(user=auth_client.user)
# public holidays of previous location may not be hidden
absence = AbsenceFactory.create(
user=auth_client.user, date=datetime.date(2018, 1, 2)
)
previous_employment = EmploymentFactory.create(
user=absence.user,
start_date=datetime.date(2017, 1, 1),
end_date=datetime.date(2017, 12, 31)
)
PublicHolidayFactory.create(
date=absence.date, location=previous_employment.location
)

# overlapping absence with public holidays need to be hidden
overlap_absence = AbsenceFactory.create(
user=auth_client.user, date=datetime.date(2018, 1, 1))
employment = EmploymentFactory.create(
user=overlap_absence.user,
start_date=datetime.date(2017, 12, 31)
start_date=datetime.date(2018, 1, 1)
)
PublicHolidayFactory.create(
date=overlap_absence.date, location=employment.location
Expand Down

0 comments on commit 42d013a

Please sign in to comment.