basket -> waybill
This commit is contained in:
@@ -14,7 +14,7 @@ def index():
|
|||||||
|
|
||||||
@waybill_bp.route('/clear', methods=['GET'])
|
@waybill_bp.route('/clear', methods=['GET'])
|
||||||
@check_auth
|
@check_auth
|
||||||
def clear_basket():
|
def clear_waybill():
|
||||||
clear()
|
clear()
|
||||||
return redirect(url_for('waybill_bp.index'))
|
return redirect(url_for('waybill_bp.index'))
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ class InfoRespronse:
|
|||||||
sql_provider = SQLProvider(os.path.join(os.path.dirname(__file__), 'sql'))
|
sql_provider = SQLProvider(os.path.join(os.path.dirname(__file__), 'sql'))
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
if session.get('basket',{}):
|
if session.get('waybill',{}):
|
||||||
session.pop('basket')
|
session.pop('waybill')
|
||||||
|
|
||||||
def workpiece_list() -> InfoRespronse:
|
def workpiece_list() -> InfoRespronse:
|
||||||
_sql = sql_provider.get('goods.sql', {})
|
_sql = sql_provider.get('goods.sql', {})
|
||||||
@@ -29,17 +29,17 @@ def workpiece_list() -> InfoRespronse:
|
|||||||
status=False)
|
status=False)
|
||||||
return InfoRespronse(result, error_message='', status=True)
|
return InfoRespronse(result, error_message='', status=True)
|
||||||
|
|
||||||
def form_basket() -> list:
|
def form_waybill() -> list:
|
||||||
current_basket = session.get('basket',{})
|
current_waybill = session.get('waybill',{})
|
||||||
basket = []
|
waybill = []
|
||||||
for k,v in current_basket.items():
|
for k,v in current_waybill.items():
|
||||||
_sql = sql_provider.get('one_good.sql', dict(prod_id=k))
|
_sql = sql_provider.get('one_good.sql', dict(prod_id=k))
|
||||||
product = select_list(current_app.config['db_config'], _sql)[0]
|
product = select_list(current_app.config['db_config'], _sql)[0]
|
||||||
product['amount'] = v
|
product['amount'] = v
|
||||||
basket.append(product)
|
waybill.append(product)
|
||||||
return basket
|
return waybill
|
||||||
|
|
||||||
def index_basket() -> list:
|
def index_waybill() -> list:
|
||||||
db_config = current_app.config['db_config']
|
db_config = current_app.config['db_config']
|
||||||
cache_config = current_app.config['cache_config']
|
cache_config = current_app.config['cache_config']
|
||||||
|
|
||||||
@@ -61,43 +61,43 @@ def button_click(request):
|
|||||||
product = result[0]
|
product = result[0]
|
||||||
|
|
||||||
if request.form.get('buy'):
|
if request.form.get('buy'):
|
||||||
if 'basket' not in session:
|
if 'waybill' not in session:
|
||||||
session['basket'] = dict()
|
session['waybill'] = dict()
|
||||||
|
|
||||||
if str(product['prod_id']) in session['basket']:
|
if str(product['prod_id']) in session['waybill']:
|
||||||
pr_id = product['prod_id']
|
pr_id = product['prod_id']
|
||||||
amount = int(session['basket'][str(pr_id)])
|
amount = int(session['waybill'][str(pr_id)])
|
||||||
session['basket'][str(pr_id)] = str(amount+1)
|
session['waybill'][str(pr_id)] = str(amount+1)
|
||||||
session.modified = True
|
session.modified = True
|
||||||
else:
|
else:
|
||||||
print("NEW PRODUCT")
|
print("NEW WORKPIECE")
|
||||||
pr_id = product['prod_id']
|
pr_id = product['prod_id']
|
||||||
session['basket'][str(pr_id)] = '1'
|
session['waybill'][str(pr_id)] = '1'
|
||||||
print(session['basket'])
|
print(session['waybill'])
|
||||||
session.modified = True
|
session.modified = True
|
||||||
|
|
||||||
elif request.form.get('product_display_plus'):
|
elif request.form.get('product_display_plus'):
|
||||||
# increasing count in basket
|
# increasing count in waybill
|
||||||
|
|
||||||
amount = int(session['basket'][str(product['prod_id'])])
|
amount = int(session['waybill'][str(product['prod_id'])])
|
||||||
session['basket'][str(product['prod_id'])] = str(amount + 1)
|
session['waybill'][str(product['prod_id'])] = str(amount + 1)
|
||||||
session.modified = True
|
session.modified = True
|
||||||
|
|
||||||
elif request.form.get('product_display_minus'):
|
elif request.form.get('product_display_minus'):
|
||||||
# decreasing count in basket
|
# decreasing count in waybill
|
||||||
|
|
||||||
amount = int(session['basket'][str(product['prod_id'])])
|
amount = int(session['waybill'][str(product['prod_id'])])
|
||||||
if amount == 1:
|
if amount == 1:
|
||||||
session['basket'].pop(str(product['prod_id']))
|
session['waybill'].pop(str(product['prod_id']))
|
||||||
else:
|
else:
|
||||||
session['basket'][str(product['prod_id'])] = str(amount-1)
|
session['waybill'][str(product['prod_id'])] = str(amount-1)
|
||||||
session.modified = True
|
session.modified = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def transaction_order_model(user_id: int, current_date: date):
|
def transaction_order_model(user_id: int, current_date: date):
|
||||||
|
|
||||||
db_config = current_app.config['db_config']
|
db_config = current_app.config['db_config']
|
||||||
basket = session.get('basket',{})
|
waybill = session.get('waybill',{})
|
||||||
|
|
||||||
# Чтобы всё это шло как одна транзакция
|
# Чтобы всё это шло как одна транзакция
|
||||||
with DBContextManager(db_config) as cursor:
|
with DBContextManager(db_config) as cursor:
|
||||||
@@ -111,7 +111,7 @@ def transaction_order_model(user_id: int, current_date: date):
|
|||||||
return InfoRespronse(tuple(), error_message="Заказ не был создан", status=False)
|
return InfoRespronse(tuple(), error_message="Заказ не был создан", status=False)
|
||||||
|
|
||||||
order_id = cursor.lastrowid
|
order_id = cursor.lastrowid
|
||||||
for key, value in basket.items():
|
for key, value in waybill.items():
|
||||||
_sql = sql_provider.get('insert_order_line.sql',
|
_sql = sql_provider.get('insert_order_line.sql',
|
||||||
dict(e_order_id = order_id,
|
dict(e_order_id = order_id,
|
||||||
e_prod_id = int(key),
|
e_prod_id = int(key),
|
||||||
|
|||||||
@@ -27,11 +27,11 @@
|
|||||||
<!-- Секция кнакладной -->
|
<!-- Секция кнакладной -->
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<h4>Накладная</h4>
|
<h4>Накладная</h4>
|
||||||
{% if basket %}
|
{% if waybill %}
|
||||||
{% for item in basket %}
|
{% for item in waybill %}
|
||||||
{{ components.render_item(item, show_form = False, show_amount = True) }}
|
{{ components.render_item(item, show_form = False, show_amount = True) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<a href="{{url_for('basket_bp.save_order')}}"><button class="btn btn-primary">Оформить накладную</button></a>
|
<a href="{{url_for('waybill_bp.save_order')}}"><button class="btn btn-primary">Оформить накладную</button></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span>Ваша накладная пуста</span>
|
<span>Ваша накладная пуста</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user