Skip to content

Commit

Permalink
support multiple months in reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
czue committed Jan 15, 2025
1 parent fb7383f commit 38abe27
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import datetime
import sentry_sdk
from logistics.models import Product
from logistics.reports import calc_percentage, format_percentage
from logistics_project.apps.malawi.warehouse import warehouse_view
from logistics_project.apps.malawi.warehouse.models import CalculatedConsumption
from logistics_project.utils.dates import months_between

CONDITION_DIARRHEA = "Diarrhea"
CONDITION_UNCOMPLICATED_MALARIA_YOUNG = "Uncomplicated Malaria (5 - 35 months)"
Expand Down Expand Up @@ -129,14 +131,13 @@ class View(warehouse_view.MalawiWarehouseView):
def custom_context(self, request):
# get consumption data
reporting_sp = self.get_reporting_supply_point(request)
month = request.datespan.enddate
main_table_headers = [
'Condition',
'Product',
'Products Dispensed',
'# Cases',
]
main_table_rows = self._get_main_table_rows(reporting_sp, month)
main_table_rows = self._get_main_table_rows(reporting_sp, request.datespan)
malaria_total_row = _get_total_malaria_row(main_table_rows)
pneumonia_total_row = _get_total_pneumonia_row(main_table_rows)
main_table_rows.insert(3, malaria_total_row)
Expand All @@ -161,7 +162,6 @@ def custom_context(self, request):
total_uncomplicated = uncomplicated_malaria_young_cases + uncomplicated_malaria_old_cases
total_malaria = total_uncomplicated + severe_malaria_cases
return {
"show_single_date": True,
"main_table": main_table,
'uncomplicated_malaria_breakdown_table': {
"is_datatable": False,
Expand All @@ -184,8 +184,20 @@ def custom_context(self, request):
}
}

def _get_main_table_rows(self, supply_point, month):
return [
_build_condition_row(condition, supply_point, month)
for condition in CONDITIONS
]
def _get_main_table_rows(self, supply_point, datespan):
rows = []
for condition in CONDITIONS:
row = None
for year, month in months_between(datespan.startdate, datespan.enddate):
month_datetime = datetime(year, month, 1)
current_row = _build_condition_row(condition, supply_point, month_datetime)
print(current_row)
if row is None:
row = current_row
else:
row[2] += current_row[2]
row[3] += current_row[3]

rows.append(row)

return rows

0 comments on commit 38abe27

Please sign in to comment.