Skip to content

Commit

Permalink
check that staffing mission boundaries are not changed in an
Browse files Browse the repository at this point in the history
inconsistent way with current staffing
  • Loading branch information
digitalfox committed Nov 10, 2024
1 parent b69a9c6 commit 36560e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion staffing/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def add_fields(self, form, index):
if self.instance.end_date:
maxDate = self.instance.end_date.replace(day=1)
else:
maxDate = None
maxDate = self.instance.staffing_end_date()
form.fields["consultant"] = ModelChoiceField(widget=ConsultantChoices(attrs={'data-placeholder':_("Select a consultant to add forecast...")}), queryset=Consultant.objects)
form.fields["staffing_date"] = StaffingDateChoicesField(minDate=minDate, maxDate=maxDate)
form.fields["charge"].widget.attrs["class"] = "numberinput form-control"
Expand Down Expand Up @@ -410,9 +410,13 @@ def _clean_start_end_date(self, field):
return self.cleaned_data[field]

def clean_start_date(self):
if self.cleaned_data.get("start_date") and self.cleaned_data.get("start_date") > self.instance.staffing_start_date():
raise ValidationError(_("start date must be before staffing start date (%s)" % self.instance.staffing_start_date()))
return self._clean_start_end_date("start_date")

def clean_end_date(self):
if self.cleaned_data.get("end_date") and self.cleaned_data.get("end_date") < self.instance.staffing_end_date():
raise ValidationError(_("end date must be after staffing end date (%s)" % self.instance.staffing_end_date()))
return self._clean_start_end_date("end_date")

def clean(self):
Expand Down
11 changes: 10 additions & 1 deletion staffing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,22 @@ def objectiveMargin(self, startDate=None, endDate=None):

@cacheable("Mission.staffing_start_date%(id)s", 10)
def staffing_start_date(self):
"""Starting date (=oldiest) staffing date of this mission. None if no staffing"""
"""Starting date (=oldest) staffing date of this mission. None if no staffing"""
start_dates = self.staffing_set.all().aggregate(Min("staffing_date")).values()
if start_dates:
return list(start_dates)[0]
else:
return None

@cacheable("Mission.staffing_end_date%(id)s", 10)
def staffing_end_date(self):
"""End date (=latest) staffing date of this mission. None if no staffing"""
end_dates = self.staffing_set.all().aggregate(Max("staffing_date")).values()
if end_dates:
return list(end_dates)[0]
else:
return None

def pivotable_data(self, startDate=None, endDate=None):
"""Compute raw data for pivot table on that mission"""
#TODO: factorize with staffing.views.mission_timesheet
Expand Down

0 comments on commit 36560e7

Please sign in to comment.