0004-agendas-add-command-to-update-shared-custody-holiday.patch
chrono/agendas/management/commands/update_shared_custody_holiday_rules.py | ||
---|---|---|
1 |
# chrono - agendas system |
|
2 |
# Copyright (C) 2022 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from django.core.management.base import BaseCommand |
|
18 | ||
19 |
from chrono.agendas.models import SharedCustodyHolidayRule |
|
20 | ||
21 | ||
22 |
class Command(BaseCommand): |
|
23 |
help = 'Update shared custody holiday rules' |
|
24 | ||
25 |
def handle(self, **options): |
|
26 |
for rule in SharedCustodyHolidayRule.objects.all(): |
|
27 |
rule.update_or_create_periods() |
debian/uwsgi.ini | ||
---|---|---|
27 | 27 |
cron = 1 -1 -1 -1 -1 /usr/bin/chrono-manage tenant_command sync_desks_timeperiod_exceptions --all-tenants |
28 | 28 |
# daily |
29 | 29 |
cron = 2 4 -1 -1 -1 /usr/bin/chrono-manage tenant_command anonymize_bookings --all-tenant |
30 |
# monthly |
|
31 |
cron = 1 1 1 -1 -1 /usr/bin/chrono-manage tenant_command update_shared_custody_holiday_rules --all-tenant |
|
30 | 32 |
# every 01/01 at 1:1 |
31 | 33 |
cron = 1 1 1 1 -1 /usr/bin/chrono-manage tenant_command sync_desks_timeperiod_exceptions_from_settings --all-tenants -v0 |
32 | 34 |
tests/test_agendas.py | ||
---|---|---|
3308 | 3308 |
('28/12', 'Jane Doe'), |
3309 | 3309 |
('29/12', 'John Doe'), |
3310 | 3310 |
] |
3311 | ||
3312 | ||
3313 |
def test_shared_custody_agenda_update_holiday_rules_command(): |
|
3314 |
calendar = UnavailabilityCalendar.objects.create(label='Calendar') |
|
3315 | ||
3316 |
father = Person.objects.create(user_external_id='father_id', name='John Doe') |
|
3317 |
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe') |
|
3318 |
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother) |
|
3319 | ||
3320 |
christmas_holiday = TimePeriodExceptionGroup.objects.create( |
|
3321 |
unavailability_calendar=calendar, label='Christmas', slug='christmas' |
|
3322 |
) |
|
3323 |
exception = TimePeriodException.objects.create( |
|
3324 |
unavailability_calendar=calendar, |
|
3325 |
start_datetime=make_aware(datetime.datetime(year=2021, month=12, day=18, hour=0, minute=0)), |
|
3326 |
end_datetime=make_aware(datetime.datetime(year=2022, month=1, day=3, hour=0, minute=0)), |
|
3327 |
group=christmas_holiday, |
|
3328 |
) |
|
3329 | ||
3330 |
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father) |
|
3331 |
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='odd', guardian=mother) |
|
3332 | ||
3333 |
rule = SharedCustodyHolidayRule.objects.create(agenda=agenda, guardian=father, holiday=christmas_holiday) |
|
3334 |
rule.update_or_create_periods() |
|
3335 | ||
3336 |
period = SharedCustodyPeriod.objects.get() |
|
3337 |
assert period.date_start == datetime.date(year=2021, month=12, day=18) |
|
3338 |
assert period.date_end == datetime.date(year=2022, month=1, day=3) |
|
3339 | ||
3340 |
exception.start_datetime += datetime.timedelta(days=1) |
|
3341 |
exception.save() |
|
3342 |
TimePeriodException.objects.create( |
|
3343 |
unavailability_calendar=calendar, |
|
3344 |
start_datetime=make_aware(datetime.datetime(year=2022, month=12, day=18, hour=0, minute=0)), |
|
3345 |
end_datetime=make_aware(datetime.datetime(year=2023, month=1, day=3, hour=0, minute=0)), |
|
3346 |
group=christmas_holiday, |
|
3347 |
) |
|
3348 | ||
3349 |
call_command('update_shared_custody_holiday_rules') |
|
3350 |
period1, period2 = SharedCustodyPeriod.objects.all() |
|
3351 |
assert period1.date_start == datetime.date(year=2021, month=12, day=19) |
|
3352 |
assert period1.date_end == datetime.date(year=2022, month=1, day=3) |
|
3353 |
assert period2.date_start == datetime.date(year=2022, month=12, day=18) |
|
3354 |
assert period2.date_end == datetime.date(year=2023, month=1, day=3) |
|
3311 |
- |