Skip to content

Commit

Permalink
Fix creat/delet bug in ControlPoint #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Diacquenod committed Aug 25, 2024
1 parent c6bb88f commit b11e3fc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions conformity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ def get_absolute_url():

@staticmethod
def post_init_callback(instance, **kwargs):
"""Delete old control point and create all control point needed for the chosen frequency."""
ControlPoint.objects.filter(control=instance.id).filter(Q(status='SCHD') | Q(status='TOBE')).delete()

num_cp = instance.frequency
Expand All @@ -453,11 +452,12 @@ def post_init_callback(instance, **kwargs):
for _ in range(num_cp):
period_start_date = date(start_date.year, start_date.month, 1)
period_end_date = date(end_date.year, end_date.month, monthrange(end_date.year, end_date.month)[1])
ControlPoint.objects.create(
control=instance,
period_start_date=period_start_date,
period_end_date=period_end_date,
)
if not ControlPoint.objects.filter(control=instance.id).filter(period_start_date=period_start_date).filter(period_end_date=period_end_date) :
ControlPoint.objects.create(
control=instance,
period_start_date=period_start_date,
period_end_date=period_end_date,
)
start_date = period_end_date + timedelta(days=1)
end_date = start_date + delta - timedelta(days=1)

Expand Down

0 comments on commit b11e3fc

Please sign in to comment.