change result to dict

This commit is contained in:
bcomsugi 2023-10-11 03:17:51 +07:00
parent 3ca1b27b22
commit 6521a0cd4b

31
main.py
View File

@ -13,6 +13,8 @@ import pdfexcel4DNwithxlrd
from ItemInventoryQuery import ItemInventoryQuery from ItemInventoryQuery import ItemInventoryQuery
from SO_to_Inv import readSO from SO_to_Inv import readSO
import os import os
from icecream import ic
import pprint
# app = FastAPI() # app = FastAPI()
app = FastAPI(docs_url="/itemreceipt", redoc_url=None) app = FastAPI(docs_url="/itemreceipt", redoc_url=None)
@ -89,15 +91,38 @@ async def create_upload_file(uploaded_file: UploadFile):
status = "OK" status = "OK"
else: else:
print("ERROR", status_msg) print("ERROR", status_msg)
print(f"ret:{ret}", type(ret))
status = "ERROR" status = "ERROR"
msg = f"ERROR. replyfromqbxml:{ret}" msg = f"ERROR. replyfromqbxml:{ret}"
msg = f"{status}. replyfrom qbxml:{ret}" msg = f"{status}. replyfrom qbxml:{ret}"
else: else:
print("create_upload_file->not all DN are added") print("create_upload_file->not all DN are added")
msg = f"Error. not all DN are added. \n these items not added in the list :\n{notinthelist}" # ic(notinthelist)
status = 'Error' # errmsg = ic(notinthelist)
# errmsg = pprint.pprint(notinthelist)
# errmsg = str(errmsg)
# print(errmsg, type(errmsg))
errmsg = json.dumps(notinthelist, indent=2, sort_keys=True)
errmsg = json.loads(errmsg)
return {"info": f"file '{uploaded_file.filename}' saved at '{file_location}'", "status": status, "msg": msg} # print(errmsg, type(errmsg))
print(type(errmsg))
# msg = f"Error. not all DN are added. \n these items not added in the list :\n{notinthelist}"
msg = f"Error. not all DN are added. \n these items not added in the list :\n{errmsg}"
status = 'Error'
msgdict={}
msgdict["info"]=f'file {uploaded_file.filename} saved at {file_location}'
msgdict["status"]=status
msgdict["msg"]=errmsg
print(msgdict, type(msg))
# jsonmsg = json.dumps(msgdict)
# jsonmsg = json.loads(jsonmsg)
return msgdict
return [{"info": f"file '{uploaded_file.filename}' saved at '{file_location}'", "status": status, "msg": msg}]
return {"info": f"file '{uploaded_file.filename}' is not Excel(.xls) file or it is not Delivery Note(TCO-DN)file. please upload the correct file", "status": status} return {"info": f"file '{uploaded_file.filename}' is not Excel(.xls) file or it is not Delivery Note(TCO-DN)file. please upload the correct file", "status": status}
@app.post('/getopenso') @app.post('/getopenso')