Skip to content

Commit

Permalink
warns and aborts when Count objects are below 100 when generating report
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Nov 17, 2023
1 parent c083d2e commit 6a4826c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion comptages/core/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from datetime import timedelta, datetime
from openpyxl import load_workbook
from comptages.core.utils import push_info

from comptages.datamodel import models
from comptages.core import statistics
Expand Down Expand Up @@ -64,12 +65,21 @@ def _prepare_default_reports(file_path, count, template_path, callback_progress)
def _prepare_yearly_report(
file_path, year, template_path, section_id, callback_progress
):
lower_bound = 100
section = models.Section.objects.get(id__contains=section_id)
# Get first count to be used as example
count_qs = models.Count.objects.filter(
id_installation__lane__id_section=section, start_process_date__year=year
)
if not count_qs:
count_nb = count_qs.count()

if count_nb < lower_bound:
push_info(
f"""
Only {count_nb} Count objects were found! Please add {lower_bound - count_nb} objects before retrying.
No report will be generated until then.
"""
)
return
count = count_qs[0]

Expand Down

0 comments on commit 6a4826c

Please sign in to comment.