mirror of
https://github.com/bcomsugi/Quickbooks-API.git
synced 2026-04-01 18:14:58 +07:00
add qbclasses.count()
This commit is contained in:
parent
e2121465e1
commit
0f769f33ce
53
QBClasses.py
53
QBClasses.py
@ -1,8 +1,20 @@
|
|||||||
from server import baseQBQuery, timing
|
from server import baseQBQuery, timing
|
||||||
import pprint
|
import pprint
|
||||||
import timeit
|
import timeit
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
|
def timing(f):
|
||||||
|
# @wraps(f)
|
||||||
|
def wrap(*args, **kw):
|
||||||
|
ts = time()
|
||||||
|
result = f(*args, **kw)
|
||||||
|
te = time()
|
||||||
|
print('func:%r args:[%r, %r] took: %2.6f sec' % \
|
||||||
|
(f.__name__, args, kw, te-ts))
|
||||||
|
return result
|
||||||
|
return wrap
|
||||||
|
|
||||||
# from functools import wraps
|
# from functools import wraps
|
||||||
|
|
||||||
def cleanIncludeRetElements(includeRetElements_allowed:list, includeRetElements:list):
|
def cleanIncludeRetElements(includeRetElements_allowed:list, includeRetElements:list):
|
||||||
@ -23,14 +35,19 @@ class ItemInventoryQuery(baseQBQuery):
|
|||||||
print(f'{args = }')
|
print(f'{args = }')
|
||||||
print(f'{kwargs = }')
|
print(f'{kwargs = }')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.includeRetElements_allowed = ["FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "BarCodeValue",
|
self.includeRetElements_allowed = ["ListID", "FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "BarCodeValue",
|
||||||
"ManufacturerPartNumber", "UnitOfMeasureSetRef", "IsTaxIncluded", "SalesTaxCodeRef", "SalesDesc,", "SalesPrice", "IncomeAccountRef",
|
"ManufacturerPartNumber", "UnitOfMeasureSetRef", "IsTaxIncluded", "SalesTaxCodeRef", "SalesDesc,", "SalesPrice", "IncomeAccountRef",
|
||||||
"PurchaseDesc", "PurchaseCost", "PurchaseTaxCodeRef", "COGSAccountRef", "PrefVendorRef", "AssetAccountRef", "ReforderPoint", "Max", "QuantityOnHand",
|
"PurchaseDesc", "PurchaseCost", "PurchaseTaxCodeRef", "COGSAccountRef", "PrefVendorRef", "AssetAccountRef", "ReforderPoint", "Max", "QuantityOnHand",
|
||||||
"AcerageCost", "QuantityOnOrder", "QuantityOnSalesOrder",
|
"AcerageCost", "QuantityOnOrder", "QuantityOnSalesOrder",
|
||||||
"ExternalGUID", "DataExtRet",
|
"ExternalGUID", "DataExtRet",
|
||||||
]
|
]
|
||||||
self.cleanIncludeRetElements = cleanIncludeRetElements
|
self.cleanIncludeRetElements = cleanIncludeRetElements
|
||||||
|
self.onError = "stopOnError"
|
||||||
self.retName = 'ItemInventoryRet'
|
self.retName = 'ItemInventoryRet'
|
||||||
|
self.defaultFilterKey = "ListID"
|
||||||
|
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
|
||||||
|
self.class_debug=kwargs["debug"]
|
||||||
|
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
||||||
if 'ListID' in kwargs:
|
if 'ListID' in kwargs:
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID']
|
self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID']
|
||||||
@ -53,6 +70,9 @@ class ItemInventoryQuery(baseQBQuery):
|
|||||||
IRE = self.cleanIncludeRetElements(self.includeRetElements_allowed, kwargs["IncludeRetElement"])
|
IRE = self.cleanIncludeRetElements(self.includeRetElements_allowed, kwargs["IncludeRetElement"])
|
||||||
# self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement']
|
# self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement']
|
||||||
print(f"{IRE = }")
|
print(f"{IRE = }")
|
||||||
|
if len(IRE)>0:
|
||||||
|
if self.defaultFilterKey not in IRE:
|
||||||
|
IRE.append(self.defaultFilterKey)
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=IRE
|
self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=IRE
|
||||||
if 'OwnerID' in kwargs:
|
if 'OwnerID' in kwargs:
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID']
|
self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID']
|
||||||
@ -69,7 +89,8 @@ class GeneralSummaryReportQuery(baseQBQuery):
|
|||||||
self.cleanIncludeRetElements = cleanIncludeRetElements
|
self.cleanIncludeRetElements = cleanIncludeRetElements
|
||||||
self.retName = 'ReportRet'
|
self.retName = 'ReportRet'
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
||||||
|
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
|
||||||
|
self.class_debug=kwargs["debug"]
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]="InventoryStockStatusByItem"
|
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]="InventoryStockStatusByItem"
|
||||||
if 'GeneralSummaryReportType' in kwargs:
|
if 'GeneralSummaryReportType' in kwargs:
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]=kwargs['GeneralSummaryReportType']
|
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]=kwargs['GeneralSummaryReportType']
|
||||||
@ -193,7 +214,11 @@ class CustomerQuery(baseQBQuery):
|
|||||||
self.cleanIncludeRetElements = cleanIncludeRetElements
|
self.cleanIncludeRetElements = cleanIncludeRetElements
|
||||||
self.onError = "stopOnError"
|
self.onError = "stopOnError"
|
||||||
self.retName = 'CustomerRet'
|
self.retName = 'CustomerRet'
|
||||||
|
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
|
||||||
|
self.class_debug=kwargs["debug"]
|
||||||
|
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
||||||
|
|
||||||
if 'ListID' in kwargs:
|
if 'ListID' in kwargs:
|
||||||
self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID']
|
self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID']
|
||||||
elif 'FullName' in kwargs:
|
elif 'FullName' in kwargs:
|
||||||
@ -227,6 +252,9 @@ class CustomerQuery(baseQBQuery):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
@timing
|
@timing
|
||||||
def main():
|
def main():
|
||||||
g= GeneralSummaryReportQuery(GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear")
|
g= GeneralSummaryReportQuery(GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear")
|
||||||
@ -235,23 +263,30 @@ def main():
|
|||||||
print(g.all())
|
print(g.all())
|
||||||
pprint.pprint(g.filter("ColData").all())
|
pprint.pprint(g.filter("ColData").all())
|
||||||
|
|
||||||
|
@timing
|
||||||
def iteminventoryquery():
|
def iteminventoryquery():
|
||||||
# g=ItemInventoryQuery(MaxReturned=2)
|
# g=ItemInventoryQuery()
|
||||||
g=ItemInventoryQuery(MaxReturned = 3, IncludeRetElement=["DataExtRet", "Name"]) #put OwnerID=0 to get DataExtRet
|
g=ItemInventoryQuery(debug = False, MaxReturned = None, IncludeRetElement=["FullName", "DataExtRet", "Name", "QuantityOnHand", "QuantityOnSalesOrder", "QuantityOnOrder", ]) #put OwnerID=0 to get DataExtRet
|
||||||
# print("before g.all")
|
# print("before g.all")
|
||||||
# print(f'{g.all() = }')
|
# print(f'{g.all() = }')
|
||||||
# print("after g.all")
|
# print("after g.all")
|
||||||
# print("")
|
# print("")
|
||||||
# pprint.pprint(g.filter(["FullName", "Name", "sublevel"]).all())
|
# pprint.pprint(g.filter(["FullName", "Name", "sublevel"]).all())
|
||||||
# print(f'{g.filter("fullname") = }')
|
# print(f'{g.filter("fullname") = }')
|
||||||
print(f'{g = }')
|
|
||||||
print("before")
|
|
||||||
print(g.filter([ "Name", "QuantityOnHand", "QUantityOnSalesOrder", "QuantityonOrder"]).first())
|
|
||||||
|
|
||||||
pprint.pprint(g.returnRet())
|
# print(f'{g = }')
|
||||||
|
print("before")
|
||||||
|
# print(g.filter([ "Name", "QuantityOnHand", "QUantityOnSalesOrder", "QuantityonOrder"]).first())
|
||||||
|
c = g.filter([ "Name", "QuantityOnHand", "QUantityOnSalesOrder", "QuantityonOrder"]).all()
|
||||||
|
print(c)
|
||||||
|
# pprint.pprint(g.returnRet())
|
||||||
|
# print(g.filter("name").firstValue())
|
||||||
|
print(g.count())
|
||||||
|
|
||||||
|
|
||||||
# print(g.filter(["DataExtRet"]).all())
|
# print(g.filter(["DataExtRet"]).all())
|
||||||
|
|
||||||
|
@timing
|
||||||
def customerquery():
|
def customerquery():
|
||||||
g= CustomerQuery(MaxReturned=3, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock"])
|
g= CustomerQuery(MaxReturned=3, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock"])
|
||||||
# g= CustomerQuery(MaxReturned=20, ActiveStatus="ActiveOnly", MatchCriterion="StartsWith", Name="to", IncludeRetElement=["fullname", "name", "billaddressblock", "currencyfilter"])
|
# g= CustomerQuery(MaxReturned=20, ActiveStatus="ActiveOnly", MatchCriterion="StartsWith", Name="to", IncludeRetElement=["fullname", "name", "billaddressblock", "currencyfilter"])
|
||||||
@ -316,8 +351,6 @@ def readxmltodict():
|
|||||||
print(recursiveDict(varDict, f, enumDict))
|
print(recursiveDict(varDict, f, enumDict))
|
||||||
f.close
|
f.close
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# main()
|
# main()
|
||||||
iteminventoryquery()
|
iteminventoryquery()
|
||||||
# customerquery()
|
# customerquery()
|
||||||
|
|||||||
20
server.py
20
server.py
@ -31,6 +31,8 @@ class baseQBQuery:
|
|||||||
self.cleanIncludeRetElements = None
|
self.cleanIncludeRetElements = None
|
||||||
self.includeRetElements_allowed = None
|
self.includeRetElements_allowed = None
|
||||||
self.retName = None
|
self.retName = None
|
||||||
|
self.defaultFilterKey = None
|
||||||
|
self.class_debug = False
|
||||||
### end ### variable to be replace with other class init value
|
### end ### variable to be replace with other class init value
|
||||||
self.listOfDict = self.ListOfDict(None, self.varDict, self.retName)
|
self.listOfDict = self.ListOfDict(None, self.varDict, self.retName)
|
||||||
self.statusCode = -1
|
self.statusCode = -1
|
||||||
@ -96,6 +98,7 @@ class baseQBQuery:
|
|||||||
# QBXML = ET.fromstring(self.response_string)
|
# QBXML = ET.fromstring(self.response_string)
|
||||||
# print(xmltodict.parse(self.response_string))
|
# print(xmltodict.parse(self.response_string))
|
||||||
self.varDict = xmltodict.parse(self.response_string)
|
self.varDict = xmltodict.parse(self.response_string)
|
||||||
|
if self.class_debug:
|
||||||
pprint.pprint(self.varDict)
|
pprint.pprint(self.varDict)
|
||||||
self.listOfDict.varDict = self.varDict
|
self.listOfDict.varDict = self.varDict
|
||||||
self.listOfDict.filterKey = ["@statusCode"]
|
self.listOfDict.filterKey = ["@statusCode"]
|
||||||
@ -172,15 +175,15 @@ class baseQBQuery:
|
|||||||
# print(f'{self.returnRet() = }')
|
# print(f'{self.returnRet() = }')
|
||||||
return self.response_string
|
return self.response_string
|
||||||
|
|
||||||
|
def count(self) -> int:
|
||||||
|
# objs = self.filter(self.defaultFilterKey).all()
|
||||||
|
# print(f"{objs = }", type(objs))
|
||||||
|
return len(self.filter(self.defaultFilterKey).all())
|
||||||
|
|
||||||
# def __str__(self) -> str:
|
|
||||||
# print("repr")
|
|
||||||
# print(self.returnRet())
|
|
||||||
# return "abc"
|
|
||||||
|
|
||||||
def filter(self, key=None):
|
def filter(self, key=None):
|
||||||
print(f'{key = }')
|
# print(f'{key = }')
|
||||||
print(f'{self.statusOk = }')
|
# print(f'{self.statusOk = }')
|
||||||
if not self.runCheck():
|
if not self.runCheck():
|
||||||
print("not runcheck")
|
print("not runcheck")
|
||||||
return self.ListOfDict(["abc"], self.varDict, self.retName, self.statusOk)
|
return self.ListOfDict(["abc"], self.varDict, self.retName, self.statusOk)
|
||||||
@ -194,7 +197,7 @@ class baseQBQuery:
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
key = self.cleanIncludeRetElements(self.includeRetElements_allowed, key)
|
key = self.cleanIncludeRetElements(self.includeRetElements_allowed, key)
|
||||||
print(f'f {key = }')
|
# print(f'f {key = }')
|
||||||
if key:
|
if key:
|
||||||
return self.ListOfDict(key, self.varDict, self.retName)
|
return self.ListOfDict(key, self.varDict, self.retName)
|
||||||
else:
|
else:
|
||||||
@ -246,7 +249,7 @@ class baseQBQuery:
|
|||||||
return _dct
|
return _dct
|
||||||
|
|
||||||
def all(self, var:dict=None, dataRetList:list=None):
|
def all(self, var:dict=None, dataRetList:list=None):
|
||||||
print(f'{self.statusOk = }')
|
# print(f'{self.statusOk = }')
|
||||||
if not self.statusOk:
|
if not self.statusOk:
|
||||||
return []
|
return []
|
||||||
_lst = [x for x in self.find_listOfDict(var, dataRetList)]
|
_lst = [x for x in self.find_listOfDict(var, dataRetList)]
|
||||||
@ -269,6 +272,7 @@ class baseQBQuery:
|
|||||||
|
|
||||||
def firstValue(self, var:dict=None, dataRetList:list=None):
|
def firstValue(self, var:dict=None, dataRetList:list=None):
|
||||||
if not self.statusOk:
|
if not self.statusOk:
|
||||||
|
print("firstValue statusOk is False")
|
||||||
return []
|
return []
|
||||||
# return self.first(var, dataRetList)[self.filterKey]
|
# return self.first(var, dataRetList)[self.filterKey]
|
||||||
_val=self.first(var, dataRetList)
|
_val=self.first(var, dataRetList)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user