parent
bfee03a3be
commit
8308a7adec
15 changed files with 146 additions and 15 deletions
@ -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') |
||||
|
||||
|
||||
|
||||
@ -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') |
||||
Loading…
Reference in new issue