diff --git a/QBClass/QBClasses.py b/QBClass/QBClasses.py index c1e3199..90b60b3 100644 --- a/QBClass/QBClasses.py +++ b/QBClass/QBClasses.py @@ -345,7 +345,7 @@ class InvoiceAdd(baseQBQuery): self.qbdictlist.append(self.QBDict.copy()) del self.QBDict[self.__class__.__name__] self.QBDict[self.classNameRq]=self.qbdictlist - pprint.pprint(self.QBDict, sort_dicts=False) + # pprint.pprint(self.QBDict, sort_dicts=False) def create_data(self, kwargs): @@ -590,8 +590,8 @@ class InvoiceAdd(baseQBQuery): self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement'] # print(self.classNameRq) - print('self.QBDICT') - pprint.pprint(self.QBDict, sort_dicts=False) + # print('self.QBDICT') + # pprint.pprint(self.QBDict, sort_dicts=False) diff --git a/QBClass/server.py b/QBClass/server.py index f8a3a69..36cca2e 100644 --- a/QBClass/server.py +++ b/QBClass/server.py @@ -75,7 +75,7 @@ class baseQBQuery: # } # } firstKey = str(list(self.QBDict.keys())[0]) - print(f'{firstKey = } {self.QBDict}') + # print(f'{firstKey = } {self.QBDict}') dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Example with multiple FullName Item ### "@onError": self.onError, firstKey: self.QBDict[firstKey]}} diff --git a/exim.py b/exim.py index 8a3bea8..5b675dc 100644 --- a/exim.py +++ b/exim.py @@ -20,7 +20,7 @@ def timer(func): result = func(*args, **kwargs) duration = time.time() - start total += duration - print(f"Execution time: {duration} Total: {total}") + print(f"Function:{func.__name__} Execution time: {duration} Total: {total}") return result total = 0 @@ -269,7 +269,7 @@ def process_data(iq_list, so_dict): is_inv_so_line_ok = False if sorate: if float(inv_line.get('Rate',0))!=float(sorate): - print(f"{inv_line['ItemRef']['FullName'] = } {inv_line['Rate']=} <> {sorate=} ; {float(inv_line.get('Rate',0)) = } {float(sorate) = }") + print(f"{txn['RefNumber'] = } {inv_line['ItemRef']['FullName'] = } {inv_line['Rate']=} <> {sorate=} ; {float(inv_line.get('Rate',0)) = } {float(sorate) = }") is_inv_so_line_ok = False # if soamount: # if float(inv_line.get('Amount',0))!=float(soamount): @@ -309,7 +309,7 @@ def process_data(iq_list, so_dict): # c =next(iter(iq_list)) # print('TEST RESULT:') # pprint(c, sort_dicts=False) - print(f'{len(nolinkInv) = }\n{nolinkInv = }\n{soNotInOneInv = }\n{manuallyClosedSO = }\n{openSO = }\n{len(fullyInvoicedSO) = }') + # print(f'{len(nolinkInv) = }\n{nolinkInv = }\n{soNotInOneInv = }\n{manuallyClosedSO = }\n{openSO = }\n{len(fullyInvoicedSO) = }') c = [item for item in so_list if item not in fullyInvoicedSO] print(f'not fuuly invoice, leftover SO: {c}') return iq_list @@ -379,16 +379,17 @@ def make_invoiceadd_dict(iq_list): invadddict['TemplateRef_FullName'] = inv_line['TemplateRef']['FullName'] invadddict['TxnDate'] = inv_line['TxnDate'] invadddict['RefNumber'] = inv_line['RefNumber'] - invadddict['BillAddress_Addr1'] = inv_line['BillAddress'].get('Addr1') - invadddict['BillAddress_Addr2'] = inv_line['BillAddress'].get('Addr2') - invadddict['BillAddress_Addr3'] = inv_line['BillAddress'].get('Addr3') - invadddict['BillAddress_Addr4'] = inv_line['BillAddress'].get('Addr4') - invadddict['BillAddress_Addr5'] = inv_line['BillAddress'].get('Addr5') - invadddict['BillAddress_City'] = inv_line['BillAddress'].get('City') - invadddict['BillAddress_State'] = inv_line['BillAddress'].get('State') - invadddict['BillAddress_PostalCode'] = inv_line['BillAddress'].get('PostalCode') - invadddict['BillAddress_Country'] = inv_line['BillAddress'].get('Country') - invadddict['BillAddress_Note'] = inv_line['BillAddress'].get('Note') + if 'BillAddress' in inv_line: + invadddict['BillAddress_Addr1'] = inv_line['BillAddress'].get('Addr1') + invadddict['BillAddress_Addr2'] = inv_line['BillAddress'].get('Addr2') + invadddict['BillAddress_Addr3'] = inv_line['BillAddress'].get('Addr3') + invadddict['BillAddress_Addr4'] = inv_line['BillAddress'].get('Addr4') + invadddict['BillAddress_Addr5'] = inv_line['BillAddress'].get('Addr5') + invadddict['BillAddress_City'] = inv_line['BillAddress'].get('City') + invadddict['BillAddress_State'] = inv_line['BillAddress'].get('State') + invadddict['BillAddress_PostalCode'] = inv_line['BillAddress'].get('PostalCode') + invadddict['BillAddress_Country'] = inv_line['BillAddress'].get('Country') + invadddict['BillAddress_Note'] = inv_line['BillAddress'].get('Note') if 'ShipAddress' in inv_line: invadddict['ShipAddress_Addr1'] = inv_line['ShipAddress'].get('Addr1') invadddict['ShipAddress_Addr2'] = inv_line['ShipAddress'].get('Addr2') @@ -402,7 +403,8 @@ def make_invoiceadd_dict(iq_list): invadddict['ShipAddress_Note'] = inv_line['ShipAddress'].get('Note') if inv_line.get('PONumber'): invadddict['PONumber'] = inv_line.get('PONumber') - invadddict['TermsRef_FullName'] = inv_line['TermsRef']['FullName'] + if 'TermsRef' in inv_line: + invadddict['TermsRef_FullName'] = inv_line['TermsRef']['FullName'] invadddict['DueDate'] = inv_line['DueDate'] if 'SalesRepRef' in inv_line: invadddict['SalesRepRef_FullName'] = inv_line['SalesRepRef']['FullName'] @@ -456,7 +458,9 @@ def make_invoiceadd_dict(iq_list): invoiceaddlist.append(invadddict) # pprint(invadddict, sort_dicts=False) - pprint(invoiceaddlist, sort_dicts=False) + + # pprint(invoiceaddlist, sort_dicts=False) + for x in invoiceaddlist: if '10671' in x['RefNumber']: pprint(x, sort_dicts=False) @@ -527,6 +531,7 @@ def get_last_date_of_month(stryearmonth:str): return f"{datesplit[0]}-{datesplit[1]}-{str(res.day)}" +@timer def main(fromtxndate, totxndate, maxreturned:int=None): # print(timeit.repeat(process, repeat=1)) # process() @@ -564,14 +569,19 @@ def main(fromtxndate, totxndate, maxreturned:int=None): if __name__=='__main__': # print(np.arange('2021-02', '2021-03', dtype='datetime64[D]')) - fromtxndate = '2022-07-02' + fromtxndate = '2024-07-01' totxndate = get_last_date_of_month(fromtxndate) _fromdate = datetime.datetime.fromisoformat(fromtxndate) print(fromtxndate) - readydata = main(fromtxndate, totxndate, 2) + + readydata = main(fromtxndate, totxndate) # pprint(readydata, sort_dicts=False) - IA = InvoiceAdd(*readydata, debug=True) - print(IA.create_QBXML()) + IA = InvoiceAdd(*readydata, debug=False) + # print(IA.create_QBXML()) + filename = f'exim\Data\{fromtxndate}_qbxml.txt' + + with open(f"{filename}", "w") as outfile: + outfile.write(IA.create_QBXML()) # IA.all()