창고 이름 리스트를 콤보박스로 선택할 수 있는 기능 추가

ㄴ db에 재고(stock 테이블) 값 변경되도록 추가
This commit is contained in:
김민구
2024-01-22 17:12:18 +09:00
parent da618633b0
commit e9d1092222
2 changed files with 68 additions and 141 deletions

178
app.py
View File

@@ -8,13 +8,6 @@ import pymysql
import datetime
# import uuid
# 전역함수
global url
global group_number
global product_id
global warehouse_id
global manager_id
# DB 연결 설정 정보 세팅 ( db_config.ini에 정의 )
config = configparser.ConfigParser()
config.read(os.getcwd() + os.sep + 'db_config.ini', encoding='utf-8')
@@ -29,7 +22,7 @@ def dbcon():
db= config['DB_CONFIG']['DBNAME'],
charset="utf8")
def insert_data(quantity):
def insert_data(group_number, product_id, quantity, warehouse_id, manager_id):
try:
db = dbcon()
c = db.cursor()
@@ -49,7 +42,19 @@ def update_data(url):
db = dbcon()
c = db.cursor()
setdata = (url)
c.execute("UPDATE wms.plan_In SET clear = TRUE WHERE url=%s", setdata)
c.execute("UPDATE wms.plan_In SET clear = TRUE, activation = false WHERE url=%s", setdata)
db.commit()
except Exception as e:
print('db error:', e)
finally:
db.close()
def update_stock(warehouse_id, product_id, quantity):
try:
db = dbcon()
c = db.cursor()
setdata = (warehouse_id, product_id,warehouse_id,product_id, warehouse_id, product_id, quantity, warehouse_id,product_id,quantity)
c.execute("INSERT INTO wms.stock(id, warehouse_id, product_id, quantity, activation)VALUES(CASE WHEN( SELECT inner_stock.id from stock inner_stock where inner_stock.warehouse_id = %s and inner_stock.product_id = %s) is null THEN UUID() ELSE (SELECT inner_stock2.id from stock inner_stock2 where inner_stock2.warehouse_id = %s and inner_stock2.product_id = %s) END, %s, %s, %s, TRUE) ON DUPLICATE KEY UPDATE quantity = (SELECT quantity from stock s where s.warehouse_id = %s and s.product_id = %s) + %s", setdata)
db.commit()
except Exception as e:
print('db error:', e)
@@ -72,24 +77,25 @@ def select_all():
db.close()
return ret
# def select_num(url):
# ret = ()
# try:
# db = dbcon()
# #c = db.cursor()
# c = db.cursor(pymysql.cursors.DictCursor)
# setdata = (url)
# # c.execute('SELECT * FROM wms.plan_In WHERE url=%s', setdata)
# c.execute('SELECT * FROM wms.plan_In WHERE url=%s AND clear=0', setdata)
# ret = c.fetchall()
# except Exception as e:
# print('db error:', e)
# finally:
# db.close()
# return ret
def wh_select_all():
ret = list()
try:
db = dbcon()
# c = db.cursor()
c = db.cursor(pymysql.cursors.DictCursor)
#c.execute('SELECT * FROM wms.plan_In')
c.execute('SELECT * FROM wms.warehouse WHERE activation=1')
ret = c.fetchall()
# for row in c.execute('SELECT * FROM student'):
# ret.append(row)
except Exception as e:
print('db error:', e)
finally:
db.close()
return ret
def select_num(url):
ret = ()
ret = list()
try:
db = dbcon()
# c = db.cursor()
@@ -104,114 +110,28 @@ def select_num(url):
db.close()
return ret
# # # DB 연결
# # db = dbcon()
# # Tuple
# cur = conn.cursor()
# # DictCursor
# cur = conn.cursor(pymysql.cursors.DictCursor)
# # sql = f"""SELECT * FROM wms.plan_In2
# # """
# sql = f"""SELECT * FROM wms.plan_In2 where qr_hash=%s
# """
# cur.execute(sql, 'testqr')
# 데이터 접근
# result = cur.fetchall()
# rows = cur.fetchall()
# result = cur.fetchone()
# for record in result:
# print(record)
# 연결 종료
#conn.close()
# ret = select_num('485b02c0-b05e-11ee-935d-0242ac110006')
# for row in ret:
# # print(row)
# print(row['wh_name'], row['pd_name'])
# rows = [list(rows[x]) for x in range(len(rows))]
#------------------------------------------------
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
@app.route('/hello')
def hellohtml():
return render_template("hello.html")
@app.route('/hellos/<name>')
def hellos(name):
return "hellos {}".format(name)
@app.route('/input/<int:num>')
def input(num):
name = ''
if num == 1:
name = '도라에몽'
elif num == 2:
name = '진구'
elif num == 3:
name = '퉁퉁이'
return "hello {}".format(name)
app.route('/test')
def test1():
return 'test1'
@app.route('/test/')
def test2():
return 'test2'
@app.route('/naver')
def naver():
return render_template("naver.html")
@app.route('/kakao')
def daum():
return redirect("https://www.daum.net/")
@app.route('/urltest')
def url_test():
return redirect(url_for('daum'))
@app.route('/dora')
def myimage():
return render_template("myimage.html")
#@app.route('/form')
@app.route('/form/<string:str>')
@app.route('/qr/<string:str>')
#def formhtml():
def formhtml(str):
ret = select_num(str)
for row in ret:
print()
d = select_num(str)
row = d[0]
ret2 = wh_select_all()
global group_number
global product_id
global warehouse_id
global manager_id
global url
group_number = row['group_number']
product_id = row['product_id']
warehouse_id = row['warehouse_id']
manager_id = row['manager_id']
url = row['url']
# print(group_number, product_id, warehouse_id, manager_id)
# if str == 'f90aef8a-aecd-11ee-935d-0242ac110006':
# return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], quantity = row['quantity'])
# return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], name = row['name'], quantity = row['quantity'])
return render_template("form.html", date = row['date'], wh_name = row['wh_name'], quantity = row['quantity'], pd_name = row['pd_name'])
return render_template("form.html", date = row['date'], wh_name = row['wh_name'],
quantity = row['quantity'], pd_name = row['pd_name'], group_number = row['group_number'],
product_id = row['product_id'], warehouse_id = row['warehouse_id'], manager_id = row['manager_id'],
url = row['url'], server_list = ret2)
@app.route('/method', methods=['GET', 'POST'])
def method():
@@ -225,25 +145,23 @@ def method():
# num = request.form["num"]
# name = request.form["name"]
# return "POST로 전달된 데이터({}, {})".format(num, name)
if request.method == 'GET':
# args_dict = request.args.to_dict()
# print(args_dict)
date = request.args.get["date"]
warehouse_id = request.args.get("wh_name")
# name = request.args.get("name")
# return "GET으로 전달된 데이터({}, {})".format(date, warehouse_id, quantity, name)
return "GET으로 전달된 데이터({}, {}, {})".format(date, wh_name, quantity)
else:
date = request.form["date"]
wh_name = request.form["wh_name"]
warehouse_id = wh_name
quantity = request.form["quantity"]
pd_name = request.form["pd_name"]
insert_data(quantity)
group_number = request.form["group_number"]
product_id = request.form["product_id"]
manager_id = request.form["manager_id"]
url = request.form["url"]
insert_data(group_number, product_id, quantity, warehouse_id, manager_id)
update_data(url)
update_stock(warehouse_id, product_id, quantity)
return "POST로 전달된 데이터({}, {}, {}, {})".format(date, wh_name, quantity, pd_name)
# return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], quantity = row['quantity'])
if __name__ == '__main__':
with app.test_request_context():
print(url_for('daum'))
app.run()

View File

@@ -19,8 +19,17 @@
<form action="/method" method="POST">
<label for="date">날짜</label>
<input type="text" id="date" name="date" value="{{date}}" readonly><br><br>
<input hidden name="group_number" value="{{group_number}}">
<input hidden name="product_id" value="{{product_id}}">
<input hidden name="manager_id" value="{{manager_id}}">
<input hidden name="url" value="{{url}}">
<label for="wh_name">창고명</label>
<input type="text" id="wh_name" name="wh_name" value="{{wh_name}}" readonly><br><br>
<select name="wh_name" width="300px">
{% for x in server_list %}
<option value="{{ x.id }}"{% if x.id == warehouse_id %} SELECTED{% endif %}>{{ x.name }}</option>
{% endfor %}
</select><br><br>
<!-- <input type="text" id="wh_name" name="wh_name" value="{{wh_name}}" readonly><br><br> -->
<label for="pd_name">제품명</label>
<input type="text" id="pd_name" name="pd_name" value="{{pd_name}}" readonly><br><br>
<label for="quantity">제품수량</label>