manager: forbid second partial booking check with same status (#83505)
gitea/chrono/pipeline/head This commit looks good
Details
gitea/chrono/pipeline/head This commit looks good
Details
This commit is contained in:
parent
21cd345c35
commit
d9a93ac2e3
|
@ -610,8 +610,9 @@ class PartialBookingCheckForm(forms.ModelForm):
|
|||
'type_slug': forms.HiddenInput(),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args, first_check_form=None, **kwargs):
|
||||
agenda = kwargs.pop('agenda')
|
||||
self.first_check_form = first_check_form
|
||||
super().__init__(*args, **kwargs)
|
||||
self.check_types = get_agenda_check_types(agenda)
|
||||
absence_check_types = [(ct.slug, ct.label) for ct in self.check_types if ct.kind == 'absence']
|
||||
|
@ -636,7 +637,7 @@ class PartialBookingCheckForm(forms.ModelForm):
|
|||
self.fields.pop('absence_check_type', None)
|
||||
|
||||
def clean(self):
|
||||
if self.cleaned_data['presence'] is None:
|
||||
if self.cleaned_data.get('presence') is None:
|
||||
return
|
||||
|
||||
start_time = self.cleaned_data.get('start_time')
|
||||
|
@ -656,6 +657,16 @@ class PartialBookingCheckForm(forms.ModelForm):
|
|||
self.cleaned_data['type_slug']
|
||||
)
|
||||
|
||||
def clean_presence(self):
|
||||
if (
|
||||
self.first_check_form
|
||||
and self.cleaned_data['presence'] is not None
|
||||
and self.cleaned_data['presence'] == self.first_check_form.cleaned_data['presence']
|
||||
):
|
||||
raise ValidationError(_('Both booking checks cannot have the same status.'))
|
||||
|
||||
return self.cleaned_data['presence']
|
||||
|
||||
def save(self):
|
||||
booking = self.instance.booking
|
||||
if self.cleaned_data['presence'] is None:
|
||||
|
|
|
@ -4615,6 +4615,7 @@ class PartialBookingCheckView(ViewableAgendaMixin, TemplateView):
|
|||
PartialBookingCheckForm(
|
||||
instance=second_check,
|
||||
prefix=self.get_prefix(booking, second_check=True),
|
||||
first_check_form=booking.check_forms[0],
|
||||
**kwargs,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -591,6 +591,23 @@ def test_manager_partial_bookings_multiple_checks(app, admin_user):
|
|||
|
||||
assert 'Booking check hours are overlapping.' in resp.text
|
||||
|
||||
# two check cannot have the same presence value
|
||||
resp.form['presence'] = 'True'
|
||||
resp.form['start_time'] = '10:00'
|
||||
resp.form['end_time'] = '11:00'
|
||||
resp.form['check-2-presence'] = 'True'
|
||||
resp.form['check-2-start_time'] = '12:00'
|
||||
resp.form['check-2-end_time'] = '13:00'
|
||||
resp = resp.form.submit()
|
||||
|
||||
assert 'Both booking checks cannot have the same status.' in resp.text
|
||||
|
||||
resp.form['presence'] = 'False'
|
||||
resp.form['check-2-presence'] = 'False'
|
||||
resp = resp.form.submit()
|
||||
|
||||
assert 'Both booking checks cannot have the same status.' in resp.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('subscription_only', (True, False))
|
||||
def test_manager_partial_bookings_incomplete_check(subscription_only, app, admin_user):
|
||||
|
|
Loading…
Reference in New Issue