from server import baseQBQuery, timing import pprint import timeit # from functools import wraps class ItemInventoryQuery(baseQBQuery): def __init__(self, *args, **kwargs): print(f'{args = }') print(f'{kwargs = }') super().__init__(*args, **kwargs) self.retName = 'ItemInventoryRet' self.QBDict[self.__class__.__name__ + "Rq"]={} if 'ListID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID'] elif 'FullName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FullName"]=kwargs['FullName'] else: if 'MaxReturned' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["MaxReturned"]=kwargs['MaxReturned'] if 'ActiveStatus' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ActiveStatus"]=kwargs['ActiveStatus'] if 'FromModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FromModifiedDate"]=kwargs['FromModifiedDate'] if 'ToModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ToModifiedDate"]=kwargs['ToModifiedDate'] if 'MatchCriterion' in kwargs and 'Name' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameFilter"]={'MatchCriterion':kwargs['MatchCriterion', 'Name':kwargs['Name']]} if 'FromName' in kwargs or 'ToName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} if 'IncludeRetElement' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement'] if 'OwnerID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID'] # print(self.__class__.__name__ + "Rq") # print(self.QBDict) class GeneralSummaryReportQuery(baseQBQuery): def __init__(self, *args, **kwargs): print(f'{args = }') print(f'{kwargs = }') super().__init__( ) self.retName = 'ReportRet' self.QBDict[self.__class__.__name__ + "Rq"]={} self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]="InventoryStockStatusByItem" if 'GeneralSummaryReportType' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]=kwargs['GeneralSummaryReportType'] else: return None if 'FromReportDate' in kwargs or 'ToReportDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ReportPeriod"]={'FromReportDate':kwargs.get('FromReportDate', ""), 'ToReportDate':kwargs.get('ToReportDate', "")} elif 'ReportDateMacro' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ReportDateMacro"]=kwargs.get('ReportDateMacro', "") elif 'FullName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FullName"]=kwargs['FullName'] else: if 'MaxReturned' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["MaxReturned"]=kwargs['MaxReturned'] if 'ActiveStatus' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ActiveStatus"]=kwargs['ActiveStatus'] if 'FromModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FromModifiedDate"]=kwargs['FromModifiedDate'] if 'ToModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ToModifiedDate"]=kwargs['ToModifiedDate'] if 'MatchCriterion' in kwargs and 'Name' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameFilter"]={'MatchCriterion':kwargs['MatchCriterion', 'Name':kwargs['Name']]} if 'FromName' in kwargs or 'ToName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} if 'IncludeRetElement' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement'] if 'OwnerID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID'] print(self.__class__.__name__ + "Rq") print(f'{self.QBDict = }') class InvoiceAdd(baseQBQuery): def __init__(self, *args, **kwargs): print(f'{args = }') print(f'{kwargs = }') super().__init__(*args, **kwargs) self.retName = 'InvoiceAddRet' self.reqSubName = self.retName.replace('Ret', '') self.QBDict[self.__class__.__name__ + "Rq"]={} if 'CustomerFullName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID'] if 'ListID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID'] elif 'FullName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FullName"]=kwargs['FullName'] else: if 'MaxReturned' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["MaxReturned"]=kwargs['MaxReturned'] if 'ActiveStatus' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ActiveStatus"]=kwargs['ActiveStatus'] if 'FromModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FromModifiedDate"]=kwargs['FromModifiedDate'] if 'ToModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ToModifiedDate"]=kwargs['ToModifiedDate'] if 'MatchCriterion' in kwargs and 'Name' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameFilter"]={'MatchCriterion':kwargs['MatchCriterion', 'Name':kwargs['Name']]} if 'FromName' in kwargs or 'ToName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} if 'IncludeRetElement' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement'] if 'OwnerID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID'] # print(self.__class__.__name__ + "Rq") # print(self.QBDict) # x=ItemInventoryQuery('bagus', 'kedua', key5=5, key2="hore", FullName1='hooooo', FromName1="sg", ToName1="sugi", IncludeRetElement1=['Name', 'FullName'], MaxReturned="2") # x.create_QBXML() # x.connect_to_quickbooks() # # print(x.find_firstListOfDict("FullName")['FullName']) # # print(x.find_firstListOfDictValue("PurchaseCost")) # # print(x.find_firstListOfDict("PurchaseCost")) # # print(x.find_allListOfDict("FullName")) # # pprint.pprint(x.Rs) # # print("ada" if list(x.find_listOfDict("FullName")) else "ga") # print(x.filter("FullName")) # y=x.filter("Name") # print(type(x.filter("FullName1"))) # print(type(y)) # print(x.filter("FullName1").all()) # _test=x.filter("FullName1").all() # if _test: # print(_test) # try: # print(x.filter("FullName1").all()[-1]) # except Exception as e: # print(e) # print(x.filter("FullName1").first()) # print(x.filter("FullName1").firstValue()) # print(x.filter("FullName1").last()) # print(x.filter("FullName1").lastValue()) # print(x.filter("FullName").count()) # print(y.last()) # print(y.lastValue()) # pprint.pprint(x.all()) # a1=x.filter("FullName") # print(a1) # a2 = x.filter("Name") # print(a2) # print(a1) class CustomerQuery(baseQBQuery): def __init__(self, *args, **kwargs): print(f'{args = }') print(f'{kwargs = }') super().__init__(*args, **kwargs) self.onError = "stopOnError" self.retName = 'CustomerRet' self.QBDict[self.__class__.__name__ + "Rq"]={} if 'ListID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID'] elif 'FullName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FullName"]=kwargs['FullName'] else: if 'MaxReturned' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["MaxReturned"]=kwargs['MaxReturned'] if 'ActiveStatus' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ActiveStatus"]=kwargs['ActiveStatus'] if 'FromModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["FromModifiedDate"]=kwargs['FromModifiedDate'] if 'ToModifiedDate' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["ToModifiedDate"]=kwargs['ToModifiedDate'] if 'MatchCriterion' in kwargs and 'Name' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameFilter"]={'MatchCriterion':kwargs['MatchCriterion'], 'Name':kwargs['Name']} elif 'FromName' in kwargs or 'ToName' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} if 'Operator' in kwargs and 'Amount' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["TotalBalanceFilter"]={'Operator':kwargs['Operator'], 'Amount':kwargs['Amount']} if 'IncludeRetElement' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement'] if 'OwnerID' in kwargs: self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID'] print(self.__class__.__name__ + "Rq") print(self.QBDict) @timing def main(): g= GeneralSummaryReportQuery(GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear") print(type(g.all())) print(g.all()) pprint.pprint(g.filter("ColData").all()) def customerquery(): g= CustomerQuery(MaxReturned=3, IncludeRetElement=["FullName", "Name", "CompanyName", "BillAddressBlock", "ShipAddress"]) print("init finish") print(f'{type(g.all()) = }') print("before g.all") print(f'{g.all() = }') # print("after g.all") # pprint.pprint(g.filter("ColData").all()) def readxmltodict(): import xmltodict filename="ItemInventoryQuery.xml" filename="InvoiceAdd.xml" with open(filename, "r") as f: xml = f.read() print(xml) print("") print("") with open(filename, "r") as f: xmllines = f.readlines() print(xmllines) varDict = xmltodict.parse(xml) # print(f"{varDict = }") print() f = open(filename) enumDict ={} def recursiveDict(varDict, f, enumDict): # print(varDict) for dKey in varDict: print(dKey) if not isinstance(varDict[dKey], (list, dict)): if dKey[0]=='@' or dKey[0]=="#": continue _ = f.readline() dKey = dKey.replace("#", "") print(dKey) # print(f'{dKey = }, {varDict[dKey]}, {_}') _strOptional = "" while not dKey in _: _ = f.readline() # print(f'{dKey = }, {varDict[dKey]}, {_}') if "values:" in _: enumDict[dKey]=_.split(":")[-1].replace("[DEFAULT]","").replace("-->","").replace(" ","").replace("\n","").split(",") _ = f.readline() _strOptional = _.split("--")[1].strip() varDict[dKey]+=";"+_strOptional print(f'{varDict[dKey] = }') elif isinstance(varDict[dKey], dict): varDict[dKey], enumDict=recursiveDict(varDict[dKey], f, enumDict)##### istirahat dulu ah return varDict, enumDict print(f'{varDict = }') print() print(recursiveDict(varDict, f, enumDict)) f.close if __name__ == "__main__": # main() customerquery() # readxmltodict()