From e28ccaab143edcb8232cec2b9ef70887d173b47a Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Wed, 4 Dec 2024 18:05:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BB=D1=8F=20=D1=81=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D0=B3=D0=B3=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Waybill/model.py | 35 ++++++++++++--------------- App/Waybill/sql/good_price.sql | 1 + App/Waybill/sql/insert_order_line.sql | 3 +-- 3 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 App/Waybill/sql/good_price.sql 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