|
@@ -8,7 +8,6 @@ class db():
|
|
|
def get_cursor(self):
|
|
def get_cursor(self):
|
|
|
if not self.conn.open:
|
|
if not self.conn.open:
|
|
|
self.connect()
|
|
self.connect()
|
|
|
-
|
|
|
|
|
try:
|
|
try:
|
|
|
cur = self.conn.cursor()
|
|
cur = self.conn.cursor()
|
|
|
except:
|
|
except:
|
|
@@ -27,6 +26,7 @@ class db():
|
|
|
cur = self.get_cursor()
|
|
cur = self.get_cursor()
|
|
|
cur.execute("SELECT id,nombre,apellido,hash FROM clientes where hash=%s", (_hash,))
|
|
cur.execute("SELECT id,nombre,apellido,hash FROM clientes where hash=%s", (_hash,))
|
|
|
res = cur.fetchall()
|
|
res = cur.fetchall()
|
|
|
|
|
+ cur.close()
|
|
|
if len(res) == 0:
|
|
if len(res) == 0:
|
|
|
return None
|
|
return None
|
|
|
return res[0]
|
|
return res[0]
|
|
@@ -48,6 +48,7 @@ class db():
|
|
|
p["cantidad"] = row["cantidad"]
|
|
p["cantidad"] = row["cantidad"]
|
|
|
|
|
|
|
|
pedido["productos"] = productos
|
|
pedido["productos"] = productos
|
|
|
|
|
+ cur.close()
|
|
|
return pedido
|
|
return pedido
|
|
|
|
|
|
|
|
|
|
|
|
@@ -59,19 +60,19 @@ class db():
|
|
|
row["fecha"] = row["fecha"].isoformat() #strftime("%Y-%m-%d %H:%M")
|
|
row["fecha"] = row["fecha"].isoformat() #strftime("%Y-%m-%d %H:%M")
|
|
|
ret.append(row)
|
|
ret.append(row)
|
|
|
|
|
|
|
|
|
|
+ cur.close()
|
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
def products(self, _id=None):
|
|
def products(self, _id=None):
|
|
|
ret=[]
|
|
ret=[]
|
|
|
if _id is None:
|
|
if _id is None:
|
|
|
cur = self.get_cursor()
|
|
cur = self.get_cursor()
|
|
|
- cur.execute("SELECT id,nombre,precio FROM productos where id between 1000 and 2999")
|
|
|
|
|
|
|
+ cur.execute("SELECT id, nombre, precio, stock > 0 as disponible, stock < 25 as low, stock FROM productos where id between 1000 and 2999 and id not in (1019, 1014, 2014, 1015, 2015, 1047, 2038, 2030)")
|
|
|
for row in cur.fetchall():
|
|
for row in cur.fetchall():
|
|
|
row["cantidad"]=0
|
|
row["cantidad"]=0
|
|
|
ret.append(row)
|
|
ret.append(row)
|
|
|
- else:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
|
|
|
|
|
+ cur.close()
|
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
def update_pedido(self, productos, _hash, obs, id_pedido):
|
|
def update_pedido(self, productos, _hash, obs, id_pedido):
|
|
@@ -92,6 +93,7 @@ class db():
|
|
|
lista_productos = [ (id_pedido,p["id"],p["cantidad"]) for p in productos ]
|
|
lista_productos = [ (id_pedido,p["id"],p["cantidad"]) for p in productos ]
|
|
|
cur.executemany("insert into productos_pedido(id_pedido,id_producto,cantidad) values (%s, %s, %s)", lista_productos)
|
|
cur.executemany("insert into productos_pedido(id_pedido,id_producto,cantidad) values (%s, %s, %s)", lista_productos)
|
|
|
self.conn.commit()
|
|
self.conn.commit()
|
|
|
|
|
+ cur.close()
|
|
|
|
|
|
|
|
def create_pedido(self, productos, _hash, obs):
|
|
def create_pedido(self, productos, _hash, obs):
|
|
|
clienteID = int(self.client(_hash)["id"])
|
|
clienteID = int(self.client(_hash)["id"])
|
|
@@ -101,14 +103,16 @@ class db():
|
|
|
params = ( clienteID, sum([ p["cantidad"] for p in productos]), subtotal, obs )
|
|
params = ( clienteID, sum([ p["cantidad"] for p in productos]), subtotal, obs )
|
|
|
|
|
|
|
|
#CREADO, CONFIRMADO, ARMADO, ENVIADO
|
|
#CREADO, CONFIRMADO, ARMADO, ENVIADO
|
|
|
- ex = cur.execute("insert into pedidos (cliente,cant_productos,subtotal,fecha,estado) values (%s, %s, %s, %s, NOW(), 'CREADO')", params)
|
|
|
|
|
|
|
+ ex = cur.execute("insert into pedidos (cliente, cant_productos, subtotal, observaciones, fecha, estado) values (%s, %s, %s, %s, NOW(), 'CREADO')", params)
|
|
|
_id = cur.lastrowid
|
|
_id = cur.lastrowid
|
|
|
lista_productos = [ (_id,p["id"],p["cantidad"]) for p in productos ]
|
|
lista_productos = [ (_id,p["id"],p["cantidad"]) for p in productos ]
|
|
|
cur.executemany("insert into productos_pedido(id_pedido,id_producto,cantidad) values (%s, %s, %s)", lista_productos)
|
|
cur.executemany("insert into productos_pedido(id_pedido,id_producto,cantidad) values (%s, %s, %s)", lista_productos)
|
|
|
self.conn.commit()
|
|
self.conn.commit()
|
|
|
|
|
+ cur.close()
|
|
|
|
|
|
|
|
def confirm(self, _hash, _id):
|
|
def confirm(self, _hash, _id):
|
|
|
c = self.client(_hash)
|
|
c = self.client(_hash)
|
|
|
cur = self.get_cursor()
|
|
cur = self.get_cursor()
|
|
|
cur.execute("UPDATE pedidos set estado = 'CONFIRMADO', fecha=NOW() where id = %s and cliente = %s and estado = 'CREADO'", (_id,c["id"]))
|
|
cur.execute("UPDATE pedidos set estado = 'CONFIRMADO', fecha=NOW() where id = %s and cliente = %s and estado = 'CREADO'", (_id,c["id"]))
|
|
|
self.conn.commit()
|
|
self.conn.commit()
|
|
|
|
|
+ cur.close()
|