浏览代码

Реализовано добавление статей по умполчанию при создании заказа. Форма создания заказа перенесена в таблицу

Anastasia 10 年之前
父节点
当前提交
b20ff6cb46
共有 7 个文件被更改,包括 60 次插入14 次删除
  1. 3 4
      asuzr/common.py
  2. 7 0
      asuzr/models.py
  3. 5 7
      asuzr/tables.py
  4. 1 1
      asuzr/views.py
  5. 1 0
      record/settings.py
  6. 2 2
      templates/asuzr/table2.html
  7. 41 0
      templates/asuzr/table_with_form.html

+ 3 - 4
asuzr/common.py

@@ -14,10 +14,9 @@ class custom_date(date):
  def weekday_color(self):
     return self.day_colors[self.weekday()]
   
- @property
- def date_dd_mm_yy(self):
-    return self.strftime('%d/%m/%Y')
-
  @property
  def is_weekend(self):
     return self.weekday() >= 5
+
+ def __format__(self):
+    return self.strftime('%d.%m.%Y')

+ 7 - 0
asuzr/models.py

@@ -108,6 +108,13 @@ class Order(models.Model):
     
     return need_color
   
+  def save(self, *args, **kwargs):
+    super(Order, self).save(*args, **kwargs)
+    cost_items = CostItem.objects.filter(default_item = True)
+    for ci in cost_items:
+      new_order_cost = OrderCosts(order = self, cost_item = ci, value = 0, formula = '')
+      new_order_cost.save()
+    
 #Эскизы
 class Sketch(models.Model):
   def get_sketch_path(self, file_name):

+ 5 - 7
asuzr/tables.py

@@ -67,8 +67,8 @@ class ThumbnailColumn(tables.TemplateColumn):
     super(ThumbnailColumn, self).__init__(template, *args, **kwargs)
 
 class OrdersTable(tables.Table):
-  date = tables.DateColumn('d/m/Y', verbose_name = 'Дата')
-  deadline = tables.DateColumn('d/m/Y', verbose_name = 'Срок сдачи')
+  date = tables.DateColumn('d.m.Y', verbose_name = 'Дата')
+  deadline = tables.DateColumn('d.m.Y', verbose_name = 'Срок сдачи')
   #product = tables.LinkColumn('asuzr.views.production_table', verbose_name = 'Наименование', args=[tables.utils.A('pk')]) 
   product = StaffLinkColumn(view = 'asuzr.views.production_table', verbose_name = 'Наименование') 
   delivery = EditableColumn('delivery', verbose_name = 'Доставка')
@@ -159,6 +159,7 @@ class VisitTable(tables.Table):
       idx = indexes[s]
       self.summary[idx] = summaries[s]
  
+
   def render_orders(self, value, record, column):
     value = 0 if value == None else value
     return mark_safe('<a href="%s?date=%s">%s</a>' % (
@@ -201,7 +202,7 @@ class DayOrdersTable(OrdersTable):
                 'designer', 
                 'deadline',
                )
-    template = 'asuzr/totals_table.html'
+    template = 'asuzr/table_with_form.html'
     
 class ProdPlanTable(tables.Table):
   date = tables.Column(verbose_name = 'Дата')
@@ -215,14 +216,11 @@ class ProdPlanTable(tables.Table):
     
 class ProductionTable(tables.Table):
   cost_item = tables.Column(verbose_name = 'Комплектующие')
-  value = tables.Column(verbose_name = 'Стоимость')
+  value = EditableColumn('value', verbose_name = 'Стоимость')
   
   summary = ['Итого затрат', 0]
   balance = ['Прибыль', 0]
   
-  def render_value(self, value):
-    return '%0.2f' % value
-  
   def set_summary(self, value):
     self.summary[1] = value
     

+ 1 - 1
asuzr/views.py

@@ -128,7 +128,7 @@ def visit_view(request):
                                                'additional_info': add_info,
                                                'title': title,
                                                'dateform': form,
-                                               'order_form': order_form
+                                               'model_form': order_form
                                                })
 
 @login_required 

+ 1 - 0
record/settings.py

@@ -107,3 +107,4 @@ from django.utils.safestring import mark_safe
 
 INPLACEEDIT_EDIT_EMPTY_VALUE = mark_safe(u'<div class="gray">Редактировать</div>')
 ADAPTOR_INPLACEEDIT_EDIT = 'inplaceeditform.perms.AdminDjangoPermEditInline'
+

+ 2 - 2
templates/asuzr/table2.html

@@ -3,8 +3,8 @@
 {% load render_table from django_tables2 %}
 
 {% block page %}
-  <div class="inline"><div><h3>{{ table1.verbose_name }}</h3></div>{% render_table table1 %}</div>
-  <div class="inline"><div><h3>{{ table2.verbose_name }}</h3></div>{% render_table table2 %}</div>
+  <div class="inline" style="width:38%;"><div><h3>{{ table1.verbose_name }}</h3></div>{% render_table table1 %}</div>
+  <div class="inline" style="width:20%;"><div><h3>{{ table2.verbose_name }}</h3></div>{% render_table table2 %}</div>
   {% if order_form %}
   <form action="{% url 'add-order' %}" method="POST" >
   {% csrf_token %}

+ 41 - 0
templates/asuzr/table_with_form.html

@@ -0,0 +1,41 @@
+{% extends "asuzr/totals_table.html" %}
+{% load django_tables2 %}
+{% load i18n %}
+{% block table.tbody %}
+    <tbody>
+        {% for row in table.page.object_list|default:table.rows %} {# support pagination #}
+        {% block table.tbody.row %}
+        <tr class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }}"> {# avoid cycle for Django 1.2-1.6 compatibility #}
+            {% for column, cell in row.items %}
+                <td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
+            {% endfor %}
+        </tr>
+        {% endblock table.tbody.row %}
+        {% empty %}
+        {% if table.empty_text %}
+        {% block table.tbody.empty_text %}
+        <tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
+        {% endblock table.tbody.empty_text %}
+        {% endif %}
+        {% endfor %}
+        {% if model_form %}
+        <form action="{% url 'add-order' %}" method="POST" >
+	  {% csrf_token %}
+	  <tr>
+	    <td>{{model_form.product}}</td>
+	    <td>{{model_form.price}}</td>
+	    <td>{{model_form.paid}}</td>
+	    <td>{{model_form.address}}</td>
+	    <td></td>
+	    <td>{{model_form.deadline}}</td>
+	    <td>{{model_form.delivery}}</td>
+	    <td>{{model_form.lifting}}</td>
+	  </tr>
+	  <tr>
+	    <td></td><td></td><td></td><td></td><td></td><td></td><td></td>
+	    <td><input type="submit" text="Добавить заказ"></td>
+	  </tr>
+	</form>
+        {% endif %}
+    </tbody>
+{% endblock table.tbody %}