This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
RIS/App/Requests/requests.py
2024-11-04 21:57:55 +03:00

76 lines
3.1 KiB
Python

from flask import request, Blueprint, render_template
from os import path
from checker import check_auth, group_required
from .requests_model import sklad, get_goods, get_sellers, materials_per_seller
from datetime import date
import json
with open(path.join(path.dirname(__file__), 'zapros_menu.json')) as f:
requests_list = json.load(f)
requests_bp = Blueprint('requests_bp', __name__, template_folder='templates')
@requests_bp.route('/', methods=['GET', 'POST'])
@check_auth
@group_required
def requests():
if request.method == 'GET':
return render_template('zapros_menu.html', options=requests_list)
@requests_bp.route('/sklad', methods=['GET', 'POST'])
@check_auth
@group_required
def sklad_zapros():
if request.method == 'GET':
zagotovki = get_goods()
if zagotovki.status:
return render_template('zagotovki.html', materials=zagotovki.result, header='Количество заготовок на складе')
else:
return render_template('error.html', error_message=zagotovki.error_message)
else:
material = dict(request.form)
zagotovki = sklad(material)
if zagotovki.status:
header = f'Заготовки на складе из материала \'{material["material"]}\''
return render_template('output.html', items=zagotovki.result, object=header)
else:
return render_template('error.html', error_message=zagotovki.error_message)
# Под вопросом
""" @requests_bp.route('/req2', methods=['GET', 'POST'])
@check_auth
@group_required
def zagotovki_ship():
if request.method == 'GET':
zagotovki = get_goods()
if zagotovki.status:
return render_template('zagotovki.html', materials=zagotovki.result, header='Поставки заготовок')
else:
return render_template('error.html', error_message=zagotovki.error_message)
else:
material = dict(request.form)
zagotovki = route(material, 'zapros2.sql')
if zagotovki.status:
header = f'Поставки заготовок из материала \'{material['material']}\''
return render_template('output.html', items=zagotovki.result, object=header)
else:
return render_template('error.html', error_message=zagotovki.error_message) """
@requests_bp.route('/shipments', methods=['GET', 'POST'])
@check_auth
@group_required
def sellers_ship():
if request.method == 'GET':
zagotovki = get_sellers()
if zagotovki.status:
return render_template('sellers_ship.html', sellers=zagotovki.result, year_from='2000', year_to=str(date.today().year))
else:
return render_template('error.html', error_message=zagotovki.error_message)
else:
seller = dict(request.form)
zagotovki = materials_per_seller(seller)
if zagotovki.status:
header = f'Поставки от поставщика \'{seller['seller']}\''
return render_template('output.html', items=zagotovki.result, object=header)
else:
return render_template('error.html', error_message=zagotovki.error_message)