diff --git a/asuzr/forms.py b/asuzr/forms.py index 38f66d0..453fb25 100644 --- a/asuzr/forms.py +++ b/asuzr/forms.py @@ -71,7 +71,6 @@ class ProdTableForm(ModelForm): class ProdPlanForm(ModelForm): class Meta: model = ProdPlan - fields = ['start_date', 'order', 'executor','action'] + fields = ['executor','order' ,'action'] submit_text = "Добавить" - start_date = forms.DateField(widget = AdminDateWidget(format = '%d.%m.%Y')) diff --git a/asuzr/models.py b/asuzr/models.py index b5367ee..9ba6b34 100644 --- a/asuzr/models.py +++ b/asuzr/models.py @@ -146,9 +146,9 @@ class Action(models.Model): class ProdPlan(models.Model): start_date = models.DateField() #дата начала end_date = models.DateField() #дата окончания - order = models.ForeignKey(Order) #id заказа - executor = models.ForeignKey(User) #id исполнителя - action = models.ForeignKey(Action) #id действия + order = models.ForeignKey(Order, null=True, blank = True) #id заказа + executor = models.ForeignKey(User, null=True, blank = True) #id исполнителя + action = models.ForeignKey(Action, null=True, blank = True) #id действия def __unicode__(self): return ', '.join((str(self.start_date), self.order.product.name, self.action.name, self.executor.first_name)) diff --git a/asuzr/tables.py b/asuzr/tables.py index 8c0b2e0..9e25823 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -205,9 +205,7 @@ class DayOrdersTable(OrdersTable): template = 'asuzr/table_with_form.html' class ProdPlanTable(tables.Table): - date = tables.Column(verbose_name = 'Дата') - week_day = tables.Column(verbose_name = 'День недели', accessor = 'date.weekday_name') - executor = EditableColumn('executor', 'prodplan',verbose_name = 'Исполнитель') + executor = EditableColumn('executor', 'prodplan', verbose_name = 'Исполнитель') order = EditableColumn('order', 'prodplan', verbose_name = 'Заказ') action = EditableColumn('action', 'prodplan', verbose_name = 'Действие') diff --git a/asuzr/views.py b/asuzr/views.py index e11ac5d..214b811 100644 --- a/asuzr/views.py +++ b/asuzr/views.py @@ -133,75 +133,6 @@ def visit_view(request): 'form_action': 'add-order' }) -@login_required -def main(request, day, month, year): - if day == None: - day = str(date.today().day) - if month == None: - month = str(date.today().month) - if year == None: - year = str(date.today().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['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 = month_plan-sum_price - - d_date = p_date.strftime("%d/%m/%Y") - - t = loader.get_template('asuzr/attend_order.html') - c = RequestContext(request,{ - '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': month_plan, - 'balance': plan_balance, - 'd_date': d_date, - }) - return HttpResponse(t.render(c)) @log_view_call @login_required @@ -297,19 +228,29 @@ def prod_plan_view(request): week_days = {i.weekday(): {'date': custom_date(i.year,i.month,i.day)} for i in days} prodplan_list = ProdPlan.objects.filter(start_date__range = (sdate,edate)) - for prodplan in prodplan_list: - week_days[prodplan.start_date.weekday()]['prodplan'] = prodplan + tables = [] + for week_day in week_days: + tdate = week_days[week_day]['date'] + prodplan_list = ProdPlan.objects.filter(start_date = tdate) + tables.append(ProdPlanTable(prodplan_list)) + tables[week_day].verbose_name = ', '.join((tdate.strftime('%d.%m.%Y'), tdate.weekday_name)) - table = ProdPlanTable(week_days.values()) title = u'Производственный план на %s - %s' % (sdate.strftime('%d.%m.%Y'), edate.strftime('%d.%m.%Y')) date_form = DateForm({'date':curr_date}) add_form = ProdPlanForm() - RequestConfig(request).configure(table) - return render(request, 'asuzr/table.html', {'table': table, 'title': title, 'dateform': date_form, 'add_form': add_form, 'form_action' : 'add-plan-item'}) + for table in tables: + RequestConfig(request).configure(table) + return render(request, 'asuzr/table_n.html', {'tables': tables, 'title': title, 'dateform': date_form, 'add_form': add_form, 'form_action' : 'add-plan-item'}) def prod_plan_add_item(request): return redirect(prod_plan_view) +def create_plan_item_if_need(date): + plan_item, created = ProdPlan.objects.get_or_create(start_date = date, + defaults={'end_date': date}) + if created: + plan_item.save() + @login_required def log_view(request): log = LogEntry.objects.all() diff --git a/record/urls.py b/record/urls.py index a6b01d2..66b508d 100644 --- a/record/urls.py +++ b/record/urls.py @@ -14,7 +14,6 @@ js_info_dict = { urlpatterns = patterns('', url(r'^product/$', 'asuzr.views.prod_list'), url(r'^product/(?P\d+)/$', 'asuzr.views.prod_detail'), - url(r'^main/?(?P\d+)?/?(?P\d+)?/?(?P\d+)?/$', 'asuzr.views.main', name='asuzr-main'), url(r'^visits/$', 'asuzr.views.visit_view'), url(r'^order/add/$', 'asuzr.views.add_order', name = 'add-order'), url(r'^orders/(?P\d+)/$', 'asuzr.views.orders',name='asuzr-orders'), diff --git a/templates/asuzr/table_n.html b/templates/asuzr/table_n.html new file mode 100644 index 0000000..9ae882f --- /dev/null +++ b/templates/asuzr/table_n.html @@ -0,0 +1,10 @@ +{% extends "asuzr/base.html" %} +{% load inplace_edit %} +{% load render_table from django_tables2 %} + +{% block page %} + {%for table in tables %} +

{{ table.verbose_name }}

{% render_table table %}
+ {% endfor %} +{% endblock %} +