Skip to content

Commit

Permalink
[#3049] Fix end-date of plan can precede that of action templates
Browse files Browse the repository at this point in the history
  • Loading branch information
linssen814 committed Feb 20, 2025
1 parent eaf6816 commit 73e5fa9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Binary file modified src/open_inwoner/conf/locale/nl/LC_MESSAGES/django.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions src/open_inwoner/conf/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6431,6 +6431,10 @@ msgstr "U dient in ieder geval 1 contactpersoon toe te voegen voor een plan."
msgid "This field is required when not using a template"
msgstr "Dit veld is vereist."

#: open_inwoner/plans/forms.py:93
msgid "The end date of the plan cannot precede the end dates of the actions in the selected template."
msgstr "De einddatum van het plan kan niet voorafgaan aan de einddatums van de acties in het geselecteerde sjabloon."

#: open_inwoner/plans/models.py:22
msgid "The name of the plan template. Will not be copied over to the plan."
msgstr "De naam van het plansjabloon. Wordt niet overgekopieerd naar het plan."
Expand Down
24 changes: 23 additions & 1 deletion src/open_inwoner/plans/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta
from datetime import date, timedelta
from io import BytesIO

from django import forms
Expand Down Expand Up @@ -59,6 +59,7 @@ def clean(self):
goal = cleaned_data.get("goal")
template = cleaned_data.get("template")
plan_contacts = cleaned_data.get("plan_contacts")
end_date = cleaned_data.get("end_date")

if not plan_contacts or (
plan_contacts and not plan_contacts.exclude(pk=self.user.pk)
Expand All @@ -71,6 +72,27 @@ def clean(self):
"goal", _("This field is required when not using a template")
)

# Verify that the selected end date of the plan does not precede the
# would-be dates of the actions in the selected template (if any)
if template and end_date:
template_row = PlanTemplate.objects.get(id=template.id)

actionTemplates = template_row.actiontemplates.all()

if actionTemplates:
latest_end_in_days = max([a.end_in_days for a in actionTemplates])

today = date.today()
actions_end_date = today + timedelta(days=latest_end_in_days)

if end_date < actions_end_date:
self.add_error(
"end_date",
_(
"The end date of the plan cannot precede the end dates of the actions in the selected template."
),
)

def clean_plan_contacts(self):
# Make sure current user exists in plan_contacts when editing form
data = self.cleaned_data["plan_contacts"]
Expand Down

0 comments on commit 73e5fa9

Please sign in to comment.