manager: forbid checking arrival after departure for partial bookings (#81619)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-09-26 11:47:30 +02:00
parent ec86a9bbcc
commit 33e53a694a
2 changed files with 10 additions and 0 deletions

View File

@ -634,6 +634,9 @@ class PartialBookingCheckForm(forms.ModelForm):
self.fields.pop('absence_check_type', None)
def clean(self):
if self.cleaned_data['user_check_end_time'] <= self.cleaned_data['user_check_start_time']:
raise ValidationError(_('Arrival must be before departure.'))
if self.cleaned_data['user_was_present'] is not None:
kind = 'presence' if self.cleaned_data['user_was_present'] else 'absence'
if f'{kind}_check_type' in self.cleaned_data:

View File

@ -273,6 +273,13 @@ def test_manager_partial_bookings_check(check_types, app, admin_user):
assert resp.pyquery('.time-widget-button')[0].text == 'Fill with booking start time'
assert resp.pyquery('.time-widget-button')[1].text == 'Fill with booking end time'
resp.form['user_check_start_time'] = '11:01'
resp.form['user_check_end_time'] = '11:00'
resp.form['user_was_present'] = 'True'
resp = resp.form.submit()
assert 'Arrival must be before departure.' in resp.text
resp.form['user_check_start_time'] = '11:01'
resp.form['user_check_end_time'] = '13:15'
resp.form['user_was_present'] = 'True'