Oprava endpointu poslednaZmenaDatFoodMan
This commit is contained in:
+27
-27
@@ -228,7 +228,7 @@ def init_tab_zakazky(cur):
|
|||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO zakazky (jmeno_zakazky, uzivatel, heslo) VALUES (?,?,?)",
|
"INSERT INTO zakazky (jmeno_zakazky, uzivatel, heslo) VALUES (?,?,?)",
|
||||||
("Alto", "Kobrle", p.code("heslo")) )
|
("Alto", "Kobrle", p.code("heslo")) )
|
||||||
|
|
||||||
def init_tab_heartbeat(cur):
|
def init_tab_heartbeat(cur):
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS heartbeat_clients (
|
CREATE TABLE IF NOT EXISTS heartbeat_clients (
|
||||||
@@ -301,7 +301,7 @@ def init_mapa_stolu_schema(prefix: str, cur):
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
data TEXT NOT NULL
|
data TEXT NOT NULL
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def seed_mapa_stolu_if_empty(prefix: str, cur):
|
def seed_mapa_stolu_if_empty(prefix: str, cur):
|
||||||
table = f"{prefix}_mapa_stolu"
|
table = f"{prefix}_mapa_stolu"
|
||||||
@@ -321,7 +321,7 @@ def seed_mapa_stolu_if_empty(prefix: str, cur):
|
|||||||
cur.execute(
|
cur.execute(
|
||||||
f'INSERT INTO "{table}" (data) VALUES (?)',
|
f'INSERT INTO "{table}" (data) VALUES (?)',
|
||||||
(raw_json,),
|
(raw_json,),
|
||||||
)
|
)
|
||||||
|
|
||||||
def init_tab_closerep(prefix: str, cur):
|
def init_tab_closerep(prefix: str, cur):
|
||||||
table = f"{prefix}_clsrep"
|
table = f"{prefix}_clsrep"
|
||||||
@@ -1215,7 +1215,7 @@ def default_payment_types() -> list[data.PaymentType]:
|
|||||||
rate=1.,allow_partial=True, is_cash=False,
|
rate=1.,allow_partial=True, is_cash=False,
|
||||||
handler=None, #charge_kredit_c.py,
|
handler=None, #charge_kredit_c.py,
|
||||||
color=None, is_default=False, is_bankterm=True,
|
color=None, is_default=False, is_bankterm=True,
|
||||||
),
|
),
|
||||||
data.PaymentType(
|
data.PaymentType(
|
||||||
code="EURO",
|
code="EURO",
|
||||||
name="Euro",
|
name="Euro",
|
||||||
@@ -1463,7 +1463,7 @@ def table_exists(table_name: str) -> bool:
|
|||||||
"SELECT 1 FROM sqlite_master WHERE type='table' AND name=?", (table_name,) )
|
"SELECT 1 FROM sqlite_master WHERE type='table' AND name=?", (table_name,) )
|
||||||
return cur.fetchone() is not None
|
return cur.fetchone() is not None
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
# FastApi Authentificacion
|
# FastApi Authentificacion
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
@@ -1807,10 +1807,10 @@ def posledna_zmena_dat_foodman(
|
|||||||
auth: tuple[str, str, str] = Depends(auth_ctx),
|
auth: tuple[str, str, str] = Depends(auth_ctx),
|
||||||
):
|
):
|
||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
logger.info(f"GET poslednaZmenaDatFoodMan: prefix={prefix} pokladna={id_kas}")
|
logger.info(f"GET poslednaZmenaDatFoodMan: prefix={prefix}")
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
return ensure_foodman_data_change_cur(cur, prefix, id_kas)
|
return ensure_foodman_data_change_cur(cur, prefix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1854,7 +1854,7 @@ def load_users_table(conn, prefix: str) -> list[dict]:
|
|||||||
"levels": json.loads(r[7] or "[]"),
|
"levels": json.loads(r[7] or "[]"),
|
||||||
"jazyk": r[8] or "sk",
|
"jazyk": r[8] or "sk",
|
||||||
})
|
})
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@app.post("/users/reset/")
|
@app.post("/users/reset/")
|
||||||
def reset_users_api(users: list[data.UserIn] = Body(...), id_kas: str = "",
|
def reset_users_api(users: list[data.UserIn] = Body(...), id_kas: str = "",
|
||||||
@@ -1882,7 +1882,7 @@ def reset_users_table(conn, prefix: str, users: list[data.UserIn]):
|
|||||||
cur.execute(f"DROP TABLE IF EXISTS {table}")
|
cur.execute(f"DROP TABLE IF EXISTS {table}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("INSERT ERROR:", e)
|
print("INSERT ERROR:", e)
|
||||||
raise
|
raise
|
||||||
try:
|
try:
|
||||||
# CREATE
|
# CREATE
|
||||||
cur.execute(f"""
|
cur.execute(f"""
|
||||||
@@ -1924,7 +1924,7 @@ def reset_users_table(conn, prefix: str, users: list[data.UserIn]):
|
|||||||
print("INSERT ERROR:", e)
|
print("INSERT ERROR:", e)
|
||||||
raise
|
raise
|
||||||
cur.execute(f"SELECT COUNT(*) FROM {table}")
|
cur.execute(f"SELECT COUNT(*) FROM {table}")
|
||||||
print("POCET VLOZENYCH USERU:", cur.fetchone())
|
print("POCET VLOZENYCH USERU:", cur.fetchone())
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def init_limit_locks_schema(prefix: str, cur) -> None:
|
def init_limit_locks_schema(prefix: str, cur) -> None:
|
||||||
@@ -9375,7 +9375,7 @@ def save_mapa_stolu(
|
|||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
logger.info(f"POST mapa_stolu: prefix={prefix} pokladny={mapa.pokladny}")
|
logger.info(f"POST mapa_stolu: prefix={prefix} pokladny={mapa.pokladny}")
|
||||||
save_mapa_to_db(prefix, mapa)
|
save_mapa_to_db(prefix, mapa)
|
||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|
||||||
def save_mapa_to_db(cur_pref: str, mapa: data.MapaStolu):
|
def save_mapa_to_db(cur_pref: str, mapa: data.MapaStolu):
|
||||||
table = f"{cur_pref}_mapa_stolu"
|
table = f"{cur_pref}_mapa_stolu"
|
||||||
@@ -9595,7 +9595,7 @@ def upsert_ucet_db(cur_pref: str, uct: data.Ucet, client_id: str, block: bool):
|
|||||||
uct.c_uzaverka = c_uzaverka_db
|
uct.c_uzaverka = c_uzaverka_db
|
||||||
if blocked_by_db:
|
if blocked_by_db:
|
||||||
#Petr 8.5.
|
#Petr 8.5.
|
||||||
owner = blocked_by_db.split("|", 1)[0] if blocked_by_db else ""
|
owner = blocked_by_db.split("|", 1)[0] if blocked_by_db else ""
|
||||||
#Petr 8.5.2026 ^
|
#Petr 8.5.2026 ^
|
||||||
if owner != client_id:
|
if owner != client_id:
|
||||||
# kontrola expirace blocku
|
# kontrola expirace blocku
|
||||||
@@ -9612,7 +9612,7 @@ def upsert_ucet_db(cur_pref: str, uct: data.Ucet, client_id: str, block: bool):
|
|||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
409,
|
409,
|
||||||
f"Otevřený účet ke stolu {uct.stul} je blokován: {blocked_by_db}"
|
f"Otevřený účet ke stolu {uct.stul} je blokován: {blocked_by_db}"
|
||||||
)
|
)
|
||||||
# historický účet – povol jen update pole storno
|
# historický účet – povol jen update pole storno
|
||||||
strip_transient_hotel_charge_data(uct)
|
strip_transient_hotel_charge_data(uct)
|
||||||
ensure_ucet_room_name(cur_pref, uct)
|
ensure_ucet_room_name(cur_pref, uct)
|
||||||
@@ -9644,7 +9644,7 @@ def upsert_ucet_db(cur_pref: str, uct: data.Ucet, client_id: str, block: bool):
|
|||||||
if blocked_by_db:
|
if blocked_by_db:
|
||||||
owner = blocked_by_db.split("|", 1)[0]
|
owner = blocked_by_db.split("|", 1)[0]
|
||||||
#if owner != client_id:
|
#if owner != client_id:
|
||||||
# raise HTTPException(409, f"Ucet blocked by {blocked_by_db}")
|
# raise HTTPException(409, f"Ucet blocked by {blocked_by_db}")
|
||||||
if owner != client_id:
|
if owner != client_id:
|
||||||
# kontrola expirace blocku
|
# kontrola expirace blocku
|
||||||
if is_block_expired(cur, cur_pref, id_kas, blocked_by_db):
|
if is_block_expired(cur, cur_pref, id_kas, blocked_by_db):
|
||||||
@@ -9710,13 +9710,13 @@ def upsert_ucet_db(cur_pref: str, uct: data.Ucet, client_id: str, block: bool):
|
|||||||
"ucislo": uct.ucislo,
|
"ucislo": uct.ucislo,
|
||||||
"blocked": bool(new_block),
|
"blocked": bool(new_block),
|
||||||
}, uct)
|
}, uct)
|
||||||
|
|
||||||
# ---pripoji ucet k existujicimu
|
# ---pripoji ucet k existujicimu
|
||||||
@app.post("/ucet/merge/")
|
@app.post("/ucet/merge/")
|
||||||
def merge_ucet( req: data.MergeUcetRequest, auth: tuple[str, str, str] = Depends(auth_ctx),):
|
def merge_ucet( req: data.MergeUcetRequest, auth: tuple[str, str, str] = Depends(auth_ctx),):
|
||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
if not (id_kas := req.ucet.id_kas):
|
if not (id_kas := req.ucet.id_kas):
|
||||||
raise HTTPException(422, "id_kas in object Ucet must be set")
|
raise HTTPException(422, "id_kas in object Ucet must be set")
|
||||||
cleanup_dead_clients(prefix, id_kas)
|
cleanup_dead_clients(prefix, id_kas)
|
||||||
if not req.target_stul:
|
if not req.target_stul:
|
||||||
raise HTTPException(422, "target_stul must be set")
|
raise HTTPException(422, "target_stul must be set")
|
||||||
@@ -9726,7 +9726,7 @@ def merge_ucet( req: data.MergeUcetRequest, auth: tuple[str, str, str] = Depends
|
|||||||
source=req.ucet,
|
source=req.ucet,
|
||||||
target_stul=req.target_stul,
|
target_stul=req.target_stul,
|
||||||
client_id=client_id, )
|
client_id=client_id, )
|
||||||
|
|
||||||
def merge_polozky(target: list, incoming: list):
|
def merge_polozky(target: list, incoming: list):
|
||||||
"""
|
"""
|
||||||
Přidá položky z incoming do target.
|
Přidá položky z incoming do target.
|
||||||
@@ -9735,7 +9735,7 @@ def merge_polozky(target: list, incoming: list):
|
|||||||
if not incoming:
|
if not incoming:
|
||||||
return
|
return
|
||||||
target.extend(incoming)
|
target.extend(incoming)
|
||||||
|
|
||||||
def merge_ucet_db(
|
def merge_ucet_db(
|
||||||
cur_pref: str,
|
cur_pref: str,
|
||||||
id_kas: str,
|
id_kas: str,
|
||||||
@@ -9794,7 +9794,7 @@ def merge_ucet_db(
|
|||||||
)
|
)
|
||||||
# --- načti cílový účet ---
|
# --- načti cílový účet ---
|
||||||
if not data_db:
|
if not data_db:
|
||||||
raise HTTPException(500, "Cílový účet nemá data")
|
raise HTTPException(500, "Cílový účet nemá data")
|
||||||
if isinstance(data_db, str):
|
if isinstance(data_db, str):
|
||||||
target_payload = json.loads(data_db)
|
target_payload = json.loads(data_db)
|
||||||
elif isinstance(data_db, dict):
|
elif isinstance(data_db, dict):
|
||||||
@@ -9851,7 +9851,7 @@ def merge_ucet_db(
|
|||||||
"created": True,
|
"created": True,
|
||||||
"merged_items": len(source.poloz or []),
|
"merged_items": len(source.poloz or []),
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---nacte ucet ze serveru, bud dle stul (otevreny) nebo ucislo (uzavreny)
|
# ---nacte ucet ze serveru, bud dle stul (otevreny) nebo ucislo (uzavreny)
|
||||||
@app.get("/ucet/")
|
@app.get("/ucet/")
|
||||||
def get_ucet(
|
def get_ucet(
|
||||||
@@ -9999,7 +9999,7 @@ def delete_ucet(
|
|||||||
id_kas: str = Query(...),
|
id_kas: str = Query(...),
|
||||||
auth: tuple[str, str, str] = Depends(auth_ctx),):
|
auth: tuple[str, str, str] = Depends(auth_ctx),):
|
||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
cleanup_dead_clients(prefix, id_kas)
|
cleanup_dead_clients(prefix, id_kas)
|
||||||
logger.info(f'Ucet delete {stul}')
|
logger.info(f'Ucet delete {stul}')
|
||||||
if (ucislo is None) == (stul is None):
|
if (ucislo is None) == (stul is None):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -10143,7 +10143,7 @@ def load_ucty_for_select(
|
|||||||
CASE WHEN u.stul IS NULL THEN 1 ELSE 0 END,
|
CASE WHEN u.stul IS NULL THEN 1 ELSE 0 END,
|
||||||
u.stul
|
u.stul
|
||||||
"""
|
"""
|
||||||
limit_sql = ""
|
limit_sql = ""
|
||||||
# --- SQL ---
|
# --- SQL ---
|
||||||
sql = f"""
|
sql = f"""
|
||||||
SELECT
|
SELECT
|
||||||
@@ -10486,7 +10486,7 @@ def block_ucet_by_stul(
|
|||||||
stul: str = Query(...), id_kas: str = Query(...),
|
stul: str = Query(...), id_kas: str = Query(...),
|
||||||
auth: tuple[str, str, str] = Depends(auth_ctx)):
|
auth: tuple[str, str, str] = Depends(auth_ctx)):
|
||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
cleanup_dead_clients(prefix, id_kas)
|
cleanup_dead_clients(prefix, id_kas)
|
||||||
logger.info(f'Ucet block {stul}')
|
logger.info(f'Ucet block {stul}')
|
||||||
return db_block_ucet_by_stul(prefix, stul, id_kas, client_id)
|
return db_block_ucet_by_stul(prefix, stul, id_kas, client_id)
|
||||||
|
|
||||||
@@ -10744,7 +10744,7 @@ def open_block_create_ucet_db(
|
|||||||
}
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
# Uzaverka
|
# Uzaverka
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
def ensure_closure_runtime_schema(prefix: str, cur) -> None:
|
def ensure_closure_runtime_schema(prefix: str, cur) -> None:
|
||||||
init_tab_closerep(prefix=prefix, cur=cur)
|
init_tab_closerep(prefix=prefix, cur=cur)
|
||||||
@@ -12162,7 +12162,7 @@ def cen_load_for_pokl(prefix, pokl):
|
|||||||
result.append(obj)
|
result.append(obj)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@app.delete("/cenik/pokl/{pokl}", status_code=204)
|
@app.delete("/cenik/pokl/{pokl}", status_code=204)
|
||||||
def delete_cenik_pokl(pokl: str, auth: tuple[str, str, str] = Depends(auth_ctx)):
|
def delete_cenik_pokl(pokl: str, auth: tuple[str, str, str] = Depends(auth_ctx)):
|
||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
@@ -12181,7 +12181,7 @@ def cenik_delete_pokl(cur_pref: str, pokl: str) -> bool:
|
|||||||
def replace_cenik(cenik: data.Cenik, auth: tuple[str, str, str] = Depends(auth_ctx)):
|
def replace_cenik(cenik: data.Cenik, auth: tuple[str, str, str] = Depends(auth_ctx)):
|
||||||
prefix, user, client_id = auth
|
prefix, user, client_id = auth
|
||||||
cenik_replace(prefix, cenik)
|
cenik_replace(prefix, cenik)
|
||||||
|
|
||||||
def cenik_replace(cur_pref: str, cenik: data.Cenik) -> None:
|
def cenik_replace(cur_pref: str, cenik: data.Cenik) -> None:
|
||||||
table = f"{cur_pref}_cenik"
|
table = f"{cur_pref}_cenik"
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
@@ -12489,4 +12489,4 @@ def migrate_ucet_payload(payload: dict):
|
|||||||
aa=data.Ucet(autor="Petr Kobrle", poloz=[])
|
aa=data.Ucet(autor="Petr Kobrle", poloz=[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user