autocomplete, code-name ajax

remotes/origin/yandex
Bachurin Sergey 12 years ago
parent bfee03a3be
commit 8308a7adec
  1. 2
      project/docs/admin.py
  2. 12
      project/docs/autocomplete_light_registry.py
  3. 4
      project/docs/consts.py
  4. 5
      project/docs/forms/faktura.py
  5. 6
      project/docs/urls.py
  6. 1
      project/docs/views/__init__.py
  7. 47
      project/docs/views/ajax.py
  8. 1
      project/settings.py
  9. 12
      project/static/js/formset-events.js
  10. 1
      project/templates/base.html
  11. 2
      project/templates/docs/parts/faktura_form_tbl_items.html
  12. 57
      project/templates/docs/stub_js.html
  13. 5
      project/urls.py
  14. 3
      requirements-dev.txt
  15. 3
      requirements.txt

@ -5,3 +5,5 @@ import models
admin.site.register(models.Currency)
admin.site.register(models.Country)
admin.site.register(models.Measure)

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
import autocomplete_light
from django.db.models import Q
from models import (Country, Currency, Measure)
autocomplete_light.register(Country, name='ACCountry')
autocomplete_light.register(Currency, name='ACCurrency')
autocomplete_light.register(Measure, name='ACMeasure')

