예제 #1
0
파일: views.py 프로젝트: suall936/ozbuy
def sale_json(request):
  serializer = JSONSimpleSerializer()
  if 'sn' in request.GET:
    sale = SaleOrder.objects.filter(sn = request.GET['sn'])
  else:
    sale = SaleOrder.objects.all()
  return HttpResponse(serializer.serialize(sale, use_natural_foreign_keys=True))
예제 #2
0
파일: views.py 프로젝트: suall936/ozbuy
def customer_delete(request):
  if request.method == 'POST':
    delete_customer = Customer.objects.get(sn=request.POST['sn'])
    delete_name = unicode(delete_customer)
    delete_customer.delete()
    serializer = JSONSimpleSerializer()
    return HttpResponse(serializer.serialize([delete_customer,]))
  else:
    return HttpResponse("Invalid request.")
예제 #3
0
파일: views.py 프로젝트: suall936/ozbuy
def saleItem_json(request):
  """return json of all sale_items with sn as sale.sn. For ajax"""
  if request.GET['sn']:
    try:
      p = SaleOrder.objects.get(sn=request.GET['sn'])
    except SaleOrder.DoesNotExist:
      raise Http404
    pi = p.saleitem_set.all().order_by("sn")
    serializer = JSONSimpleSerializer()
    return HttpResponse(serializer.serialize(pi, use_natural_foreign_keys=True))
  else:
    return HttpResponse("Invalid request.")
예제 #4
0
파일: views.py 프로젝트: suall936/ozbuy
def vendor_add(request):
  if request.method == 'POST':
    form = VendorForm(request.POST)
    if form.is_valid():
      p = form.save(commit=False)
      p.sn = generate_sn(prefix = 'VDR')
      p = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
  else:
    form = VendorForm()
    return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: suall936/test
def currencyRate_json(request):
  """return json of all currencyRate with sn as currency.sn. For ajax"""
  if request.GET['sn']:
    try:
      p = Currency.objects.get(sn=request.GET['sn'])
    except Currency.DoesNotExist:
      raise Http404
    pi = p.fromRates.all().order_by("sn")
    serializer = JSONSimpleSerializer()
    return HttpResponse(serializer.serialize(pi, use_natural_foreign_keys=True))
  else:
    return HttpResponse("Invalid request.")
예제 #6
0
파일: views.py 프로젝트: suall936/ozbuy
def customer_add(request):
  if request.method == 'POST':
    form = CustomerForm(request.POST)
    if form.is_valid():
      c = form.save(commit=False)
      c.sn = generate_sn(prefix = 'CTM')
      c.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c,]))
  else:
    form = CustomerForm()
    return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
예제 #7
0
파일: views.py 프로젝트: suall936/test
def currencyRate_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    sn = postdata.pop('sn')[0]
    p = Currency.objects.get(pk=postdata['fromCurrency'][0])
    pi = CurrencyRate.objects.get(fromCurrency=p, sn=sn)
    form = CurrencyRateForm(postdata, instance=pi)
    if form.is_valid():
      pi_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi_saved,], use_natural_foreign_keys=True))
  else:
    pass
예제 #8
0
파일: views.py 프로젝트: suall936/test
def product_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      c = Product.objects.get(sn=postdata.pop('sn')[0])
    except Product.DoesNotExist:
      raise Http404
    form = ProductForm(postdata, instance=c)
    if form.is_valid():
      p = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
  else:
      return HttpResponse('Invalid request.')
예제 #9
0
파일: views.py 프로젝트: suall936/ozbuy
def vendor_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      c = Vendor.objects.get(sn=postdata.pop('sn')[0])
    except Vendor.DoesNotExist:
      raise Http404(module + ' not found')
    form = VendorForm(postdata, instance=c)
    if form.is_valid():
      c_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c_saved,]))
  else:
    return HttpResponse('Invalid request.')
예제 #10
0
파일: views.py 프로젝트: suall936/ozbuy
def saleItem_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    p_pk = postdata.pop('order')[0]
    sn = postdata.pop('sn')[0]
    p = SaleOrder.objects.get(pk=p_pk)
    pi = SaleItem.objects.get(order=p, sn=sn)
    form = SaleItemForm(postdata, instance=pi)
    if form.is_valid():
      pi_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi_saved,], use_natural_foreign_keys=True))
  else:
    pass
예제 #11
0
파일: views.py 프로젝트: suall936/test
def currency_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      p = Currency.objects.get(sn=postdata.pop('sn')[0])
    except Currency.DoesNotExist:
      raise Http404(module + ' not found')
    form = CurrencyForm(postdata, instance=p)
    print form.errors
    if form.is_valid():
      p_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p_saved,]))
  else:
    return HttpResponse('Invalid request.')
