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