update product stock tests
This commit is contained in:
parent
a5c6b1135c
commit
7c8e3de261
3 changed files with 26 additions and 18 deletions
|
|
@ -1,10 +1,7 @@
|
||||||
import re
|
|
||||||
from base64 import urlsafe_b64encode
|
from base64 import urlsafe_b64encode
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
# from lnbits.db import open_ext_db
|
# from lnbits.db import open_ext_db
|
||||||
from lnbits.db import SQLITE
|
from lnbits.db import SQLITE
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
@ -291,6 +288,22 @@ async def set_diagonalley_order_paid(payment_hash: str) -> Orders:
|
||||||
(payment_hash,),
|
(payment_hash,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def update_diagonalley_product_stock(products):
|
||||||
|
|
||||||
|
q = "\n".join([f"""WHEN id='{p["product_id"]}' THEN {p["quantity"]}""" for p in products])
|
||||||
|
v = ",".join(["?"] * len(products))
|
||||||
|
|
||||||
|
await db.execute(
|
||||||
|
f"""
|
||||||
|
UPDATE diagonalley.products
|
||||||
|
SET quantity=(CASE
|
||||||
|
{q}
|
||||||
|
END)
|
||||||
|
WHERE id IN ({v});
|
||||||
|
""",
|
||||||
|
(*[p["product_id"] for p in products],)
|
||||||
|
)
|
||||||
|
|
||||||
async def get_diagonalley_orders(wallet_ids: Union[str, List[str]]) -> List[Orders]:
|
async def get_diagonalley_orders(wallet_ids: Union[str, List[str]]) -> List[Orders]:
|
||||||
if isinstance(wallet_ids, str):
|
if isinstance(wallet_ids, str):
|
||||||
wallet_ids = [wallet_ids]
|
wallet_ids = [wallet_ids]
|
||||||
|
|
|
||||||
|
|
@ -30,19 +30,6 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
await set_diagonalley_order_paid(payment.payment_hash)
|
await set_diagonalley_order_paid(payment.payment_hash)
|
||||||
|
|
||||||
# deduct items sold from stock
|
# deduct items sold from stock
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
if "lnticket" != payment.extra.get("tag"):
|
|
||||||
# not a lnticket invoice
|
|
||||||
return
|
|
||||||
|
|
||||||
ticket = await get_ticket(payment.checking_id)
|
|
||||||
if not ticket:
|
|
||||||
print("this should never happen", payment)
|
|
||||||
return
|
|
||||||
|
|
||||||
await payment.set_pending(False)
|
|
||||||
await set_ticket_paid(payment.payment_hash)
|
|
||||||
"""
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from .crud import (
|
||||||
get_diagonalley_stall,
|
get_diagonalley_stall,
|
||||||
get_diagonalley_zone,
|
get_diagonalley_zone,
|
||||||
get_diagonalley_zones,
|
get_diagonalley_zones,
|
||||||
|
update_diagonalley_product_stock,
|
||||||
)
|
)
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
templates = Jinja2Templates(directory="templates")
|
||||||
|
|
@ -31,6 +32,13 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
|
|
||||||
@diagonalley_ext.get("/{stall_id}", response_class=HTMLResponse)
|
@diagonalley_ext.get("/{stall_id}", response_class=HTMLResponse)
|
||||||
async def display(request: Request, stall_id):
|
async def display(request: Request, stall_id):
|
||||||
|
# test_qty = 99
|
||||||
|
# test = [
|
||||||
|
# {"product_id": "55vpVjWAuQExHsJxT28MYe", "quantity": test_qty},
|
||||||
|
# {"product_id": "f2eGNsEWgbLJbfAApd3Jw5", "quantity": test_qty},
|
||||||
|
# {"product_id": "FVqZLZdemWCsiqe9gafvsC", "quantity": test_qty},
|
||||||
|
# ]
|
||||||
|
# await update_diagonalley_product_stock(test)
|
||||||
stall = await get_diagonalley_stall(stall_id)
|
stall = await get_diagonalley_stall(stall_id)
|
||||||
products = await get_diagonalley_products(stall_id)
|
products = await get_diagonalley_products(stall_id)
|
||||||
zones = []
|
zones = []
|
||||||
|
|
@ -43,7 +51,7 @@ async def display(request: Request, stall_id):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Stall does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="Stall does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
stall = stall.dict()
|
stall = stall.dict()
|
||||||
del stall["privatekey"]
|
del stall["privatekey"]
|
||||||
stall["zones"] = zones
|
stall["zones"] = zones
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue