Внесены изменения в модель. Добавлено расписание. Реализован вывод информации о заказах н/з от посещаемости. Реализовано отображение всех дней месяца
This commit is contained in:
@@ -5,10 +5,11 @@ from asuzr.models import Product
|
||||
from asuzr.models import Attendance
|
||||
from asuzr.models import Order
|
||||
from asuzr.models import OrderPlan
|
||||
from datetime import datetime, date
|
||||
from asuzr.models import Schedule
|
||||
from datetime import datetime, date, timedelta
|
||||
import calendar
|
||||
from django.db.models import Count, Sum
|
||||
|
||||
# Create your views here.
|
||||
from asuzr.common import custom_date
|
||||
|
||||
def prod_list(request):
|
||||
product_list = Product.objects.all()
|
||||
@@ -37,35 +38,62 @@ def get_orders_by_date(dt):
|
||||
|
||||
|
||||
def main(request, day, month, year):
|
||||
d,m,y=int(day),int(month), int(year)
|
||||
|
||||
attend_list = Attendance.objects.all().order_by('date')
|
||||
filtered_attend_list=get_filtered_list(attend_list, year, month)
|
||||
|
||||
p_date = datetime.strptime(day+'/'+month+'/'+year, '%d/%m/%Y')
|
||||
order_list = Order.objects.filter(date=p_date).order_by('id')
|
||||
month_order_list=Order.objects.filter(date__range=(date(y,m,1),date(y,m,calendar.monthrange(y,m)[1]))).values('date').annotate(Count('product'),Sum('price'))
|
||||
|
||||
plan = OrderPlan.objects.all()
|
||||
filtered_plan = get_filtered_list(plan, year, month)
|
||||
month_plan=0
|
||||
if len(filtered_plan) > 0:
|
||||
month_plan=filtered_plan[0].plan
|
||||
|
||||
schedule = Schedule.objects.all().order_by('date')
|
||||
filtered_schedule = get_filtered_list(schedule, year, month)
|
||||
|
||||
month_days={i: {'date': custom_date(int(year),int(month),i)} for i in range(1,calendar.monthrange(int(year),int(month))[1]+1)}
|
||||
|
||||
for l in filtered_attend_list:
|
||||
month_days[l.date.day]['attend']=l
|
||||
|
||||
for s in filtered_schedule:
|
||||
if 'designers' in month_days[s.date.day]:
|
||||
des=', '.join((month_days[s.date.day]['designers'], ' '.join((s.designer.first_name, s.designer.last_name))))
|
||||
month_days[s.date.day]['designers'] = des
|
||||
else:
|
||||
month_days[s.date.day]['designers'] = ' '.join((s.designer.first_name, s.designer.last_name))
|
||||
|
||||
for order in month_order_list:
|
||||
month_days[order['date'].day]['orders_count'] = order['product__count']
|
||||
month_days[order['date'].day]['orders_price'] = order['price__sum']
|
||||
|
||||
month_days_values = month_days.values()
|
||||
|
||||
sum_calls = sum(l.calls for l in filtered_attend_list)
|
||||
sum_visits = sum(l.visits for l in filtered_attend_list)
|
||||
sum_orders = sum(l.order_count for l in filtered_attend_list)
|
||||
sum_price = sum(l.orders_price for l in filtered_attend_list)
|
||||
sum_orders = sum(l['orders_count'] for l in month_days_values if 'orders_count' in l)
|
||||
sum_price = sum(l['orders_price'] for l in month_days_values if 'orders_price' in l)
|
||||
|
||||
sum_order_price = sum(l.price for l in order_list)
|
||||
plan_balance = filtered_plan[0].plan-sum_price
|
||||
plan_balance = month_plan-sum_price
|
||||
|
||||
d_date = p_date.strftime("%d/%m/%Y")
|
||||
|
||||
t = loader.get_template('asuzr/attend_order.html')
|
||||
c = Context({
|
||||
'attend_list': filtered_attend_list,
|
||||
'attend_list': month_days_values,
|
||||
'order_list': order_list,
|
||||
'sum_calls': sum_calls,
|
||||
'sum_visits': sum_visits,
|
||||
'sum_orders': sum_orders,
|
||||
'sum_price': sum_price,
|
||||
'sum_order_price': sum_order_price,
|
||||
'plan': filtered_plan[0],
|
||||
'plan': month_plan,
|
||||
'balance': plan_balance,
|
||||
'd_date': d_date,
|
||||
})
|
||||
@@ -90,7 +118,7 @@ def desreport(request):
|
||||
sdate = datetime.strptime(start_date, '%d.%m.%y')
|
||||
end_date = request.GET.get('edate', date.today().strftime('%d.%m.%y'))
|
||||
edate = datetime.strptime(end_date, '%d.%m.%y')
|
||||
des_list = Order.objects.filter(cancelled=False, date__range=(sdate,edate)).values('designer__first_name').annotate(Sum('price'),Count('designer'))
|
||||
des_list = Order.objects.filter(cancelled=False, date__range=(sdate,edate)).values('designer__first_name','designer__last_name').annotate(Sum('price'),Count('designer'))
|
||||
t=loader.get_template('asuzr/desreport.html')
|
||||
c=Context({
|
||||
'des_list' : des_list,
|
||||
@@ -99,6 +127,7 @@ def desreport(request):
|
||||
})
|
||||
return HttpResponse(t.render(c))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user