Example #1
0
def newBill_view(request):
    contador=0
    form = FacturaForm(request.POST or None)
    id=Factura.objects.all().count()
    id_fac=id+1
    producto = Producto.objects.all()
    if form.is_valid():
        form.save()
        id1=Factura.objects.all().count()
        print id1
        idF= get_object_or_404(Factura, id=id1)
        print idF
        contador = int(request.POST.get("contar"))
        print contador
        for i in range(contador):
            print "1"
            prd=get_object_or_404(Producto, id= request.POST.get("idpr1"))
            cant=request.POST.get("TxtCantidad"+str(i+1))
            det=request.POST.get("id_fac_des")
            print cant,det
            deta=Detalle_Factura(det_ped_can=cant,det_ped_des=det,ped_id=idF,pro_id=prd)
            deta.save()
        return redirect("list_factura")

    cntx={'listaClientes': Cliente.objects.all(),'listaProductos':Producto.objects.all(),'id_fac':id_fac, 'form':form}

    return render(request,'addbill.html',cntx)
Example #2
0
def guardarFacturaDetalle(request):
    print 'yes'
    cliente_id= ""
    cliente= Cliente.objects.filter(cli_ced=request.GET["cedCli"])
    for i in cliente:
        cliente_id=i.id
        
    bill=Detalle_Factura(fac_num=request.GET["numFac"],
           fac_fec=datetime.datetime.now(),
           fac_sub_tot=request.GET["subTot"],
           fac_iva=request.GET["iva"],
           fac_des="Emitida por: "+request.user.usu_nom,
           fac_tot=request.GET["txtTotal"],
           cli_id_id=cliente_id,
           )
    bill.save()
    print 'yes1'
    id_ped=bill.id
    data = json.dumps(id_ped)

    return HttpResponse(data, content_type='application/json')