Skip to content

Commit

Permalink
appt_date not on or before report datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Sep 22, 2023
1 parent 736e5cf commit 19a6c76
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions edc_next_appointment/form_validators/form_validator_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.utils.translation import gettext_lazy as _
from edc_form_validators import INVALID_ERROR
from edc_utils.date import to_local

from ..utils import allow_clinic_on_weekend

Expand All @@ -28,6 +29,10 @@ def clinic_days(self) -> list[int]:

def validate_date_is_on_clinic_day(self):
if appt_date := self.cleaned_data.get("appt_date"):
if appt_date <= to_local(self.cleaned_data.get("report_datetime")).date():
raise self.raise_validation_error(
{"appt_date": "Cannot be on or before the report datetime"}, INVALID_ERROR
)
if not allow_clinic_on_weekend() and appt_date.weekday() > calendar.FRIDAY:
raise self.raise_validation_error(
{
Expand Down

0 comments on commit 19a6c76

Please sign in to comment.