Ejemplo n.º 1
0
def make_pedido(request):
    print "we are in Make Pedidos"
    current_user = request.user
    cliente = Cliente.objects.get(user_id = current_user.id)
    username = str(current_user.username)
    user_listas = Cliente.objects.get(user_id=current_user.id).listas.all()
    #BUGGGGG!!!! TODO: nothing to say... 2 clients
    cliente = Cliente.objects.filter(user_id = current_user.id)
    print "we are going to use the cliente"
    print cliente
    proveedor = cliente[0].user.groups.exclude(name=CLIENTE_ATTRIBUTE)[0]
    pedido = {}
    cliente = cliente.values()[0]
    orden = {}
    descripcion = {}
    precio = {}
    active = {}
    for lista_i in user_listas:
      current_list = Elemento.objects.filter(lista_id = lista_i.id, producto_id__isnull = False)
      for ele in current_list:
        descripcion[ele.producto.product_ref] = ele.producto.nombre
        precio[ele.producto.product_ref] = float(ele.producto.precio)
        active[ele.producto.product_ref] = 1
        if ele.producto.product_ref in orden:
          orden[ele.producto.product_ref] += ele.cantidad
        else:
          orden[ele.producto.product_ref] = ele.cantidad
        ##yes.. I am accessing by ID to a dict...
        ##create Pedido like 
        ## pedido[0] will have the information related with the user
        ## pedido[0] = {'user_name':'CLIENTE1','date':'pick a standard','tarifa':'proveedor1'}....
        ## pedido[1] will have amounts and prices (should be enough, because the price belongs to the ref, no to any other thing
        ## pedido[1] = {'product_ref':'cantidad','CAJUL':'25','MNB':'34'} ....
        ## pedido[2] If more information is requested could do like:
        ## pedido[2] = {'product_ref':'whatever you need here, like comments','CAJUL':'comment',
        ## [3] is the item is active, used by re_order system, desactive = 0 , desactivate = 1
    pedido['cliente'] = cliente
    pedido['orden'] = orden
    #we can send the price of the elements right now... not sure if is right
    pedido['precio'] = precio
    pedido['descripcion'] = descripcion
    pedido['active'] = active 
    print "Add logic to send order here"
    #really?? again?? TODO: fix cliente
    cliente = Cliente.objects.get(user_id = current_user.id)

    send_order(pedido,proveedor)
    print "Update to pending to send or something like that"
    print "now, clean the remaining cantidades..."
    for lista_i in user_listas:
      current_list = Elemento.objects.filter(lista_id = lista_i.id, producto_id__isnull = False).update(cantidad=0)
    #TODO: handle the exceptions!!
    return redirect('/cliente/historico/', request)
Ejemplo n.º 2
0
        current_list = Elemento.objects.filter(lista_id=lista_i.id, producto_id__isnull=False)
        for ele in current_list:
            descripcion[ele.producto.product_ref] = ele.producto.nombre
            precio[ele.producto.product_ref] = float(ele.producto.precio)
            active[ele.producto.product_ref] = 1
            if ele.producto.product_ref in orden:
                orden[ele.producto.product_ref] += ele.cantidad
            else:
                orden[ele.producto.product_ref] = ele.cantidad
        pedido["cliente"] = cliente_values
        pedido["orden"] = orden
        # we can send the price of the elements right now... not sure if is right
        pedido["precio"] = precio
        pedido["descripcion"] = descripcion
        pedido["active"] = active
        print "Add logic to send order here"
        send_order(pedido, proveedor)
    print "Done"

print "Current time " + time.strftime("%X")


# lets put in different status the pedidos
print "Current time " + time.strftime("%X")
print "set random status"
for t in Pedidos.objects.all():
    t.pedidostate = str(Pedidos.STATE_CHOICES[random.randrange(0, len(Pedidos.STATE_CHOICES))][0])
    t.save()

print "Current time " + time.strftime("%X")