Wip/71605 Garde Alternee Forcer La Selecti #71605 #11

Merged
vdeniaud merged 1 commits from wip/71605-Garde-alternee-forcer-la-selecti into main 2022-11-28 14:11:30 +01:00
2 changed files with 23 additions and 2 deletions

View File

@ -1498,7 +1498,7 @@ class SharedCustodyRuleForm(forms.ModelForm):
days = forms.TypedMultipleChoiceField(
choices=WEEKDAY_CHOICES,
coerce=int,
required=False,
required=True,
widget=WeekdaysWidget,
label=_('Days'),
)
@ -1518,7 +1518,7 @@ class SharedCustodyRuleForm(forms.ModelForm):
cleaned_data = super().clean()
if self.instance.agenda.rule_overlaps(
days=cleaned_data['days'], weeks=cleaned_data['weeks'], instance=self.instance
days=cleaned_data.get('days', []), weeks=cleaned_data['weeks'], instance=self.instance
):
raise ValidationError(_('Rule overlaps existing rules.'))

View File

@ -82,6 +82,27 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
assert SharedCustodyRule.objects.count() == 1
def test_shared_custody_agenda_settings_rules_require_days(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
)
app = login(app)
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
resp = resp.click('Add custody rule')
resp.form['guardian'] = father.pk
resp.form['weeks'] = 'even'
resp = resp.form.submit()
assert 'This field is required.' in resp.text
resp.form['days'] = [0]
resp.form.submit().follow()
assert SharedCustodyRule.objects.count() == 1
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_settings_periods(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')