diff --git a/App/Waybill/model.py b/App/Waybill/model.py index 63cf7d0..48d4488 100644 --- a/App/Waybill/model.py +++ b/App/Waybill/model.py @@ -72,13 +72,6 @@ def button_click(request): print(session['waybill']) session.modified = True - # elif request.form.get('product_display_plus'): - # # increasing count in waybill - - # amount = int(session['waybill'][str(product['work_id'])]) - # session['waybill'][str(product['work_id'])] = str(amount + 1) - # session.modified = True - elif request.form.get('product_display_minus'): # decreasing count in waybill @@ -101,23 +94,25 @@ def transaction_order_model(user_id: int, current_date: date): with DBContextManager(db_config) as cursor: data = dict(e_user_id=user_id, e_order_date=current_date, e_total=total) - - _sql = sql_provider.get('create_order.sql', data) try: + _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('good_price.sql', dict( + e_prod_id = int(key) + )) + price = select_list(db_config, _sql)[0][0] + + _sql = sql_provider.get('insert_order_line.sql', + dict(e_order_id = order_id, + e_price = price, + e_prod_id = int(key), + e_amount = int(value))) + cursor.execute(_sql) except: return InfoRespronse((), error_message="Заказ не был создан", status=False) - - 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_prod_id = int(key), - e_amount = int(value))) - try: - cursor.execute(_sql) - except: - return InfoRespronse((), error_message="Заказ не был создан", status=False) result = tuple([order_id]) clear() diff --git a/App/Waybill/sql/good_price.sql b/App/Waybill/sql/good_price.sql new file mode 100644 index 0000000..d01f1ec --- /dev/null +++ b/App/Waybill/sql/good_price.sql @@ -0,0 +1 @@ +SELECT price FROM workpiece WHERE work_id = $e_prod_id \ No newline at end of file diff --git a/App/Waybill/sql/insert_order_line.sql b/App/Waybill/sql/insert_order_line.sql index 26091a8..4eaeb65 100644 --- a/App/Waybill/sql/insert_order_line.sql +++ b/App/Waybill/sql/insert_order_line.sql @@ -1,2 +1 @@ -INSERT INTO `waybill_lines` VALUES ($e_order_id, $e_prod_id, -(SELECT price FROM workpiece WHERE work_id = $e_prod_id), $e_amount); \ No newline at end of file +INSERT INTO `waybill_lines` VALUES ($e_order_id, $e_prod_id, $e_price, $e_amount); \ No newline at end of file