|
|
@@ -23,7 +23,7 @@ class db():
|
|
|
cur = self.conn.cursor()
|
|
|
cur.execute( "SELECT id, cant_productos, subtotal, fecha, estado FROM pedidos where cliente = %s and id = %s", (int(clientid),pedidoid) )
|
|
|
pedido = cur.fetchone()
|
|
|
- pedido["fecha"] = pedido["fecha"].strftime("%Y-%m-%d %H:%M")
|
|
|
+ pedido["fecha"] = pedido["fecha"].isoformat() #strftime("%Y-%m-%d %H:%M")
|
|
|
|
|
|
productos = self.products()
|
|
|
|
|
|
@@ -43,7 +43,7 @@ class db():
|
|
|
cur = self.conn.cursor()
|
|
|
cur.execute( "SELECT id, cant_productos, subtotal, fecha, estado FROM pedidos where cliente = %s", (int(clientid),) )
|
|
|
for row in cur.fetchall():
|
|
|
- row["fecha"] = row["fecha"].strftime("%Y-%m-%d %H:%M")
|
|
|
+ row["fecha"] = row["fecha"].isoformat() #strftime("%Y-%m-%d %H:%M")
|
|
|
ret.append(row)
|
|
|
|
|
|
return ret
|
|
|
@@ -60,6 +60,26 @@ class db():
|
|
|
pass
|
|
|
|
|
|
return ret
|
|
|
+
|
|
|
+ def update_pedido(self, productos, _hash, id_pedido):
|
|
|
+ clienteID = int(self.client(_hash)["id"])
|
|
|
+ cur = self.conn.cursor()
|
|
|
+
|
|
|
+ cur.execute( "SELECT 1 FROM pedidos where id = %s and cliente = %s", (id_pedido, clienteID) )
|
|
|
+ if not cur.fetchone():
|
|
|
+ print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
|
|
+ return
|
|
|
+
|
|
|
+ cur.execute( "DELETE FROM productos_pedido WHERE id_pedido = %s", (id_pedido,) )
|
|
|
+ subtotal = sum([ p["precio"]*p["cantidad"] for p in productos])
|
|
|
+ cantidad = sum([ p["cantidad"] for p in productos])
|
|
|
+
|
|
|
+ cur.execute("UPDATE pedidos SET cant_productos = %s, subtotal = %s, fecha=NOW() WHERE id = %s", ( cantidad, subtotal, id_pedido ))
|
|
|
+
|
|
|
+ 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)
|
|
|
+ self.conn.commit()
|
|
|
+
|
|
|
def create_pedido(self, productos, _hash):
|
|
|
clienteID = int(self.client(_hash)["id"])
|
|
|
|