@ -20,8 +20,8 @@ NDS_TYPE_CHOICES = (
# ставка НДС
NDS_VALUE_0 = 0
NDS_VALUE_10 = 0.1
NDS_VALUE_18 = 0.18
NDS_VALUE_10 = 10
NDS_VALUE_18 = 18
NDS_VALUE_CHOICES = (
(NDS_VALUE_0, u'Без НДС'),

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from django import forms
from project.commons.forms import MyBaseModelForm
import autocomplete_light
from project.commons.forms import MyBaseModelForm
from .base_forms import BaseModelForm
from ..models import Faktura, FakturaItem, PlatDoc
@ -41,6 +42,8 @@ class FakturaAdminForm(FakturaForm):
class FakturaItemForm(MyBaseModelForm):
"""Форма редактирования табличной части фактуры."""
units = forms.CharField(widget=autocomplete_light.TextWidget('ACMeasure'),)
country_name = forms.CharField(widget=autocomplete_light.TextWidget('ACCountry'),)
class Meta:
model = FakturaItem
exclude = ['parent']

@ -2,7 +2,7 @@
from django.conf.urls import *
from .views import (InvoiceViews, AktRabotViews, AktSverkiViews, DoverViews, PlatejkaViews, NakladnViews, FakturaViews)
from .views import getview, index
from .views import getview, index, get_pair, get_invoices, get_tbl_items
urlpatterns = patterns('docs.views',
@ -56,6 +56,10 @@ for name, klass in klasses:
# отправить pdf/xls на email - AJAX
url(r'^%s/(?P<id>\d+)/email/ajax/$' % name, getview, {'klass': klass, 'oper': 'email_ajax',},
name='docs_%s_email_ajax' % name),
url(r'^ajax_get_pair/(?P<model>\w+)/(?P<param1>\w+)/(?P<param2>\w+)/(?P<val1>\w+)/$', get_pair, name='ajax_get_pair'),
url(r'^ajax_get_invoices/(?P<client_id>\d+)/$', get_invoices, name='ajax_get_invoices'),
url(r'^ajax_get_tbl_items/(?P<invoice_id>\d+)/$', get_tbl_items, name='ajax_get_tbl_items'),
)
# доп. обработчики: создать Документ по Счету

@ -11,6 +11,7 @@ from .dover import DoverViews
from .platejka import PlatejkaViews
from .nakladn import NakladnViews
from .faktura import FakturaViews
from .ajax import get_pair, get_invoices, get_tbl_items
#from .sfv import SfvViews

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
import simplejson as json
from django.shortcuts import render, get_object_or_404, redirect
from django.http import HttpResponseBadRequest, HttpResponse
from django.core import serializers
from django.db.models import get_model
from django.views.decorators.csrf import csrf_protect
from ..models import Invoice
def get_pair(request, model, param1, val1, param2):
if not request.is_ajax():
return HttpResponseBadRequest()
kwargs = {param1: val1}
try:
q_model = get_model('docs', model)
val2 = getattr(q_model.objects.get(**kwargs), param2)
except:
val2 = None
data = {
'val': val2,
}
return HttpResponse(json.dumps(data), mimetype='application/json')
def get_invoices(request, client_id):
if not request.is_ajax():
return HttpResponseBadRequest()
invoices = Invoice.objects.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')
def get_tbl_items(request, invoice_id):
if not request.is_ajax():
return HttpResponseBadRequest()
invoice = Invoice.objects.get(pk=invoice_id)
data = serializers.serialize('json', invoice.invoice_items.all())
return HttpResponse(json.dumps(data), mimetype='application/json')

@ -140,6 +140,7 @@ INSTALLED_APPS = (
'pytils',
'django_filters',
'autocomplete_light',
# my apps
'project.commons',

@ -1,4 +1,4 @@
$(function($) {
$(function() {
var calc_summa = function (e) {
var $this = $(this);
var qty = parseFloat($this.closest('tr.row').find('td.qty input').val());
@ -8,6 +8,10 @@ $(function($) {
$this.closest('tr.row').find('td.total_price input').val(qty * price);
}
}
var calc_itogo_nds = function() {
$('#itogo_nds_text').html('НДС ' + $('#id_nds_value option:selected').text());
$('#itogo_nds').html(parseFloat($('#id_nds_value').val()) * parseFloat($('#itogo').html()) / 100);
}
window.calc_itogo = function (e) {
var itogo_sum = 0;
$('#tbl_items').find('.total_price input:visible').each(function(){
@ -15,12 +19,8 @@ $(function($) {
itogo_sum += itogo_sum_row;
})
$('#itogo').html(itogo_sum);
calc_itogo_nds();
}
var calc_itogo_nds = function() {
$('#itogo_nds_text').html('НДС ' + $('#id_nds_value option:selected').text());
$('#itogo_nds').html($('#id_nds_value').val() * parseInt($('#itogo').html()));
}
window.set_events = function set_events() {
$("#tbl_items tr.row td.qty input").on('keyup', calc_summa);
$("#tbl_items tr.row td.price input").on('keyup', calc_summa);

@ -67,6 +67,7 @@
<script src="{{ STATIC_URL }}js/commons.js"></script>
<script src="{{ STATIC_URL }}js/dialogs.js"></script>
{% include 'autocomplete_light/static.html' %}
{% endblock %}
{% block js %}{% endblock %}

@ -21,7 +21,7 @@
{{ iform.units.errors }}
{{ iform.units }}
</td>
<td class="units">
<td class="units_kod">
{{ iform.units_kod.errors }}
{{ iform.units_kod }}
</td>

@ -7,5 +7,62 @@
$('tr.row_tbl_items').formset({
prefix: '{{ formset.prefix }}'
});
var get_pair = function(model, class1, class2, name1, name2) {
$('body').on('focusout', '.' + class1 + ' input', function() {
var $this = $(this);
var $code_input = $this.closest('.row_tbl_items').find('.' + class2 + ' input');
var code_input_val = $code_input.val();
$.get('/my/docs/ajax_get_pair/' + model + '/' + name1 + '/' + name2 + '/' + $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');
}
});
})
}
get_pair('Country', 'country_code', 'country_name', 'code', 'name');
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();
$.get('/my/docs/ajax_get_invoices/' + client_id, function(data) {
var select = $('#id_invoice');
if(select.prop) {
var options = select.prop('options');
}
else {
var options = select.attr('options');
}
$('option', select).remove();
options[options.length] = new Option('--', null);
$.each(data, function(val, text) {
options[options.length] = new Option(text, val);
});
})
})
$('#id_invoice').on('change', function() {
var invoice_id = $(this).val();
$.get('/my/docs/ajax_get_tbl_items/' + invoice_id, function(data) {
var items = JSON.parse(data);
console.log(items.length);
$.each(items, function(index, item){
var name = item['fields']['name'];
var units = item['fields']['units'];
var qty = item['fields']['qty'];
var price = item['fields']['price'];
var total_price = item['fields']['total_price'];
})
})
})
});
</script>

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
import autocomplete_light
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
autocomplete_light.autodiscover()
urlpatterns = patterns('',
@ -16,7 +17,7 @@ urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'autocomplete/', include('autocomplete_light.urls')),
url(r'^$', 'project.pages.views.site_index', name='site_index'),
url(r'^my/', include('project.customer.urls')),

@ -13,9 +13,10 @@ django-filter==0.7
pytils==0.2.3
psycopg2
flup
django-autocomplete-light==2.0.0pre
# dev
django-devserver
django-eml-email-backend
django-debug-toolbar
ipython
ipython

@ -13,9 +13,10 @@ django-filter==0.7
pytils==0.2.3
psycopg2
flup
django-autocomplete-light==2.0.0pre
# dev
#django-devserver
#django-eml-email-backend
django-debug-toolbar
ipython
ipython
Loading…
Cancel
Save