diff --git a/.gitignore b/.gitignore index 2ee6455..093c5a1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ yandex_money.log /src/dokumentor/media/ /tmp/ /conf/env +!parts diff --git a/diff_static.sh b/bin/diff_static.sh old mode 100755 new mode 100644 similarity index 100% rename from diff_static.sh rename to bin/diff_static.sh diff --git a/src/docs/forms/invoice.py b/src/docs/forms/invoice.py index 2e24088..bf3dac9 100644 --- a/src/docs/forms/invoice.py +++ b/src/docs/forms/invoice.py @@ -9,13 +9,14 @@ from docs.models import Invoice, InvoiceItem class InvoiceForm(BaseModelForm): """Форма редактирования счета.""" + class Meta: model = Invoice fields = ('doc_num', 'doc_date', - 'bank_account', 'client', - 'nds_value', - 'doc_text', - ) + 'bank_account', 'client', + 'nds_value', + 'doc_text', + ) _radioselect = forms.RadioSelect _textarea = forms.Textarea(attrs={'cols': 80, 'rows': 3}) widgets = { @@ -25,6 +26,7 @@ class InvoiceForm(BaseModelForm): class InvoiceAdminForm(InvoiceForm): """Форма редактирования счета - для админки.""" + class Meta(InvoiceForm.Meta): # fields = None exclude = () @@ -49,13 +51,16 @@ class InvoicesListForm(forms.Form): class InvoiceItemForm(MyBaseModelForm): """Форма редактирования табличной части счета.""" + class Meta: model = InvoiceItem - exclude = ['parent'] - fields = '__all__' + # exclude = ('parent',) + # fields = ('name', 'qty', 'units', 'price', 'total_price', 'id',) + fields = ('id', 'name', 'qty', 'units', 'price', 'total_price',) class InvoiceItemAdminForm(InvoiceItemForm): """Форма редактирования табличной части счета - для админки.""" + class Meta(InvoiceItemForm.Meta): exclude = None diff --git a/src/docs/views/base_views.py b/src/docs/views/base_views.py index cab30fc..b829199 100644 --- a/src/docs/views/base_views.py +++ b/src/docs/views/base_views.py @@ -8,6 +8,8 @@ from time import time import simplejson as json import ghostscript +from django.contrib import messages +from django.db import DatabaseError from django.shortcuts import render, get_object_or_404, redirect from django.http import HttpResponseServerError, HttpResponseBadRequest, HttpResponse @@ -632,7 +634,7 @@ class BaseItemsViews(BaseViews): @method_decorator(license_required) @method_decorator(csrf_protect) - def add(self, *args, **kwargs): + def add(self, *args, initial_items=None, initial=None, **kwargs): """Добавить документ. Если при GET-запросе в kwargs передать initial и/или initial_items, то создаст предзаполненный документ. """ @@ -656,16 +658,22 @@ class BaseItemsViews(BaseViews): new_obj.user = self.request.user new_obj.company = self.request.user.profile new_obj.save() - # сохранить табличную часть + if formset.is_valid(): - new_items = formset.save(commit=False) - for item in new_items: - item.parent = new_obj - item.save() + try: + if not formset.instance.pk: + formset.instance = new_obj + new_items = formset.save(commit=False) + for item in new_items: + item.parent = new_obj + item.save() + messages.success(self.request, "Документ успешно сохранен") + except DatabaseError: + messages.error(self.request, "Ошибка базы данных. Пожалуйста, попробуйте снова") return redirect(self.REDIRECT_AFTER_ADD) else: - initial = kwargs.get('initial') or self.init_form() - initial_items = kwargs.get('initial_items') + initial = initial or self.init_form() + initial_items = initial_items form = self.FORM_CLASS(self.request.user, initial=initial) formset = self.ITEM_FORMSET_CLASS(prefix=self.ITEM_FORM_PREFIX, initial=initial_items) diff --git a/src/dokumentor/templates/docs/parts/doc_actions.html b/src/dokumentor/templates/docs/parts/doc_actions.html new file mode 100644 index 0000000..2c3bca7 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/doc_actions.html @@ -0,0 +1,17 @@ +{% url url_prefix|add:'img' id=obj.pk as url_img %} +{% url url_prefix|add:'pdf' id=obj.pk as url_pdf %} +{% url url_prefix|add:'xls' id=obj.pk as url_xls %} + +
Скачать документ
+ +{% if not images %} + Предпросмотр {{ padeji.rodit }} +{% endif %} + +
+ +Документ в PDF + + Документ в Excel + +
diff --git a/src/dokumentor/templates/docs/parts/doc_actions2nd.html b/src/dokumentor/templates/docs/parts/doc_actions2nd.html new file mode 100644 index 0000000..7fb90e0 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/doc_actions2nd.html @@ -0,0 +1,13 @@ +{% url url_prefix|add:'edit' id=obj.pk as url_edit %} +{% url url_prefix|add:'delete' id=obj.pk as url_delete %} +{% url url_prefix|add:'email' id=obj.pk as url_email %} + +
Действия с документом
+ +Отправить по e-mail + +Редактировать документ + +Удалить документ + +
diff --git a/src/dokumentor/templates/docs/parts/form_buttons.html b/src/dokumentor/templates/docs/parts/form_buttons.html new file mode 100644 index 0000000..53f3f0f --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_buttons.html @@ -0,0 +1,9 @@ +
+ {% if not is_ajax %} + + + {% else %} + + + {% endif %} +
diff --git a/src/dokumentor/templates/docs/parts/form_client_choices.html b/src/dokumentor/templates/docs/parts/form_client_choices.html new file mode 100644 index 0000000..cc38c33 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_client_choices.html @@ -0,0 +1,4 @@ +

{{ label }}

+ {{ label1|default:'Он же' }} +{{ label2|default:'Стороннее лицо' }} + Не указывать diff --git a/src/dokumentor/templates/docs/parts/form_field.html b/src/dokumentor/templates/docs/parts/form_field.html new file mode 100644 index 0000000..3b4f011 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_field.html @@ -0,0 +1,23 @@ +{% comment %} +field - поле +id - id поля +classes - css классы +required - отметить, что поле обязательное? +label - заголовок поля +label_inline - вывести заголовок и поле на одной строке? +help - подсказка по заполнению поля +is_ajax - ajax-форма? +no_clear_after - не добавлять очистку float после блока +{% endcomment %} + + + {% if label %}{{ label }}:{% if required %} *{% endif %}{% endif %} + {% if label_inline %} + {{ field }} + {% else %} +

{{ field }}

+ {% endif %} + {% if help %}

{{ help }}

{% endif %} + {% if not is_ajax %}{{ field.errors }}{% endif %} + +{% if not no_clear_after %}
{% endif %} diff --git a/src/dokumentor/templates/docs/parts/form_field_client.html b/src/dokumentor/templates/docs/parts/form_field_client.html new file mode 100644 index 0000000..9112f18 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_field_client.html @@ -0,0 +1,22 @@ +{% comment %} +field - поле +required - отметить, что поле обязательное? +label - заголовок поля (по умолчанию, `Контрагент`) +is_ajax - ajax-форма? +no_clear_after - не добавлять очистку float после блока +{% endcomment %} + + +
+ {{ label|default:"Контрагент" }}:{% if required %} *{% endif %} +

+ {{ field }} + + Добавить контрагента + +

+ + {{ form.client.errors }} + {% if not is_ajax %}{{ form.client.errors }}{% endif %} +
+{% if not no_clear_after %}
{% endif %} diff --git a/src/dokumentor/templates/docs/parts/form_field_receiver.html b/src/dokumentor/templates/docs/parts/form_field_receiver.html new file mode 100644 index 0000000..6d12ed8 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_field_receiver.html @@ -0,0 +1,3 @@ +{% include 'docs/parts/form_client_choices.html' with client_group="receiver_group" id="receiver_choices" classes="field" label="Получатель" default=receiver_choice %} + +{% include 'docs/parts/form_field_client.html' with field=form.receiver id="receiver" classes="field" label="Получатель" %} diff --git a/src/dokumentor/templates/docs/parts/form_field_sender.html b/src/dokumentor/templates/docs/parts/form_field_sender.html new file mode 100644 index 0000000..8a59b8a --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_field_sender.html @@ -0,0 +1,2 @@ +{% include 'docs/parts/form_client_choices.html' with client_group="sender_group" id="sender_choices" classes="field" label="Отправитель" label1='Подставить мои данные' default=sender_choice %} +{% include 'docs/parts/form_field_client.html' with field=form.sender id="sender" classes="field" label="Отправитель" %} diff --git a/src/dokumentor/templates/docs/parts/form_tbl_items.html b/src/dokumentor/templates/docs/parts/form_tbl_items.html new file mode 100644 index 0000000..fc043dd --- /dev/null +++ b/src/dokumentor/templates/docs/parts/form_tbl_items.html @@ -0,0 +1,53 @@ +{# табличная часть документа #} + + + + + + + + + + + + {% for iform in formset %} + + {% for field in iform %} + {% if field.name == "id" or field.name == "parent" %} + {{ field }} + {% else %} + {% if field.name != "DELETE" %} + + {% endif %} + {% endif %} + {% endfor %} + + + {% endfor %} + + + + + + + + + {% comment %} + + + + + + + {% endcomment %} +
Наименование:Количество:Ед. изм.:Цена:Сумма:
+ {{ field.errors }} + {{ field }} + + {% if iform.instance.pk %}{{ iform.DELETE }}{% endif %} +
+ Итого
Без НДС
+ +{{ formset.management_form }} + +
diff --git a/src/dokumentor/templates/docs/parts/invoice_create_docs.html b/src/dokumentor/templates/docs/parts/invoice_create_docs.html new file mode 100644 index 0000000..02af408 --- /dev/null +++ b/src/dokumentor/templates/docs/parts/invoice_create_docs.html @@ -0,0 +1,9 @@ +{% url 'docs_aktrabot_add_by_invoice' invoice_id=obj.pk as url_aktrabot_by_invoice %} +{% url 'docs_nakladn_add_by_invoice' invoice_id=obj.pk as url_nakladn_by_invoice %} +{% url 'docs_faktura_add_by_invoice' invoice_id=obj.pk as url_faktura_by_invoice %} + +Акт выполненных работ + +Накладную + +Счёт-фактуру diff --git a/src/dokumentor/templates/docs/parts/linked_docs_list.html b/src/dokumentor/templates/docs/parts/linked_docs_list.html new file mode 100644 index 0000000..9e6b08c --- /dev/null +++ b/src/dokumentor/templates/docs/parts/linked_docs_list.html @@ -0,0 +1,21 @@ +{% if obj.linked_docs %} + +
Связанные документы
+ +{% for invoice in obj.linked_docs.Invoice %} + {{ invoice }} +{% endfor %} + +{% for akt in obj.linked_docs.AktRabot %} + {{ akt }} +{% endfor %} + +{% for nakladn in obj.linked_docs.Nakladn %} + {{ nakladn }} +{% endfor %} + +{% for faktura in obj.linked_docs.Faktura %} + {{ faktura }} +{% endfor %} + +{% endif %}