Waybill rewrite
This commit is contained in:
@@ -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,15 +95,17 @@ 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)
|
||||
cursor.execute(_sql)
|
||||
|
||||
@@ -121,9 +121,8 @@ def transaction_order_model(user_id: int, current_date: date):
|
||||
),
|
||||
)
|
||||
cursor.execute(_sql)
|
||||
except:
|
||||
return InfoRespronse((), error_message="Заказ не был создан", status=False)
|
||||
|
||||
result = tuple([order_id])
|
||||
if result is None:
|
||||
return InfoRespronse((), error_message="Заказ не был создан", status=False)
|
||||
clear()
|
||||
return InfoRespronse(result, error_message="", status=True)
|
||||
|
||||
Reference in New Issue
Block a user