Добавлена Производственная таблица. Переход на таблицу по ссылке из Таблицы выхода заказов

This commit is contained in:
Anastasia
2015-07-10 10:11:12 +05:00
parent f55377c5bf
commit 057aea69e5
4 changed files with 41 additions and 11 deletions

View File

@@ -57,7 +57,7 @@ class ThumbnailColumn(tables.TemplateColumn):
class OrdersTable(tables.Table): class OrdersTable(tables.Table):
date = tables.DateColumn('d/m/Y', verbose_name = 'Дата') date = tables.DateColumn('d/m/Y', verbose_name = 'Дата')
deadline = tables.DateColumn('d/m/Y', verbose_name = 'Срок сдачи') deadline = tables.DateColumn('d/m/Y', verbose_name = 'Срок сдачи')
product = tables.Column(verbose_name = 'Наименование') product = tables.LinkColumn('asuzr.views.production_table', verbose_name = 'Наименование', args=[tables.utils.A('pk')])
delivery = EditableColumn('delivery', verbose_name = 'Доставка') delivery = EditableColumn('delivery', verbose_name = 'Доставка')
lifting = EditableColumn('lifting', verbose_name = 'Подъем') lifting = EditableColumn('lifting', verbose_name = 'Подъем')
address = tables.Column(verbose_name = 'Адрес') address = tables.Column(verbose_name = 'Адрес')
@@ -200,3 +200,23 @@ class ProdPlanTable(tables.Table):
class Meta: class Meta:
attrs = {'class': 'paleblue'} attrs = {'class': 'paleblue'}
class ProductionTable(tables.Table):
cost_item = tables.Column(verbose_name = 'Комплектующие')
value = tables.Column(verbose_name = 'Стоимость')
summary = ['Итого затрат', 0]
balance = ['Прибыль', 0]
def render_value(self, value):
return '%0.2f' % value
def set_summary(self, value):
self.summary[1] = value
def set_balance(self, value):
self.balance[1] = value
class Meta:
attrs = {'class': 'paleblue'}
template = 'asuzr/totals_table.html'

View File

@@ -238,16 +238,17 @@ def desreport(request):
@login_required @login_required
def production_table(request, order_id): def production_table(request, order_id):
order_list = Order.objects.filter(is_done=False).order_by('-id') order_costs = OrderCosts.objects.filter(order=order_id)
sel_order = Order.objects.filter(id=order_id) table = ProductionTable(order_costs)
cost_items = sel_order.values('cost_items') curr_order = Order.objects.get(pk = order_id)
t=loader.get_template('asuzr/order_costs.html') title = u'Производственная таблица'
c=RequestContext(request,{ table.verbose_name = u'Заказ: %s' % (', '.join((curr_order.product.name, curr_order.address)))
'order_list' : order_list, table.verbose_name2 = u'Стоимость: %s' % str(curr_order.price)
'sel_order' : sel_order, costs_sum = order_costs.aggregate(Sum('value'))
'cost_items' : cost_items, table.set_summary(costs_sum['value__sum'] or 0)
}) table.set_balance(curr_order.price - costs_sum['value__sum'] or 0)
return HttpResponse(t.render(c)) RequestConfig(request).configure(table)
return render(request, 'asuzr/table.html', {'table': table, 'title': title})
@login_required @login_required
def prod_plan_view(request): def prod_plan_view(request):

View File

@@ -3,6 +3,8 @@
{% load render_table from django_tables2 %} {% load render_table from django_tables2 %}
{% block page %} {% block page %}
<h3>{{ table.verbose_name }}</h3>
<h3>{{ table.verbose_name2 }}</h3>
{% block table %} {% block table %}
{% render_table table %} {% render_table table %}
{% endblock %} {% endblock %}

View File

@@ -10,6 +10,13 @@
{% endfor %} {% endfor %}
</tr> </tr>
{% endif %} {% endif %}
{% if table.balance %}
<tr>
{% for balance in table.balance %}
<td> {{ balance }} </td>
{% endfor %}
</tr>
{% endif %}
</tfoot> </tfoot>
{% endblock table.tfoot %} {% endblock table.tfoot %}