fix: only carry-forward balances till today's period

Showing data in future doesn't make sense. Only carry-forward till last
bucket that contains today's day.
This commit is contained in:
Ankush Menat 2022-05-10 15:36:42 +05:30
parent 287b255ad6
commit 198b91f8d4

View File

@ -233,6 +233,8 @@ def get_data(filters):
periodic_data = get_periodic_data(sle, filters)
ranges = get_period_date_ranges(filters)
today = getdate()
for dummy, item_data in item_details.items():
row = {
"name": item_data.name,
@ -242,13 +244,13 @@ def get_data(filters):
"brand": item_data.brand,
}
previous_period_value = 0.0
for _start_date, end_date in ranges:
for start_date, end_date in ranges:
period = get_period(end_date, filters)
period_data = periodic_data.get(item_data.name, {}).get(period)
if period_data:
row[scrub(period)] = previous_period_value = sum(period_data.values())
else:
row[scrub(period)] = previous_period_value
row[scrub(period)] = previous_period_value if today >= start_date else None
data.append(row)