Checks report results for '$', strips it converts string to float. Added item detail tab, pulls in detail tab heads and writes to the spreadsheet.

This commit is contained in:
Dan Dembinski
2019-06-21 15:45:48 -04:00
parent 4d97c8aeb7
commit 4d775482c2

87
main.py
View File

@@ -40,12 +40,14 @@ def Release_Ticket(ticket, URL, HOST):
response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text
# print("released ticket "+ticket) # print("released ticket "+ticket)
def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS):
ExternalID = [] ExternalID = []
id = [] id = []
shippingcost = [] shippingcost = []
############# Order Summary tab #############
report_filter = """ <filterNameOrXml>&lt;?xml version="1.0"?&gt; &lt;PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Orders"&gt; &lt;PFWebFilter:Step publicFieldName="Balance Due" query="ExactUnequals" minValue="0.00" maxValue="" /&gt; &lt;PFWebFilter:Step publicFieldName="Order Status" query="ExactEquals" minValue="Completed" maxValue="" /&gt; &lt;/PFWebFilter:UserFilter&gt;</filterNameOrXml> report_filter = """ <filterNameOrXml>&lt;?xml version="1.0"?&gt; &lt;PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Orders"&gt; &lt;PFWebFilter:Step publicFieldName="Balance Due" query="ExactUnequals" minValue="0.00" maxValue="" /&gt; &lt;PFWebFilter:Step publicFieldName="Order Status" query="ExactEquals" minValue="Completed" maxValue="" /&gt; &lt;/PFWebFilter:UserFilter&gt;</filterNameOrXml>
""" """
@@ -62,7 +64,6 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb):
</GetReport> </GetReport>
</soap12:Body> </soap12:Body>
</soap12:Envelope>""" </soap12:Envelope>"""
# print(send)
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length', 'SOAPAction': 'http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111/GetReport'} headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length', 'SOAPAction': 'http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111/GetReport'}
@@ -78,7 +79,12 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb):
# Opens report file and writes each row # Opens report file and writes each row
for child in y.report: for child in y.report:
for childs in child: for childs in child:
results.append(childs.text) if '$' in childs.text:
convert = childs.text
apply = convert[1:]
results.append(float(apply.replace(',','')))
else:
results.append(childs.text)
ws.append(results) ws.append(results)
results = [] results = []
@@ -135,22 +141,48 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb):
y = bs(getShipping, "lxml") y = bs(getShipping, "lxml")
for w in y.find_all('fval'): for w in y.find_all('fval'):
shippingcost.append(float(w.text)) shippingcost.append(float(w.text))
print(shippingcost)
# Add Shipping Charge column. Set header and make bold # Add columns to Summary Tab
ws.insert_cols(4)
ws['D1'] = "Shipping Charges" ws.insert_cols(2)
ws['D1'].font = bold ws['B1'] = "Match"
ws.insert_cols(5)
ws['E1'] = "Production Charges"
ws.insert_cols(6)
ws['F1'] = "Shipping Charges"
ws.insert_cols(7)
ws['G1'] = "Adjustments"
# Load Shipping Charges into the sheet # Load Shipping Charges into the sheet
count = 2 count = 2
for x in shippingcost: for x in shippingcost:
ws.cell(column=4, row=count, value=x) ws.cell(column=6, row=count, value=x)
count = count + 1 count = count + 1
# Compute Production Charges and write to spreadsheet
count = 2
for row in ws:
value = "=H"+str(count)+"-G"+str(count)+"-F"+str(count)
ws.cell(column=5, row=count, value=value)
count = count + 1
############# Order Summary tab #############
# Finalize Spreadsheet and save
for cell in ws["1:1"]:
cell.font = bold
for cell in ws2["1:1"]:
cell.font = bold
wb.save('report.xlsx') wb.save('report.xlsx')
def loadMenu(): def loadMenu():
ConfigFile = "StorefrontUtilitiesConfig.xml"
ClientName = [] ClientName = []
SF_URL = [] SF_URL = []
SF_HOST = [] SF_HOST = []
@@ -158,9 +190,13 @@ def loadMenu():
SUMMARY_TAB = [] SUMMARY_TAB = []
headers = [] headers = []
client_headers = [] client_headers = []
CLIENT_DETAIL_TAB = []
DETAIL_TAB = []
client_detail_headers = []
detail_headers = []
# Open the config file # Open the config file
with open("Config_ORIG.xml") as f: with open(ConfigFile) as f:
r = f.read() r = f.read()
y = bs(r, "lxml") y = bs(r, "lxml")
@@ -196,6 +232,18 @@ def loadMenu():
CLIENT_SUMMARY_TAB = [] CLIENT_SUMMARY_TAB = []
client_headers = [] client_headers = []
# Get Monthly Report Item Detail Fields
for w in y.find_all('client'):
for x in w.find_all('monthlyreport'):
for g in x.find_all('detailtab'):
for z in g.find_all('columnname'):
z.name = "string"
CLIENT_DETAIL_TAB.append(z)
client_detail_headers.append(z.text)
DETAIL_TAB.append(CLIENT_DETAIL_TAB)
detail_headers.append(client_detail_headers)
CLIENT_DETAIL_TAB = []
client_detail_headers = []
choice = 0 choice = 0
for x in ClientName: for x in ClientName:
@@ -204,19 +252,19 @@ def loadMenu():
option = int(input()) option = int(input())
# create new report file and adds headers based on config file # create new report file and add headers based on config file
wb = workbook.Workbook() wb = workbook.Workbook()
ws = wb.active ws = wb.active
ws.title = "Order Summary" ws.title = "Order Summary"
ws.append(headers[option]) ws.append(headers[option])
bold = Font(bold=True)
for cell in ws["1:1"]: ws2 = wb.create_sheet("Item Detail")
cell.font = bold ws2.append(detail_headers[option])
# cell.row_dimensions.width = 25
# converts summary_tab values to a string, adds everything to the URL_HOST array and returns it # converts summary_tab values to a string, adds everything to the URL_HOST array and returns it
REPORT_FIELDS = '\n'.join(map(str, SUMMARY_TAB[option])) REPORT_FIELDS = '\n'.join(map(str, SUMMARY_TAB[option]))
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws] DETAIL_REPORT_FIELDS = '\n'.join(map(str, DETAIL_TAB[option]))
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS]
return URL_HOST return URL_HOST
def main(): def main():
@@ -226,9 +274,10 @@ def main():
REPORT_FIELDS = URL_HOST[2] REPORT_FIELDS = URL_HOST[2]
wb = URL_HOST[3] wb = URL_HOST[3]
ws = URL_HOST[4] ws = URL_HOST[4]
ws2 = URL_HOST[5]
DETAIL_REPORT_FIELDS = URL_HOST[6]
ticket = Obtain_Ticket(URL, HOST) ticket = Obtain_Ticket(URL, HOST)
Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb) Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS)
Release_Ticket(ticket, URL, HOST) Release_Ticket(ticket, URL, HOST)
main() main()