diff --git a/project/docs/models/faktura.py b/project/docs/models/faktura.py index e344c49..38bc9c6 100644 --- a/project/docs/models/faktura.py +++ b/project/docs/models/faktura.py @@ -50,9 +50,9 @@ class Faktura(BaseInvoiceModel, SignedStatusFieldMixin, InvoiceFieldMixin, Linke class FakturaItem(BaseItemInvoiceModel): """Табличная часть фактуры""" - units_kod = models.CharField(u'Код единицы измерения', max_length=10) + units_kod = models.CharField(u'Код единицы измерения', max_length=10, blank=True, default=u'-') parent = models.ForeignKey(Faktura, related_name='faktura_items') - country_code = models.CharField(u'Код страны', max_length=10) + 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='') @@ -62,15 +62,3 @@ class FakturaItem(BaseItemInvoiceModel): verbose_name = u'Табл. часть фактуры' verbose_name_plural = u'Табл. части фактур' app_label="docs" - - -#class PlatDoc(models.Model): -# """Платёжные документы""" -# parent = models.ForeignKey(Faktura, related_name='plat_docs') -# num = models.CharField(u'Номер', max_length=30) -# doc_date = models.DateField('Дата') -# -# class Meta: -# verbose_name = u'Платёжный документ' -# verbose_name_plural = u'Платёжные документы' -# app_label="docs" diff --git a/project/docs/urls.py b/project/docs/urls.py index 38cb7a1..bed09f7 100644 --- a/project/docs/urls.py +++ b/project/docs/urls.py @@ -60,7 +60,7 @@ for name, klass in klasses: url(r'^%s/(?P\d+)/email/ajax/$' % name, getview, {'klass': klass, 'oper': 'email_ajax',}, name='docs_%s_email_ajax' % name), - url(r'^ajax_get_pair/(?P\w+)/(?P\w+)/(?P\w+)/(?P\w+)/$', get_pair, name='ajax_get_pair'), + url(r'^ajax_get_pair/(?P\w+)/(?P\w+)/(?P\w+)/(?P.+)/$', get_pair, name='ajax_get_pair'), url(r'^ajax_get_invoices/$', get_invoices, name='ajax_get_invoices'), url(r'^ajax_get_invoices/(?P\d+)/$', get_invoices, name='ajax_get_invoices'), url(r'^ajax_get_tbl_items/(?P\d+)/$', get_tbl_items, name='ajax_get_tbl_items'), diff --git a/project/docs/views/ajax.py b/project/docs/views/ajax.py index 048f5e7..8fea4b6 100644 --- a/project/docs/views/ajax.py +++ b/project/docs/views/ajax.py @@ -15,6 +15,11 @@ def get_pair(request, model, param1, val1, param2): if not request.is_ajax(): return HttpResponseBadRequest() + if model not in ('Country', 'Measure',): + return HttpResponseBadRequest() + + raise_if_no_profile(request) + kwargs = {param1: val1} try: @@ -34,10 +39,11 @@ def get_invoices(request, client_id=None): raise_if_no_profile(request) + invoices = Invoice.objects.get_all(request.user.profile) + if client_id: - invoices = Invoice.objects.filter(client__id=client_id) - else: - invoices = Invoice.objects.filter(company=request.user.profile) + invoices = invoices.filter(client_id=client_id) + invoices = {invoice.id: '№ %s от %s' % (invoice.doc_num, invoice.doc_date) for invoice in invoices} return HttpResponse(json.dumps(invoices), mimetype='application/json') @@ -47,7 +53,9 @@ def get_tbl_items(request, invoice_id): if not request.is_ajax(): return HttpResponseBadRequest() - invoice = Invoice.objects.get(pk=invoice_id) + raise_if_no_profile(request) + + invoice = Invoice.objects.get(company=request.user.profile, pk=invoice_id) data = serializers.serialize('json', invoice.invoice_items.all()) return HttpResponse(json.dumps(data), mimetype='application/json') @@ -57,7 +65,9 @@ def get_client_by_invoice(request, invoice_id): if not request.is_ajax(): return HttpResponseBadRequest() - invoice = Invoice.objects.get(pk=invoice_id) + raise_if_no_profile(request) + + invoice = Invoice.objects.get(company=request.user.profile, pk=invoice_id) return HttpResponse(json.dumps([invoice.client.id, invoice.client.name]), mimetype='application/json') @@ -66,18 +76,24 @@ def toggle_doc_status(request, doc_type, doc_id, doc_attr): if not request.is_ajax() or request.method != 'POST': return HttpResponseBadRequest() + raise_if_no_profile(request) + model_ = get_model('docs', doc_type) - doc = model_.objects.get(pk=doc_id) + doc = model_.objects.get(company=request.user.profile, pk=doc_id) + choices_ = doc._meta.get_field_by_name(doc_attr)[0].get_choices() choices = [i[0] for i in choices_[1:]] prev_val = getattr(doc, doc_attr) + try: next_index = choices.index(prev_val) + 1 next_val = choices[next_index] except: next_val = choices[0] + setattr(doc, doc_attr, next_val) doc.save() + next_text = dict(choices_)[next_val] return HttpResponse(json.dumps([next_text, next_val]), mimetype='application/json') diff --git a/project/static/css/style.css b/project/static/css/style.css index 95427d6..f0eae62 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -475,8 +475,6 @@ a.delete { vertical-align: top; } .doc-form table.doc-list td.name { width: 590px; } .doc-form table.doc-list td.name input[type=text] { width: 584px; } -.doc-form table.factura-doc-list td.name { width: 260px; } -.doc-form table.factura-doc-list td.name input[type=text] { width: 250px; } .doc-form table.doc-list td.qty { width: 140px; } .doc-form table.doc-list td.qty input { width: 135px; } .doc-form table.doc-list td.units { width: 90px; } @@ -491,6 +489,11 @@ a.delete { vertical-align: top; } .doc-form table.doc-list td.ntd input { width: 84px; } .doc-form table.doc-list td.DELETE {width: 48px;} +.doc-form table.factura-doc-list td.name { width: 260px; } +.doc-form table.factura-doc-list td.name input[type=text] { width: 250px; } +.doc-form table.factura-doc-list td.units input { width: 166px; } +.doc-form table.factura-doc-list td.country_name input { width: 132px; } + .doc-form table.doc-list.aktsverki td.name input[type=text] { width: 432px; } .doc-form table.doc-list.aktsverki td.debit input[type=text] { width: 96px; } .doc-form table.doc-list.aktsverki td.credit input[type=text] { width: 96px; } diff --git a/project/templates/base.html b/project/templates/base.html index 9da693e..d79bec1 100644 --- a/project/templates/base.html +++ b/project/templates/base.html @@ -9,7 +9,7 @@ {% block title %}{% endblock %} | Документор - + {% render_block "css" %} diff --git a/project/templates/docs/faktura/form.html b/project/templates/docs/faktura/form.html index 00b5736..62a8b85 100644 --- a/project/templates/docs/faktura/form.html +++ b/project/templates/docs/faktura/form.html @@ -32,14 +32,12 @@
- {% include 'docs/parts/form_field.html' with field=form.nds_value id="nds_value" classes="left" label="НДС" no_clear_after="True" %} + {% include 'docs/parts/form_field.html' with field=form.nds_value id="nds_value" label="НДС" no_clear_after="True" %} + {% if formset %} + {% include 'docs/faktura/form_tbl_items.html' %} + {% endif %}
- {% if formset %} -
- {% include 'docs/parts/faktura_form_tbl_items.html' %} -
- {% endif %} {% endblock %} diff --git a/project/templates/docs/parts/faktura_form_tbl_items.html b/project/templates/docs/faktura/form_tbl_items.html similarity index 85% rename from project/templates/docs/parts/faktura_form_tbl_items.html rename to project/templates/docs/faktura/form_tbl_items.html index 27c1a37..2fbfef0 100644 --- a/project/templates/docs/parts/faktura_form_tbl_items.html +++ b/project/templates/docs/faktura/form_tbl_items.html @@ -3,11 +3,11 @@ - + - + @@ -16,6 +16,7 @@ {{ iform.id }} {{ iform.parent }} + - - + - diff --git a/project/templates/docs/parts/form_field_receiver.html b/project/templates/docs/parts/form_field_receiver.html index 8b2bf0d..6d12ed8 100644 --- a/project/templates/docs/parts/form_field_receiver.html +++ b/project/templates/docs/parts/form_field_receiver.html @@ -1,4 +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="Получатель" %} -
\ No newline at end of file diff --git a/project/templates/docs/parts/form_field_sender.html b/project/templates/docs/parts/form_field_sender.html index 5d14041..8a59b8a 100644 --- a/project/templates/docs/parts/form_field_sender.html +++ b/project/templates/docs/parts/form_field_sender.html @@ -1,3 +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="Отправитель" %} -
\ No newline at end of file diff --git a/project/templates/docs/stub_js.html b/project/templates/docs/stub_js.html index 73c5cbe..51b6636 100644 --- a/project/templates/docs/stub_js.html +++ b/project/templates/docs/stub_js.html @@ -9,29 +9,28 @@ prefix: '{{ formset.prefix }}', formCssClass: 'dynamic-form', }); - var get_pair = function(model, class1, class2, name1, name2) { - $('body').on('focusout', '.' + class1 + ' input', function() { + + var get_pair = function(model, class1, class2, param1, param2) { + $('body').on('selectChoice change', '.' + class1 + ' input', function() { var $this = $(this); - var $code_input = $this.closest('.row_tbl_items').find('.' + class2 + ' input'); - var code_input_val = $code_input.val(); + var this_val = $this.val(); + var $other_input = $this.closest('.row_tbl_items').find('.' + class2 + ' input'); - $.get('/my/docs/ajax_get_pair/' + model + '/' + name1 + '/' + name2 + '/' + $this.val() + '/', function(data){ + $.get('/my/docs/ajax_get_pair/' + model + '/' + param1 + '/' + param2 + '/' + this_val + '/', function(data) { if (data['val']) { - $code_input.val(data['val']); - if (($code_input.val() != '')&&(($code_input.val() != code_input_val))) { - $code_input.css('color', 'red') - } else { - $code_input.css('color', 'black') - } - $this.css('color', 'black'); + $other_input.val(data['val']); + $this.css('color', 'black') + } + else { + $other_input.val('-'); + $this.css('color', 'red') } }); }) } - get_pair('Country', 'country_code', 'country_name', 'code', 'name'); + {# model должна быть разрешена в docs.views.get_pair #} get_pair('Country', 'country_name', 'country_code', 'name', 'code'); get_pair('Measure', 'units', 'units_kod', 'name', 'code'); - get_pair('Measure', 'units_kod', 'units', 'code', 'name'); $('#id_client').on('change', function() { var client_id = $(this).val(); @@ -112,7 +111,7 @@ } else { $('#fix_block').hide(); } - $('#id_fixes').change(function(){ + $('#id_fixes').change(function(){ $('#fix_block').toggle(); $('#id_fix_doc_num').val(''); $('#id_fix_doc_date').val('');
НаименованиеЕд. изм.Ед. изм. Кол-во Цена СуммаСтранаСтрана № таможенной декларации
{{ iform.name.errors }} {{ iform.name }} @@ -24,9 +25,8 @@ {{ iform.units.errors }} {{ iform.units }} - {{ iform.units_kod.errors }} - {{ iform.units_kod }} + {{ iform.qty.errors }} @@ -40,14 +40,13 @@ {{ iform.total_price.errors }} {{ iform.total_price }} - {{ iform.country_code.errors }} - {{ iform.country_code }} - {{ iform.country_name.errors }} {{ iform.country_name }} {{ iform.ntd.errors }} {{ iform.ntd }} @@ -59,7 +58,7 @@ {% endfor %}
+ Итого