Waybill rewrite

This commit is contained in:
2024-12-10 01:23:41 +03:00
parent 13efda0c2a
commit 29d32bdc6f

View File

@@ -46,8 +46,6 @@ def index_waybill() -> list:
cache_select = fetch_from_cache("items_cached", cache_config)(select_list)
_sql = sql_provider.get("goods.sql", {})
products = cache_select(db_config, _sql)
if products is None:
return []
return products
@@ -97,33 +95,34 @@ def button_click(request):
return True
def transaction_order_model(user_id: int, current_date: date):
def transaction_order_model(user_id: int, current_date: date) -> InfoRespronse:
db_config = current_app.config["db_config"]
waybill = session.get("waybill", {})
total = session.get("total", 0)
result = None
# Чтобы всё это шло как одна транзакция
with DBContextManager(db_config) as cursor:
if cursor is None:
raise ValueError("Cursor not created")
data = dict(e_user_id=user_id, e_order_date=current_date, e_total=total)
try:
_sql = sql_provider.get("create_order.sql", data)
_sql = sql_provider.get("create_order.sql", data)
cursor.execute(_sql)
order_id = cursor.lastrowid
for key, value in waybill.items():
_sql = sql_provider.get(
"insert_order_line.sql",
dict(
e_order_id=order_id,
e_price=0,
e_prod_id=int(key),
e_amount=int(value),
),
)
cursor.execute(_sql)
order_id = cursor.lastrowid
for key, value in waybill.items():
_sql = sql_provider.get(
"insert_order_line.sql",
dict(
e_order_id=order_id,
e_price=0,
e_prod_id=int(key),
e_amount=int(value),
),
)
cursor.execute(_sql)
except:
return InfoRespronse((), error_message="Заказ не был создан", status=False)
result = tuple([order_id])
result = tuple([order_id])
if result is None:
return InfoRespronse((), error_message="Заказ не был создан", status=False)
clear()
return InfoRespronse(result, error_message="", status=True)