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)
|
cache_select = fetch_from_cache("items_cached", cache_config)(select_list)
|
||||||
_sql = sql_provider.get("goods.sql", {})
|
_sql = sql_provider.get("goods.sql", {})
|
||||||
products = cache_select(db_config, _sql)
|
products = cache_select(db_config, _sql)
|
||||||
if products is None:
|
|
||||||
return []
|
|
||||||
|
|
||||||
return products
|
return products
|
||||||
|
|
||||||
@@ -97,33 +95,34 @@ def button_click(request):
|
|||||||
return True
|
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"]
|
db_config = current_app.config["db_config"]
|
||||||
waybill = session.get("waybill", {})
|
waybill = session.get("waybill", {})
|
||||||
total = session.get("total", 0)
|
total = session.get("total", 0)
|
||||||
|
result = None
|
||||||
|
|
||||||
# Чтобы всё это шло как одна транзакция
|
# Чтобы всё это шло как одна транзакция
|
||||||
with DBContextManager(db_config) as cursor:
|
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)
|
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)
|
cursor.execute(_sql)
|
||||||
|
result = tuple([order_id])
|
||||||
order_id = cursor.lastrowid
|
if result is None:
|
||||||
for key, value in waybill.items():
|
return InfoRespronse((), error_message="Заказ не был создан", status=False)
|
||||||
_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])
|
|
||||||
clear()
|
clear()
|
||||||
return InfoRespronse(result, error_message="", status=True)
|
return InfoRespronse(result, error_message="", status=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user