@@ -324,11 +324,6 @@ def get_report_data_api(request, poll_id):
324
324
# Fetch all Registers
325
325
register_query = Q (tenant , schedule__in = milk_delivered , log_date__gte = twelve_month_ago )
326
326
all_register_entry = Register .objects .filter (register_query )
327
- register_data = all_register_entry .annotate (
328
- total = (F ('current_price' ) * F ('quantity' ))
329
- ).values ('log_date__month' , 'log_date__year' , 'paid' ).annotate (
330
- monthly_total = Sum ('total' )
331
- )
332
327
333
328
for i in range (- 12 , 1 ):
334
329
percent += 3.75
@@ -345,23 +340,22 @@ def get_report_data_api(request, poll_id):
345
340
'log_date__year' ] == graph_month .year ), 0 )
346
341
347
342
# Retrieve Income for the current month
348
- month_income = next ((item ['income' ] for item in income_data if
349
- item ['log_date__month' ] == graph_month .month and item [
350
- 'log_date__year' ] == graph_month .year ), 0 )
343
+ month_extra_income = next ((item ['income' ] for item in income_data if
344
+ item ['log_date__month' ] == graph_month .month and item [
345
+ 'log_date__year' ] == graph_month .year ), 0 )
351
346
352
- month_register_sale = next ((item ['monthly_total' ] for item in register_data if
353
- item ['log_date__month' ] == graph_month .month and item [
354
- 'log_date__year' ] == graph_month .year and item [
355
- 'paid' ] in (0 , 1 )), 0 ) / 1000
347
+ month_register_sale = sum (
348
+ [entry .quantity * entry .current_price for entry in all_register_entry if
349
+ entry .log_date .month == graph_month .month and entry .log_date .year == graph_month .year ]) / 1000
356
350
357
- month_income += month_register_sale
351
+ month_register_sale += month_extra_income
358
352
359
- month_paid = next ((item ['monthly_total' ] for item in register_data if
360
- item ['log_date__month' ] == graph_month .month and item [
361
- 'log_date__year' ] == graph_month .year and item ['paid' ]),
362
- 0 ) / 1000
353
+ month_paid = sum (
354
+ [entry .quantity * entry .current_price for entry in all_register_entry if
355
+ entry .log_date .month == graph_month .month and entry .log_date .year == graph_month .year and entry .paid ]) / 1000
363
356
364
- month_due = month_income - month_paid
357
+ month_paid += month_extra_income
358
+ month_due = month_register_sale - month_paid
365
359
366
360
profit = float (
367
361
max (month_paid - month_expense , 0 )) if month_paid > month_expense else False
@@ -371,7 +365,7 @@ def get_report_data_api(request, poll_id):
371
365
current_month = {
372
366
"monthName" : month_str ,
373
367
"month" : month_abbr ,
374
- "income" : float (month_income ),
368
+ "income" : float (month_register_sale ),
375
369
"paid" : float (month_paid ),
376
370
"due" : float (month_due ),
377
371
"expense" : float (month_expense ),
0 commit comments