Skip to content

Commit

Permalink
Remove add_consecutive function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kejebo committed Aug 14, 2024
1 parent 50657ab commit 463fe01
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
2 changes: 0 additions & 2 deletions src/laboratory/management/commands/precursor_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Laboratory
from laboratory.task_utils import save_object_report_precursor, \
build_precursor_report_from_reports
from laboratory.tasks import add_consecutive


class Command(BaseCommand):
Expand All @@ -34,7 +33,6 @@ def get_change_log(self):
month=current_time.month,
year=current_time.year,
laboratory=lab,
consecutive=add_consecutive(lab)
)
save_object_report_precursor(report)
build_precursor_report_from_reports(report, previos_report)
Expand Down
12 changes: 11 additions & 1 deletion src/laboratory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,17 @@ class PrecursorReport(models.Model):
consecutive = models.IntegerField(default=1)
report_values = models.ManyToManyField(Object,through=PrecursorReportValues)


def save(self, *args, **kwargs):
if not self.pk:
print(self.laboratory)
max_consecutive = PrecursorReport.objects.filter(
laboratory=self.laboratory).aggregate(Max("consecutive"))["consecutive__max"]

if max_consecutive is None:
self.consecutive=1
else:
self.consecutive= max_consecutive+1
super().save(*args, **kwargs)

STATUS_CHOICES = (
(_('Eraser'), _('Eraser')),
Expand Down
20 changes: 0 additions & 20 deletions src/laboratory/task_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ def get_base_unit(unit):
return BaseUnitValues.objects.filter(pk=4).first().measurement_unit
return unit

def set_precursor_report_consecutive(laboratory):
reports = PrecursorReport.objects.filter(laboratory=laboratory)
years= sorted(set(reports.values_list("year",flat=True).order_by("-year")))
consecutive=1
for year in years:
reports_month = reports.filter(year=year).order_by("month")
for res in reports_month:
res.consecutive=consecutive
res.save()
consecutive+=1

def create_new_precursosr_report(laboratories):
day = now() - relativedelta(months=1)
Expand All @@ -132,17 +122,7 @@ def create_new_precursosr_report(laboratories):
month=day.month,
year=day.year,
laboratory=lab,
consecutive=add_consecutive(lab)
)
save_object_report_precursor(report)
build_precursor_report_from_reports(report, previous_report)
set_precursor_report_consecutive(lab)


def add_consecutive(lab):
report = PrecursorReport.objects.filter(laboratory=lab).last()
consecutive = 1
if report is not None:
consecutive = int(report.consecutive)+1

return consecutive
4 changes: 1 addition & 3 deletions src/laboratory/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from .limit_shelfobject import send_email_limit_objs
from .task_utils import create_informsperiods, save_object_report_precursor, \
build_precursor_report_from_reports, add_consecutive
build_precursor_report_from_reports

from dateutil.relativedelta import relativedelta
from django.utils.timezone import now
Expand Down Expand Up @@ -57,7 +57,6 @@ def create_precursor_reports():
month=day.month,
year=day.year,
laboratory=lab,
consecutive=add_consecutive(lab)
)
save_object_report_precursor(report)
build_precursor_report_from_reports(report, previous_report)
Expand All @@ -73,7 +72,6 @@ def verify_precursor_reports():
month=day.month,
year=day.year,
laboratory=lab,
consecutive=add_consecutive(lab)
)
save_object_report_precursor(report)
build_precursor_report_from_reports(report, previous_report)
Expand Down
2 changes: 1 addition & 1 deletion src/organilab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
},
'verify_precursor_reports': {
'task': 'laboratory.tasks.verify_precursor_reports',
'schedule': crontab(hour='/*6', day_of_month="/*2"),
'schedule': crontab(hour='*/6', day_of_month="*/2"),
},
}

Expand Down

0 comments on commit 463fe01

Please sign in to comment.