feat(api): Refactor gpc_best_before_days function to include location mapping
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
742135ac67
commit
1db92e124a
28
app.py
28
app.py
@ -68,9 +68,13 @@ def add_product(dict_good, location):
|
||||
}
|
||||
|
||||
if ("gpc" in dict_good) and dict_good["gpc"]:
|
||||
best_before_days = gpc_best_before_days(int(dict_good["gpc"]))
|
||||
best_before_days, location_ = gpc_best_before_days_and_location(
|
||||
int(dict_good["gpc"]),
|
||||
locations)
|
||||
if best_before_days:
|
||||
data_grocy["default_best_before_days"] = best_before_days
|
||||
if location_:
|
||||
data_grocy["location_id"] = location_
|
||||
|
||||
# add product
|
||||
response_grocy = grocy.add_generic(EntityType.PRODUCTS, data_grocy)
|
||||
@ -125,7 +129,7 @@ def add_product(dict_good, location):
|
||||
return True
|
||||
|
||||
|
||||
def gpc_best_before_days(Code):
|
||||
def gpc_best_before_days_and_location(Code, locations):
|
||||
"""
|
||||
保质期(天) 类别
|
||||
7 50370000(中类,鲜切水果或蔬菜), 50380000(中类,鲜切水果或蔬菜), 50350000(中类,未处理或未加工的(新鲜)叶菜类蔬菜)
|
||||
@ -169,12 +173,30 @@ def gpc_best_before_days(Code):
|
||||
10100000,
|
||||
]
|
||||
|
||||
location_map = {item['name']: item['id'] for item in locations}
|
||||
for item in gpc_data["Schema"]:
|
||||
if item["Code"] == Code:
|
||||
title = item["Title-1"]
|
||||
location = locations[0]['name']
|
||||
if title == 'Food/Beverage/Tobacco':
|
||||
if item['Title-2'] in [
|
||||
'Bread/Bakery Products',
|
||||
]:
|
||||
location = '零食柜'
|
||||
else:
|
||||
location = '厨房'
|
||||
elif title in [
|
||||
'Beauty/Personal Care/Hygiene',
|
||||
'Cleaning/Hygiene Products',
|
||||
]:
|
||||
location = '浴室'
|
||||
elif title == 'Healthcare':
|
||||
location = '药柜'
|
||||
codes = [item["Code"], item["Code-1"], item["Code-2"], item["Code-3"]]
|
||||
for day, filter_codes in best_before_days.items():
|
||||
if any(code in filter_codes for code in codes):
|
||||
return day
|
||||
return day, location_map[location]
|
||||
return None, location_map[location]
|
||||
|
||||
|
||||
def convert_image_to_base64(image_content):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user