Jul 27 - Update code for scheduled tasks 2
This commit is contained in:
@@ -339,6 +339,10 @@ class ScheduledInspectionForm(FlaskForm):
|
||||
('weekly', 'Weekly'), ('monthly', 'Monthly'),
|
||||
], validators=[DataRequired()])
|
||||
next_due_date = DateField('Start / Due Date', validators=[DataRequired()])
|
||||
# Label is overridden per context in routes/scheduled_inspections.py:
|
||||
# "Start Date" when creating, "Next Due Date" when editing. The default
|
||||
# above is only a fallback.
|
||||
end_date = DateField('End Date', validators=[Optional()])
|
||||
# UI label only. The field name, the ScheduledInspection.notes attribute and
|
||||
# the scheduled_inspections.notes column all stay `notes` — renaming any of
|
||||
# them would break the API payload key the iPad decodes.
|
||||
@@ -387,6 +391,20 @@ class ScheduledInspectionForm(FlaskForm):
|
||||
elif not self.day_of_month.data:
|
||||
self.day_of_month.errors.append('Enter a day of the month (1–31).')
|
||||
ok = False
|
||||
|
||||
# End date (phase44). Only meaningful for recurring schedules — a
|
||||
# one-time schedule ends by deactivating when it is completed. Rejecting
|
||||
# an end date before the due date here is what makes the "already past
|
||||
# its boundary on save" case unreachable in the routes.
|
||||
if self.end_date.data:
|
||||
if self.frequency.data == 'once':
|
||||
self.end_date.errors.append(
|
||||
'A one-time schedule has no end date — it closes when completed.')
|
||||
ok = False
|
||||
elif self.next_due_date.data and self.end_date.data < self.next_due_date.data:
|
||||
self.end_date.errors.append(
|
||||
'End date must be on or after the due date.')
|
||||
ok = False
|
||||
return ok
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user