diff --git a/.gitignore b/.gitignore index 7c01289..bd9d4c7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,5 @@ local_settings.py Thumbs.db distribute-*.tar.gz *.bak - +*.swp _public_html/ diff --git a/project/customer/views/clients_ajax.py b/project/customer/views/clients_ajax.py index e8f6be9..68478b2 100644 --- a/project/customer/views/clients_ajax.py +++ b/project/customer/views/clients_ajax.py @@ -39,11 +39,15 @@ def clients_add_ajax(request): if not request.is_ajax(): return HttpResponseBadRequest() + new_client_id = None + new_client_str = None form = form_class(data=request.POST) if form.is_valid(): new_client = form.save(commit=False) new_client.user = request.user new_client.save() + new_client_id = new_client.id + new_client_str = new_client.name non_field_errors = form.non_field_errors() if not form.is_valid(): @@ -54,7 +58,9 @@ def clients_add_ajax(request): 'field_errors': form.errors, # ошибки полей 'form_errors': non_field_errors, # ошибки формы #'reload': form.is_valid() and 'reload_on_success' in request.GET - 'reload': False + 'reload': False, + 'id': new_client_id, + 'name': new_client_str, } return HttpResponse(json.dumps(data), mimetype='application/json') diff --git a/project/docs/forms/faktura.py b/project/docs/forms/faktura.py index 6120b6b..1be57d1 100644 --- a/project/docs/forms/faktura.py +++ b/project/docs/forms/faktura.py @@ -65,3 +65,7 @@ class PlatDocItemForm(MyBaseModelForm): class Meta: model = PlatDoc exclude = ['parent'] + + widgets = { + 'doc_date': forms.TextInput(attrs={'class': 'has-datepicker'}), + } diff --git a/project/docs/views/base_views.py b/project/docs/views/base_views.py index d64577c..4808d8c 100644 --- a/project/docs/views/base_views.py +++ b/project/docs/views/base_views.py @@ -645,18 +645,20 @@ class BaseItemsViews(BaseViews): receiver_choice = 1 sender_choice = 1 if self.request.method == 'GET': - if obj.user_is_sender: - sender_choice = 'he_is' - elif obj.sender: - sender_choice = 'another' - else: - sender_choice = 'nobody' - if obj.receiver == obj.client: - receiver_choice = 'he_is' - elif obj.sender: - receiver_choice = 'another' - else: - receiver_choice = 'nobody' + if hasattr(obj, 'user_is_sender'): + if obj.user_is_sender: + sender_choice = 'he_is' + elif obj.sender: + sender_choice = 'another' + else: + sender_choice = 'nobody' + if hasattr(obj, 'receiver') and hasattr(obj, 'sender'): + if obj.receiver == obj.client: + receiver_choice = 'he_is' + elif obj.sender: + receiver_choice = 'another' + else: + receiver_choice = 'nobody' if self.pformset: pformset = self.pformset(self.request.POST or None, instance=obj) diff --git a/project/static/js/dialogs.js b/project/static/js/dialogs.js index 249cc20..061c727 100644 --- a/project/static/js/dialogs.js +++ b/project/static/js/dialogs.js @@ -14,13 +14,30 @@ $(document).ready(function() { complete: function(data) { $('input', form).removeAttr('disabled'); $('button', form).removeAttr('disabled'); + }, + /*beforeSend: function() { $('.errors-layout', form).html('').hide(); },*/ success: function(data) { clear_form_errors(form); + if (data.success) { + if (form[0].id == 'client-edit-form') { + var autocomplete = $('#id_client_text').yourlabsAutocomplete(); + $('#id_client_text').val(data.name); + var choices = autocomplete.box.find(autocomplete.choiceSelector); + autocomplete.refresh(); + autocomplete.show = function(html) { + yourlabs.Autocomplete.prototype.show.call(this, html) + var choices = this.box.find(this.choiceSelector); + + if (choices.length == 1) { + this.input.trigger('selectChoice', [choices, this]); + } + } + } form.dialog('close'); form.clearForm(); if (data.message) { diff --git a/project/templates/docs/faktura/form.html b/project/templates/docs/faktura/form.html index 2658b73..98d2181 100644 --- a/project/templates/docs/faktura/form.html +++ b/project/templates/docs/faktura/form.html @@ -16,7 +16,7 @@ {% 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.html' with field=form.bank_account id="bank_account" classes="field" label="Расчётный счёт" %} {% include 'docs/parts/form_field_client.html' with field=form.client required="True" is_ajax="True" %} - {% include 'docs/parts/form_field.html' with field=form.invoice id="invoice" classes="field" label="Создать накладную по счёту" %} + {% include 'docs/parts/form_field.html' with field=form.invoice id="invoice" classes="field" 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="Получатель" %}