#1 Fix calculation daily sum
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
from datetime import datetime, timedelta
 | 
					from datetime import datetime, timedelta, date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django import template
 | 
					from django import template
 | 
				
			||||||
from django.db.models import Sum
 | 
					from django.db.models import Sum
 | 
				
			||||||
@@ -10,8 +10,14 @@ register = template.Library()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@register.filter(is_safe=True)
 | 
					@register.filter(is_safe=True)
 | 
				
			||||||
def display_daily_sale(location):
 | 
					def display_daily_sale(location):
 | 
				
			||||||
    start_date = datetime.now().replace(hour=5, minute=0, second=0, microsecond=0)
 | 
					    date = datetime.now().replace(hour=6, minute=0, second=0, microsecond=0)
 | 
				
			||||||
    end_date = start_date + timedelta(days=1)
 | 
					    now = datetime.now()
 | 
				
			||||||
 | 
					    if now < date:
 | 
				
			||||||
 | 
					        start_date = date - timedelta(days=1)
 | 
				
			||||||
 | 
					        end_date = date
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        start_date = date
 | 
				
			||||||
 | 
					        end_date = date + timedelta(days=1)
 | 
				
			||||||
    prize__sum = Accounting.objects.filter(desk__client__location=location,
 | 
					    prize__sum = Accounting.objects.filter(desk__client__location=location,
 | 
				
			||||||
                                           time_to__range=(start_date, end_date)).aggregate(Sum('prize'))
 | 
					                                           time_to__range=(start_date, end_date)).aggregate(Sum('prize'))
 | 
				
			||||||
    if prize__sum['prize__sum'] is None:
 | 
					    if prize__sum['prize__sum'] is None:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user