예제 #12
0
파일: views.py 프로젝트: suall936/ozbuy
def purchase_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      p = PurchaseOrder.objects.get(sn=postdata.pop('sn')[0])
    except PurchaseOrder.DoesNotExist:
      raise Http404(module + ' not found')
    form = PurchaseForm(postdata, instance=p)
    print form.errors
    if form.is_valid():
      p_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p_saved,],use_natural_foreign_keys=True))
  else:
    return HttpResponse('Invalid request.')
예제 #13
0
파일: views.py 프로젝트: suall936/ozbuy
def purchaseItem_add(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    p_sn = postdata.pop('itemLinkSn')[0]
    sn = postdata.pop('sn')[0]
    form = Purchase_ItemForm(postdata)
    if form.is_valid():
      pi = form.save(commit=False)
      p = PurchaseOrder.objects.get(sn=p_sn)
      pi.order = p
      pi.sn = Purchase_Item.objects.filter(order = p).count() + 1
      pi.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi,], use_natural_foreign_keys=True))
  else:
    return HttpResponse("Invalid request.")
예제 #14
0
파일: views.py 프로젝트: suall936/test
def currencyRate_add(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    # currency_pk = postdata.pop('fromCurrency')[0]
    sn = postdata.pop('sn')[0]
    form = CurrencyRateForm(postdata)
    if form.is_valid():
      pi = form.save(commit=False)
      p = Currency.objects.get(pk=postdata['fromCurrency'][0])
      # pi.sn = CurrencyRate.objects.filter(fromCurrency = p).count() + 1
      pi.sn = p.fromRates.count() + 1
      pi.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi,], use_natural_foreign_keys=True))
  else:
    return HttpResponse("Invalid request.")
예제 #15
0
파일: views.py 프로젝트: suall936/test
def currencyConvertTo_json(request):
  """return json of all currencyRate with sn specified the currency converted to. For ajax"""
  if request.GET['sn']:
    try:
      p = Currency.objects.get(sn=request.GET['sn'])
      print p
    except Currency.DoesNotExist:
      raise Http404
    if p.code == 'AUD':
      fromCurrency = Currency.objects.get(code ='CNY')
    elif p.code == 'CNY':
      fromCurrency = Currency.objects.get(code ='AUD')
    pi = p.toRates.all().filter(fromCurrency = fromCurrency).order_by('-isDefault')
    serializer = JSONSimpleSerializer()
    return HttpResponse(serializer.serialize(pi, use_natural_foreign_keys=True))
  else:
    return HttpResponse("Invalid request.")
예제 #16
0
파일: views.py 프로젝트: suall936/test
def customer_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      # c = Customer.objects.get(sn=request.POST['sn'])
      c = Customer.objects.get(sn=postdata.pop('sn')[0])
    except Customer.DoesNotExist:
      raise Http404(module + ' not found')
    # else:
    #   return HttpResponse('Invalid request.')
    form = CustomerForm(postdata, instance=c)
    if form.is_valid():
      c_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c_saved,]))
  else:
    # if request.GET['id']:
    #   c = Customer.objects.get(pk=int(request.GET['id']))
    #   form = CustomerForm(instance=c)
    #   return render_to_response('modal/main_form.html',{'action':'Edit', 'module':module, 'form': form},context_instance=RequestContext(request))
    # else:
    return HttpResponse('Invalid request.')
예제 #17
0
파일: views.py 프로젝트: suall936/test
def product_json(request):
  products= Product.objects.all()
  serializer = JSONSimpleSerializer()
  return HttpResponse(serializer.serialize(products, use_natural_foreign_keys=True))
예제 #18
0
파일: views.py 프로젝트: suall936/ozbuy
def vendor_json(request):
  vendors= Vendor.objects.all()
  serializer = JSONSimpleSerializer()
  return HttpResponse(serializer.serialize(vendors,use_natural_primary_keys=True))
예제 #19
0
파일: views.py 프로젝트: suall936/test
def currency_json(request):
  currencies= Currency.objects.all()
  serializer = JSONSimpleSerializer()
  return HttpResponse(serializer.serialize(currencies, use_natural_foreign_keys=True))
예제 #20
0
파일: views.py 프로젝트: suall936/test
def customer_json(request):
  customers= Customer.objects.all()
  serializer = JSONSimpleSerializer()
  return HttpResponse(serializer.serialize(customers))