Commit 1eff871a by Aeolus

update

parent a25281bc
...@@ -238,7 +238,7 @@ def get_tallyman_hatch_list(): ...@@ -238,7 +238,7 @@ def get_tallyman_hatch_list():
"machine_no": i.machine_no, "machine_no": i.machine_no,
"hatch_no": i.hatch_no, "hatch_no": i.hatch_no,
"production_id": i.production_id, "production_id": i.production_id,
"name": i.name, "name": i.production_name,
"status": i.status, "status": i.status,
"left_count": i.left_count, "left_count": i.left_count,
"total_count": i.total_count "total_count": i.total_count
...@@ -281,7 +281,7 @@ def run_tally_start(): ...@@ -281,7 +281,7 @@ def run_tally_start():
tally_record.machine_no = i.machine_no tally_record.machine_no = i.machine_no
tally_record.hatch_no = i.hatch_no tally_record.hatch_no = i.hatch_no
tally_record.production_id = i.production_id tally_record.production_id = i.production_id
tally_record.production_name = i.name tally_record.production_name = i.production_name
tally_record.tally_count = i.total_count - i.left_count if i.left_count > 0 else i.total_count tally_record.tally_count = i.total_count - i.left_count if i.left_count > 0 else i.total_count
tally_record.status = 1 tally_record.status = 1
db.session.add(tally_record) db.session.add(tally_record)
......
...@@ -43,14 +43,15 @@ def run_production_list(): ...@@ -43,14 +43,15 @@ def run_production_list():
count_sql = "select count(p.id) as total_count" count_sql = "select count(p.id) as total_count"
from_sql = """ from production p from_sql = """ from production p
left join brand on p.brand_id = brand.id left join brand on p.brand_id = brand.id
left join production_type on p.production_type_id = production_type.id left join production_type on p.production_type_id = production_type.id
where p.id in ( select production_id from admin_production where """
admin_production.user_id = {} and admin_production.status = 1
)
""".format(admin.id)
where_sql = " " if g.user.level == 1:
where_sql = " where 0=0"
else:
where_sql = """ where p.id in ( select production_id from admin_production where
admin_production.user_id = {} and admin_production.status = 1
)""".format(admin.id)
if keyword: if keyword:
where_sql += """ where_sql += """
and CONCAT(p.production_name, brand_name,production_type_name, p.production_no) LIKE '%{keyword}%' and CONCAT(p.production_name, brand_name,production_type_name, p.production_no) LIKE '%{keyword}%'
...@@ -68,12 +69,6 @@ def run_production_list(): ...@@ -68,12 +69,6 @@ def run_production_list():
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall() result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
"""
select p.id, p.production_no, p.name, p.title, p.brand_id,p.production_type_id, p.price,p.original_price,
p.weight, p.weight_unit, p.expiration_date, p.expiration_date_unit, p.is_expiration_date,
p.weight_error, p.img, p.tags, p.content,p.summary, p.status,
brand.name as brand_name, production_type.name as production_type_name
"""
return_data = [] return_data = []
for info in result: for info in result:
return_data.append( return_data.append(
...@@ -231,15 +226,17 @@ def get_production_detail(): ...@@ -231,15 +226,17 @@ def get_production_detail():
""" """
from_sql = """ from production p from_sql = """ from production p
left join brand on p.brand_id = brand.id left join brand on p.brand_id = brand.id
left join production_type on p.production_type_id = production_type.id left join production_type on p.production_type_id = production_type.id
where p.id in ( """
if g.user.level == 1:
where_sql = " where 0=0"
else:
where_sql = """ where p.id in (
select production_id from admin_production where select production_id from admin_production where
admin_production.user_id = {} and admin_production.status = 1 admin_production.user_id = {} and admin_production.status = 1
) )""".format(admin.id)
where_sql += " and p.id={}".format(production_id)
""".format(admin.id)
where_sql = " and p.id={}".format(production_id)
result = db.session.execute(select_sql + from_sql + where_sql).fetchall() result = db.session.execute(select_sql + from_sql + where_sql).fetchall()
if not result or len(result) != 1: if not result or len(result) != 1:
...@@ -276,13 +273,15 @@ def run_brand_list(): ...@@ -276,13 +273,15 @@ def run_brand_list():
select_sql = """select b.id, b.brand_name,b.status, b.img select_sql = """select b.id, b.brand_name,b.status, b.img
""" """
count_sql = "select count(b.id) as total_count" count_sql = "select count(b.id) as total_count"
from_sql = """ from brand b where b.id in ( from_sql = """ from brand b
select brand_id from admin_brand where """
admin_brand.user_id = {} and admin_brand.status = 1 if g.user.level == 1:
) where_sql = " where 0=0"
""".format(admin.id) else:
where_sql = """ where b.id in (
where_sql = "" select brand_id from admin_brand where
admin_brand.user_id = {} and admin_brand.status = 1
)""".format(admin.id)
if keyword: if keyword:
where_sql += """ where_sql += """
and CONCAT( b.brand_name) LIKE '%{keyword}%' and CONCAT( b.brand_name) LIKE '%{keyword}%'
...@@ -373,8 +372,14 @@ def get_brand_detail(): ...@@ -373,8 +372,14 @@ def get_brand_detail():
select_sql = """select b.id,b.brand_name,b.status, b.img select_sql = """select b.id,b.brand_name,b.status, b.img
""" """
from_sql = """ from brand b """ from_sql = """ from brand b """
if g.user.level == 1:
where_sql = " where b.id ={}".format(brand_id) where_sql = " where 0=0"
else:
where_sql = """ where b.id in (
select brand_id from admin_brand where
admin_brand.user_id = {} and admin_brand.status = 1
)""".format(admin.id)
where_sql += " and b.id ={}".format(brand_id)
result = db.session.execute(select_sql + from_sql + where_sql).fetchall() result = db.session.execute(select_sql + from_sql + where_sql).fetchall()
if not result or len(result) != 1: if not result or len(result) != 1:
...@@ -403,13 +408,16 @@ def run_production_type_list(): ...@@ -403,13 +408,16 @@ def run_production_type_list():
select_sql = """select p.id, p.production_type_name,p.status select_sql = """select p.id, p.production_type_name,p.status
""" """
count_sql = "select count(p.id) as total_count" count_sql = "select count(p.id) as total_count"
from_sql = """ from production_type p where p.id in ( from_sql = """ from production_type p
"""
if g.user.level == 1:
where_sql = " where 0=0"
else:
where_sql = """ where p.id in (
select production_type_id from admin_production_type where select production_type_id from admin_production_type where
admin_production_type.user_id = {} and admin_production_type.status = 1 admin_production_type.user_id = {} and admin_production_type.status = 1
) )
""".format(admin.id) )""".format(admin.id)
where_sql = " "
if keyword: if keyword:
where_sql += """ where_sql += """
and CONCAT( p.production_type_name) LIKE '%{keyword}%' and CONCAT( p.production_type_name) LIKE '%{keyword}%'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment