From 217fec134be4659d2084c8d851477775d8ff2ffb Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Mon, 19 Jun 2017 12:49:20 +0300 Subject: [PATCH] meckup factura --- requirements/base.txt | 1 + src/docs/forms/aktrabot.py | 4 +- src/docs/forms/base_forms.py | 29 ++++++++---- src/docs/forms/faktura.py | 29 +++++++----- src/docs/models/faktura.py | 43 ++++++++++++++---- src/docs/views/base_views.py | 3 +- src/dokumentor/static/css/style.css | 28 ++++++++++++ src/dokumentor/static/js/formset-events.js | 1 - .../templates/docs/faktura/form.html | 45 +++++++++---------- .../docs/parts/form_client_choices.html | 8 ++-- .../docs/parts/form_field_client.html | 4 +- .../docs/parts/form_field_receiver.html | 5 +-- .../docs/parts/form_field_sender.html | 4 +- src/dokumentor/templates/docs/stub_js.html | 7 ++- tox.ini | 4 ++ 15 files changed, 147 insertions(+), 68 deletions(-) create mode 100755 tox.ini diff --git a/requirements/base.txt b/requirements/base.txt index be233bc..7774738 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -71,3 +71,4 @@ django-redis==4.8.0 redis==2.10.5 trans==2.1.0 python-decouple==3.0 +flake8==3.2.1 diff --git a/src/docs/forms/aktrabot.py b/src/docs/forms/aktrabot.py index a36eb29..c89d57d 100644 --- a/src/docs/forms/aktrabot.py +++ b/src/docs/forms/aktrabot.py @@ -31,7 +31,6 @@ class AktRabotForm(BaseModelForm): class AktRabotAdminForm(AktRabotForm): """Форма редактирования акта выполн. работ - для админки.""" class Meta(AktRabotForm.Meta): - # fields = None exclude = () _textarea = forms.Textarea(attrs={'cols': 80, 'rows': 3}) widgets = { @@ -39,7 +38,8 @@ class AktRabotAdminForm(AktRabotForm): } def __init__(self, *args, **kwargs): - # обязательно нужно вызывать родительский __init__ и передавать ему None вместо user - иначе глюки ! + # обязательно нужно вызывать родительский __init__ + # и передавать ему None вместо user - иначе глюки ! super(AktRabotAdminForm, self).__init__(None, *args, **kwargs) diff --git a/src/docs/forms/base_forms.py b/src/docs/forms/base_forms.py index 776172d..e3d308c 100644 --- a/src/docs/forms/base_forms.py +++ b/src/docs/forms/base_forms.py @@ -14,18 +14,25 @@ class BaseModelForm(MyBaseModelForm): Добавляет к методу __init__ обязательный атрибут user. """ - # Список полей, у которых нужно настроить выборку контрагентов так, чтобы попадали __только__ контрагенты данного - # пользователя. Если же пользователь никак не был задан - селекты будут пустыми! Если в форме есть поле client, + # Список полей, у которых нужно настроить выборку контрагентов + # так, чтобы попадали __только__ контрагенты данного + # пользователя. Если же пользователь никак не был задан - селекты + # будут пустыми! Если в форме есть поле client, # то оно настраивается автоматически. - client = ModelChoiceField(Client.objects.all(), label=u'клиент', required=True, - widget=autocomplete_light.ChoiceWidget('ACClient')) + client = ModelChoiceField( + Client.objects.all(), + label='клиент', + required=True, + widget=autocomplete_light.ChoiceWidget('ACClient') + ) adjust_client_fields = [] def __init__(self, user, *args, **kwargs): super(BaseModelForm, self).__init__(*args, **kwargs) self._user = user - # Если передали user=None, то попробовать взять user из kwargs['instance'], а потом из self.data + # Если передали user=None, то попробовать взять + # user из kwargs['instance'], а потом из self.data if not self._user: try: self._user = getattr(kwargs.get('instance'), 'user') @@ -43,14 +50,17 @@ class BaseModelForm(MyBaseModelForm): if f.get('fix_doc_date'): f['fix_doc_date'].widget.attrs['class'] = 'has-datepicker' - # Если в форме есть поле bank_account, настроить связь с BankAccount: чтобы можно было выбрать __только__ - # расчетные счета данного пользователя. Также убрать пустой вариант из селекта. + # Если в форме есть поле bank_account, настроить связь + # с BankAccount: чтобы можно было выбрать __только__ + # расчетные счета данного пользователя. Также убрать + # пустой вариант из селекта. if 'bank_account' in f: user_accounts = BankAccount.objects.get_all(self._user.profile) f['bank_account'].queryset = user_accounts f['bank_account'].empty_label = None - # Если в форме есть поле client, настроить связь с Client: чтобы можно было выбрать __только__ + # Если в форме есть поле client, настроить связь с Client: чтобы + # можно было выбрать __только__ # контрагентов данного пользователя. if 'invoice' in f: user_invoices = Invoice.objects.filter(company=self._company) @@ -60,6 +70,9 @@ class BaseModelForm(MyBaseModelForm): user_clients = Client.objects.filter(company=self._company) f['client'].queryset = user_clients + if 'currency' in f: + f['currency'].initial = 3 + # Настроить связь других полей с контрагентами. self._adjust_clients() diff --git a/src/docs/forms/faktura.py b/src/docs/forms/faktura.py index 43be389..fc3a8ce 100644 --- a/src/docs/forms/faktura.py +++ b/src/docs/forms/faktura.py @@ -11,19 +11,26 @@ from customer.models import Client class FakturaForm(BaseModelForm): """Форма редактирования фактуры.""" - sender = forms.ModelChoiceField(Client.objects.all(), label=u'клиент', required=False, - widget=autocomplete_light.ChoiceWidget('ACClient')) - receiver = forms.ModelChoiceField(Client.objects.all(), label=u'клиент', required=False, - widget=autocomplete_light.ChoiceWidget('ACClient')) + sender = forms.ModelChoiceField( + Client.objects.all(), + label='клиент', + required=False, + widget=autocomplete_light.ChoiceWidget('ACClient') + ) + receiver = forms.ModelChoiceField( + Client.objects.all(), + label='клиент', + required=False, + widget=autocomplete_light.ChoiceWidget('ACClient') + ) adjust_client_fields = [] + class Meta: model = Faktura fields = ( 'doc_num', 'doc_date', - 'plat_doc_num', - 'plat_doc_date', 'fix_doc_num', 'fix_doc_date', 'client', @@ -42,7 +49,6 @@ class FakturaForm(BaseModelForm): _textarea = forms.Textarea(attrs={'cols': 80, 'rows': 3}) widgets = { 'doc_text': _textarea, - 'currency': autocomplete_light.ChoiceWidget('ACCurrency'), 'nds_method': forms.RadioSelect() } @@ -58,13 +64,17 @@ class FakturaAdminForm(FakturaForm): } def __init__(self, *args, **kwargs): - # обязательно нужно вызывать родительский __init__ и передавать ему None вместо user - иначе глюки ! + # обязательно нужно вызывать родительский __init__ + # и передавать ему None вместо user - иначе глюки ! super(FakturaAdminForm, self).__init__(None, *args, **kwargs) class FakturaItemForm(MyBaseModelForm): """Форма редактирования табличной части фактуры.""" - country_name = forms.CharField(widget=autocomplete_light.TextWidget('ACCountry'),) + country_name = forms.CharField( + widget=autocomplete_light.TextWidget('ACCountry') + ) + class Meta: model = FakturaItem exclude = ['parent'] @@ -75,4 +85,3 @@ class FakturaItemAdminForm(FakturaItemForm): """Форма редактирования табличной части фактуры - для админки.""" class Meta(FakturaItemForm.Meta): exclude = None - diff --git a/src/docs/models/faktura.py b/src/docs/models/faktura.py index c8fdb5e..93649a1 100644 --- a/src/docs/models/faktura.py +++ b/src/docs/models/faktura.py @@ -3,7 +3,7 @@ from django.db import models from customer.models import Client from docs.models.base_models import BaseInvoiceModel, BaseItemInvoiceModel -from docs.models.refs import Currency, Country, Measure +from docs.models.refs import Currency from docs.models.mixins import SignedStatusFieldMixin, InvoiceFieldMixin from docs.models.linked_docs_mixin import LinkedDocsMixin @@ -15,9 +15,26 @@ class Faktura(BaseInvoiceModel, SignedStatusFieldMixin, InvoiceFieldMixin, Linke avance = models.BooleanField(u'аванс', default=False) currency = models.ForeignKey(Currency, verbose_name=u'валюта', null=True) user_is_sender = models.BooleanField(u'пользователь - отправитель', default=False) - sender = models.ForeignKey(Client, related_name='sender_fakturas', blank=True, null=True, verbose_name=u'Отправитель') - receiver = models.ForeignKey(Client, related_name='receiver_fakturas', blank=True, null=True, verbose_name=u'Получатель') - plat_doc_num = models.CharField(u'Номер платёжного документа', max_length=30, blank=True, default='') + sender = models.ForeignKey( + Client, + related_name='sender_fakturas', + blank=True, + null=True, + verbose_name=u'Отправитель' + ) + receiver = models.ForeignKey( + Client, + related_name='receiver_fakturas', + blank=True, + null=True, + verbose_name=u'Получатель' + ) + plat_doc_num = models.CharField( + 'Номер платёжного документа', + max_length=30, + blank=True, + default='' + ) plat_doc_date = models.DateField('Дата платёжного документа', blank=True, null=True) fix_doc_num = models.PositiveIntegerField(u'Номер исправления', null=True, blank=True) fix_doc_date = models.DateField('Дата исправления', blank=True, null=True) @@ -37,7 +54,6 @@ class Faktura(BaseInvoiceModel, SignedStatusFieldMixin, InvoiceFieldMixin, Linke """Получатель и адрес """ if self.receiver: - #return self.user return '%s, %s' % (self.receiver.name, self.receiver.address) else: return u'' @@ -50,15 +66,24 @@ class Faktura(BaseInvoiceModel, SignedStatusFieldMixin, InvoiceFieldMixin, Linke class FakturaItem(BaseItemInvoiceModel): """Табличная часть фактуры""" - units_kod = models.CharField(u'Код единицы измерения', max_length=10, blank=True, default=u'-') + units_kod = models.CharField( + 'Код единицы измерения', + max_length=10, + blank=True, + default=u'-' + ) parent = models.ForeignKey(Faktura, related_name='faktura_items') country_code = models.CharField(u'Код страны', max_length=10, blank=True, default=u'-') country_name = models.CharField(u'Название страны', max_length=256) gtd = models.CharField(u'Основание', max_length=256, blank=True, default='') - ntd = models.CharField(u'Номер транспортной декларации', max_length=256, blank=True, default='') - #measure = models.ForeignKey(Measure, related_name='m_faktura_items') + ntd = models.CharField( + u'Номер транспортной декларации', + max_length=256, + blank=True, + default='' + ) class Meta(BaseItemInvoiceModel.Meta): verbose_name = u'Табл. часть фактуры' verbose_name_plural = u'Табл. части фактур' - app_label="docs" + app_label = "docs" diff --git a/src/docs/views/base_views.py b/src/docs/views/base_views.py index 42e2590..44fe175 100644 --- a/src/docs/views/base_views.py +++ b/src/docs/views/base_views.py @@ -804,7 +804,8 @@ class BaseItemsViews(BaseViews): new_obj.receiver = new_obj.client elif receiver == 'nobody': new_obj.receiver = None - + # + # sender = form.data.get('sender_group', None) if sender == 'he_is': new_obj.user_is_sender = True diff --git a/src/dokumentor/static/css/style.css b/src/dokumentor/static/css/style.css index 73f1822..9ca4e2f 100644 --- a/src/dokumentor/static/css/style.css +++ b/src/dokumentor/static/css/style.css @@ -860,3 +860,31 @@ input[type=number] { .nds_block__inline { display: inline-block; } + +.doc-form select#id_currency {width: 330px;height: 40px;font-size: 25px;margin-left: 0;padding-left: 2px;} + +#fixes, #avance { + padding-bottom: 7px; + font-size: 15px; +} + +.checkbox__org { + font-size: 15px; + padding-bottom: 10px; + display: inline-block; +} + +#sender p, +#receiver p { + margin: 0; + margin-bottom: 10px; +} +#sender p .add-client-link, +#receiver p .add-client-link { + padding: 0 50px 0; +} + +#id_sender-autocomplete, +#id_receiver-autocomplete { + width: 570px; +} diff --git a/src/dokumentor/static/js/formset-events.js b/src/dokumentor/static/js/formset-events.js index a138c55..edccaa2 100644 --- a/src/dokumentor/static/js/formset-events.js +++ b/src/dokumentor/static/js/formset-events.js @@ -36,7 +36,6 @@ $(function() { if ($('#id_nds_value').val() !== '0') { $('#nds_method').show(); - $('#blockTotalNds').show(); $('#decryption').show(); } diff --git a/src/dokumentor/templates/docs/faktura/form.html b/src/dokumentor/templates/docs/faktura/form.html index 59dc04e..7c1f7bc 100644 --- a/src/dokumentor/templates/docs/faktura/form.html +++ b/src/dokumentor/templates/docs/faktura/form.html @@ -1,46 +1,41 @@ {% extends "docs/_base/base_form.html" %} - {% load my_tags %} {% block form_content %} -
+
{% include 'docs/parts/form_field.html' with field=form.doc_num id="doc_num" classes="left" label="Номер" required="True" no_clear_after="True" %} {% include 'docs/parts/form_field.html' with field=form.doc_date id="doc_date" classes="left" label="Дата создания" required="True" no_clear_after="True"%} - {% include 'docs/parts/form_field.html' with field=form.bank_account %} -
-
- {% include 'docs/parts/form_field.html' with field=form.plat_doc_num id="plat_doc_num" classes="left" label="Номер платёжного документа" required="True" no_clear_after="True" %} - {% include 'docs/parts/form_field.html' with field=form.plat_doc_date id="plat_doc_date" classes="left" label="Дата платёжного документа" required="True" %} + {% include 'docs/parts/form_field.html' with field=form.bank_account %} +
Исправления
+
+ {% include 'docs/parts/form_field.html' with field=form.fix_doc_num id="fix_doc_num" classes="left" label="Номер исправления" required="True" no_clear_after="True" %} + {% include 'docs/parts/form_field.html' with field=form.fix_doc_date id="fix_doc_date" classes="left" label="Дата исправления" required="True" %} +
+
Аванс
+ {% include 'docs/parts/form_field.html' with field=form.currency id="currency" classes="field" label="Валюта документа " %}
+
- {% include 'docs/parts/form_field.html' with field=form.fixes id="fixes" label="Исправления" no_clear_after="True" label_inline="True" %} -
- {% include 'docs/parts/form_field.html' with field=form.fix_doc_num id="fix_doc_num" classes="left" label="Номер исправления" required="True" no_clear_after="True" %} - {% include 'docs/parts/form_field.html' with field=form.fix_doc_date id="fix_doc_date" classes="left" label="Дата исправления" required="True" %} -
- {% include 'docs/parts/form_field.html' with field=form.avance id="avance" label="Аванс" no_clear_after="True" label_inline="True" %} - {% include 'docs/parts/form_field_client.html' with field=form.client required="True" is_ajax="True" %} + {% include 'docs/parts/form_field_client.html' with field=form.client required="True" is_ajax="True" label="Покупатель" %} {% include 'docs/parts/form_field.html' with field=form.invoice id="invoice" classes="field hidden" label="Создать счёт-фактуру по счёту" %} - {% include 'docs/parts/form_field.html' with field=form.currency id="currency" classes="field" label="Валюта" %} - {% include 'docs/parts/form_field_sender.html' with field=form.sender id="sender" classes="field" label="Отправитель" %} - {% include 'docs/parts/form_field_receiver.html' with field=form.receiver id="receiver" classes="field" label="Получатель" %} -
-
- {% include 'docs/parts/form_field.html' with field=form.doc_reason id="doc_reason" classes="field" label="Основание" %} + {% include 'docs/parts/form_field_sender.html' with field=form.sender id="sender" %} + {% include 'docs/parts/form_field_receiver.html' with field=form.receiver id="receiver" %}
-
+
+{# {% include 'docs/parts/form_field.html' with field=form.doc_reason id="doc_reason" classes="field" label="Основание" %}#} {% include 'docs/parts/form_field.html' with field=form.nds_value id="nds_value" classes="left nds_block__inline" label="НДС" no_clear_after="True" %} {% include 'docs/parts/form_field.html' with field=form.nds_method id="nds_method" classes="left nds-method hidden" no_clear_after="True" %} +
+
+
{% if formset %} {% include 'docs/faktura/form_tbl_items.html' %} {% endif %}
+{% endblock form_content %} -{% endblock %} - -{% block js %} -{% endblock %} +{% block js %}{% endblock js %} diff --git a/src/dokumentor/templates/docs/parts/form_client_choices.html b/src/dokumentor/templates/docs/parts/form_client_choices.html index cc38c33..8cedcd9 100644 --- a/src/dokumentor/templates/docs/parts/form_client_choices.html +++ b/src/dokumentor/templates/docs/parts/form_client_choices.html @@ -1,4 +1,4 @@ -

{{ label }}

- {{ label1|default:'Он же' }} -{{ label2|default:'Стороннее лицо' }} - Не указывать +{#

{{ label }}

#} +{# {{ label1|default:'Он же' }}#} +{{ label2|default:'Стороннее лицо' }} +{# Не указывать#} diff --git a/src/dokumentor/templates/docs/parts/form_field_client.html b/src/dokumentor/templates/docs/parts/form_field_client.html index 4707541..2295651 100644 --- a/src/dokumentor/templates/docs/parts/form_field_client.html +++ b/src/dokumentor/templates/docs/parts/form_field_client.html @@ -1,4 +1,4 @@ - {% comment %} +{% comment %} field - поле required - отметить, что поле обязательное? label - заголовок поля (по умолчанию, `Контрагент`) @@ -8,7 +8,9 @@ no_clear_after - не добавлять очистку float после бло
+ {% if label != ' ' %} {{ label|default:"Контрагент" }}:{% if required %} *{% endif %} + {% endif %}

{{ field }} diff --git a/src/dokumentor/templates/docs/parts/form_field_receiver.html b/src/dokumentor/templates/docs/parts/form_field_receiver.html index 6d12ed8..ae1807d 100644 --- a/src/dokumentor/templates/docs/parts/form_field_receiver.html +++ b/src/dokumentor/templates/docs/parts/form_field_receiver.html @@ -1,3 +1,2 @@ -{% 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="Получатель" %} +{% include 'docs/parts/form_client_choices.html' with client_group="receiver_group" id="receiver_choices" classes="field" label2='Грузополучатель - стороннее лицо (не покупатель)' 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 index 8a59b8a..d2ebca7 100644 --- a/src/dokumentor/templates/docs/parts/form_field_sender.html +++ b/src/dokumentor/templates/docs/parts/form_field_sender.html @@ -1,2 +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="Отправитель" %} +{% include 'docs/parts/form_client_choices.html' with client_group="sender_group" id="sender_choices" classes="field" label2='Грузоотправитель - стороннее лицо (не моя компания)' 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/stub_js.html b/src/dokumentor/templates/docs/stub_js.html index fe3f8e1..2d0b52c 100644 --- a/src/dokumentor/templates/docs/stub_js.html +++ b/src/dokumentor/templates/docs/stub_js.html @@ -168,7 +168,10 @@ }); var toggle_sender = function(client_type) { - var sender_val = $('input:radio[name=' + client_type + '_group]:checked', '#doc-form').val(); + + console.log(client_type); + + var sender_val = $('input:checkbox[name=' + client_type + '_group]:checked', '#doc-form').val(); if (sender_val == 'another') { $('#' + client_type).show() } else { @@ -178,7 +181,7 @@ $.each(['sender', 'receiver'], function(i, client_type){ toggle_sender(client_type); - $('input:radio[name=' + client_type + '_group]').change(function(){ + $('input:checkbox[name=' + client_type + '_group]').change(function(){ toggle_sender(client_type); }) }); diff --git a/tox.ini b/tox.ini new file mode 100755 index 0000000..f2946b3 --- /dev/null +++ b/tox.ini @@ -0,0 +1,4 @@ +[flake8] +ignore = F403 +max-line-length = 120 +exclude = ./venv/*,*/migrations/*, ./node_modules/* \ No newline at end of file