mirror of
https://github.com/bcomsugi/Quickbooks-API.git
synced 2026-01-09 09:42:40 +07:00
add utils.py and update
This commit is contained in:
parent
d7dd3ae1ba
commit
21ecc50d64
64
QBClasses.py
64
QBClasses.py
@ -25,13 +25,13 @@ class ItemInventoryQuery(baseQBQuery):
|
||||
print(f'{args = }')
|
||||
print(f'{kwargs = }')
|
||||
super().__init__(*args, **kwargs)
|
||||
### Required Variable
|
||||
self.includeRetElements_allowed = ["ListID", "FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "BarCodeValue",
|
||||
"ManufacturerPartNumber", "UnitOfMeasureSetRef", "IsTaxIncluded", "SalesTaxCodeRef", "SalesDesc,", "SalesPrice", "IncomeAccountRef",
|
||||
"PurchaseDesc", "PurchaseCost", "PurchaseTaxCodeRef", "COGSAccountRef", "PrefVendorRef", "AssetAccountRef", "ReforderPoint", "Max", "QuantityOnHand",
|
||||
"AcerageCost", "QuantityOnOrder", "QuantityOnSalesOrder",
|
||||
"ExternalGUID", "DataExtRet",
|
||||
]
|
||||
self.cleanIncludeRetElements = cleanIncludeRetElements
|
||||
self.onError = "stopOnError"
|
||||
self.retName = 'ItemInventoryRet'
|
||||
self.defaultFilterKey = "ListID"
|
||||
@ -39,6 +39,8 @@ class ItemInventoryQuery(baseQBQuery):
|
||||
self.class_debug=kwargs["debug"]
|
||||
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
||||
### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[])
|
||||
|
||||
if 'ListID' in kwargs:
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["ListID"]=kwargs['ListID']
|
||||
elif 'FullName' in kwargs:
|
||||
@ -57,11 +59,10 @@ class ItemInventoryQuery(baseQBQuery):
|
||||
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:
|
||||
IRE = self.cleanIncludeRetElements(self.includeRetElements_allowed, kwargs["IncludeRetElement"])
|
||||
# self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=kwargs['IncludeRetElement']
|
||||
IRE = cleanIncludeRetElements(self.includeRetElements_allowed, kwargs["IncludeRetElement"]) # IRE->IncludeRetElements cleaned version
|
||||
print(f"{IRE = }")
|
||||
if len(IRE)>0:
|
||||
if self.defaultFilterKey not in IRE:
|
||||
if self.defaultFilterKey not in IRE: # defaultFilterKey is for BaseClass.count() eg: after instantiate, then print obj.count()
|
||||
IRE.append(self.defaultFilterKey)
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=IRE
|
||||
if 'OwnerID' in kwargs:
|
||||
@ -76,17 +77,30 @@ class GeneralSummaryReportQuery(baseQBQuery):
|
||||
print(f'{args = }')
|
||||
print(f'{kwargs = }')
|
||||
super().__init__( )
|
||||
self.includeRetElements_allowed = ["ReportTitle", "ReportSubtitle", "ReportBasis", "NumRows", "NumColumns", "NumColTitleRows", "ColDesc", "ReportData", ]
|
||||
self.cleanIncludeRetElements = cleanIncludeRetElements
|
||||
## Required variable
|
||||
self.includeRetElements_allowed = ["ReportTitle", "ReportSubtitle", "ReportBasis", "NumRows", "NumColumns", "NumColTitleRows", "ReportData", ]
|
||||
self.onError = "stopOnError"
|
||||
self.retName = 'ReportRet'
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]={}
|
||||
self.defaultFilterKey = "ListID"
|
||||
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
|
||||
self.class_debug=kwargs["debug"]
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]="InventoryStockStatusByItem"
|
||||
self.class_debug=kwargs["debug"]
|
||||
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]={} #Required
|
||||
### End Required variable
|
||||
self.ENUM_GeneralSummaryReportType = ["BalanceSheetByClass", "BalanceSheetPrevYearComp", "BalanceSheetStandard", "BalanceSheetSummary", "CustomerBalanceSummary",
|
||||
"ExpenseByVendorSummary", "IncomeByCustomerSummary", "InventoryStockStatusByItem", "InventoryStockStatusByVendor", "IncomeTaxSummary",
|
||||
"InventoryValuationSummary", "InventoryValuationSummaryBySite", "LotNumberInStockBySite", "PhysicalInventoryWorksheet", "ProfitAndLossByClass",
|
||||
"ProfitAndLossByJob", "ProfitAndLossPrevYearComp", "ProfitAndLossStandard", "ProfitAndLossYTDComp", "PurchaseByItemSummary", "PurchaseByVendorSummary",
|
||||
"SalesByCustomerSummary", "SalesByItemSummary", "SalesByRepSummary", "SalesTaxLiability", "SalesTaxRevenueSummary", "SerialNumberInStockBySite",
|
||||
"TrialBalance", "VendorBalanceSummary"]
|
||||
|
||||
if 'GeneralSummaryReportType' in kwargs:
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]=kwargs['GeneralSummaryReportType']
|
||||
enum=cleanIncludeRetElements(self.ENUM_GeneralSummaryReportType, kwargs['GeneralSummaryReportType'])
|
||||
print(enum)
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]=enum[0]
|
||||
else:
|
||||
return None
|
||||
print("Error -> GeneralSummaryReportType is required")
|
||||
return
|
||||
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:
|
||||
@ -108,15 +122,17 @@ class GeneralSummaryReportQuery(baseQBQuery):
|
||||
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:
|
||||
IRE = self.cleanIncludeRetElements(self.includeRetElements_allowed, kwargs["IncludeRetElement"])
|
||||
IRE = cleanIncludeRetElements(self.includeRetElements_allowed, kwargs["IncludeRetElement"]) #IRE->IncludeRetElements cleaned version
|
||||
print(f"{IRE = }")
|
||||
if len(IRE)>0:
|
||||
if self.defaultFilterKey not in IRE: #defaultFilterKey is for BaseClass.count() eg: after instantiate, then print obj.count()
|
||||
IRE.append(self.defaultFilterKey)
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["IncludeRetElement"]=IRE
|
||||
# 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 = }')
|
||||
# print(self.__class__.__name__ + "Rq")
|
||||
# print(f'{self.QBDict = }')
|
||||
self.runCheck() ### running the qbxml connection to get data ###
|
||||
|
||||
class InvoiceAdd(baseQBQuery):
|
||||
@ -161,15 +177,15 @@ class CustomerQuery(baseQBQuery):
|
||||
print(f'{args = }')
|
||||
print(f'{kwargs = }')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.includeRetElements_allowed = ["FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "CompanyName", "Salutation",
|
||||
self.includeRetElements_allowed = ["ListID", "FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "CompanyName", "Salutation",
|
||||
"FirstName", "MiddleName", "LastName", "JobTitle", "BillAddress", "BillAddressBlock", "ShipAddress", "ShipAddressBlock", "ShipToAddress", "Phone",
|
||||
"AltPhone", "Fax", "Email", "Cc", "Contact", "AltContact", "AdditionalContactRef", "ContactsRet", "CustomerTypeRef", "TermsRef", "SalesRepRef",
|
||||
"Balance", "TotalBalance", "SalesTaxCodeRef", "ItemSalesTaxRef", "SalesTaxCountry", "ResaleNumber", "AccountNumber", "CreditLimit",
|
||||
"PreferredPaymentMethodRef", "CreditCardInfo", "JobStatus", "JobStartDate", "JobProjectedEndDate", "JobEndDate", "JobDesc", "JobTypeRef", "Notes",
|
||||
"AdditionalNotesRet", "PreferredDeliveryMethod", "PriceLevelRef", "ExternalGUID", "TaxRegistrationNumber", "CurrencyRef", "DataExtRet"]
|
||||
self.cleanIncludeRetElements = cleanIncludeRetElements
|
||||
self.onError = "stopOnError"
|
||||
self.retName = 'CustomerRet'
|
||||
self.defaultFilterKey = "ListID"
|
||||
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
|
||||
self.class_debug=kwargs["debug"]
|
||||
|
||||
@ -197,8 +213,10 @@ class CustomerQuery(baseQBQuery):
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["TotalBalanceFilter"]={'Operator':kwargs['Operator'], 'Amount':kwargs['Amount']}
|
||||
if 'IncludeRetElement' in kwargs:
|
||||
IRE = cleanIncludeRetElements(self.includeRetElements_allowed, kwargs['IncludeRetElement'])
|
||||
print("after 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
|
||||
if 'OwnerID' in kwargs:
|
||||
self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID']
|
||||
@ -214,16 +232,18 @@ class CustomerQuery(baseQBQuery):
|
||||
if __name__ == "__main__":
|
||||
@timing
|
||||
def main():
|
||||
g= GeneralSummaryReportQuery(GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear")
|
||||
g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear")
|
||||
print(g, type(g))
|
||||
print(type(g.all()))
|
||||
print(g.all())
|
||||
pprint.pprint(g.filter("ColData").all())
|
||||
print(g.response_string)
|
||||
pprint.pprint(g.filter("reportdata").all())
|
||||
print(g.count(), g.all())
|
||||
|
||||
@timing
|
||||
def iteminventoryquery():
|
||||
# g=ItemInventoryQuery()
|
||||
g=ItemInventoryQuery(debug = True, MaxReturned = 3, IncludeRetElement=["FullName", "DataExtRet", "Name", "QuantityOnHand", "QuantityOnSalesOrder", "QuantityOnOrder", ]) #put OwnerID=0 to get DataExtRet
|
||||
g=ItemInventoryQuery(debug = False, MaxReturned = 5, IncludeRetElements = "abc")# IncludeRetElement=["FullName", "DataExtRet", "Name", "QuantityOnHand", "QuantityOnSalesOrder", "QuantityOnOrder", "ManufacturerPartNumber"]) #put OwnerID=0 to get DataExtRet
|
||||
# print("before g.all")
|
||||
# print(f'{g.all() = }')
|
||||
# print("after g.all")
|
||||
@ -242,7 +262,7 @@ if __name__ == "__main__":
|
||||
# print(g.filter("name").firstValue())
|
||||
print(g.count())
|
||||
print(g.statusOk)
|
||||
print(g.filter(["name", "quantityonhand"]).getValuesOf("quantityonhand"))
|
||||
print(g.filter(["name", "manufacturerpartnumber", "quantityonhand"]).getValuesOf(["Name","quantityonhand", "manufacturerpartnumber"]))
|
||||
|
||||
|
||||
# print(g.filter(["DataExtRet"]).all())
|
||||
|
||||
26
server.py
26
server.py
@ -249,28 +249,40 @@ class baseQBQuery:
|
||||
def __repr__(self) -> str:
|
||||
return str(self.all())
|
||||
|
||||
def filter(self, filterKey):
|
||||
self.filterKey=filterKey
|
||||
# def filter(self, filterKey):
|
||||
# self.filterKey=filterKey
|
||||
|
||||
|
||||
def getValuesOf(self, key:str=None, var:dict=None, dataRetList:list=None) :
|
||||
if key==None:
|
||||
key = self.filterKey[0]
|
||||
key = self.filterKey
|
||||
elif isinstance(key, str):
|
||||
key=[key]
|
||||
elif isinstance(key, list):
|
||||
pass
|
||||
else:
|
||||
raise TypeError(f'{key=} should be string not {type(key)}')
|
||||
print(key)
|
||||
key = cleanIncludeRetElements(self._includeRetElements_allowed, key)
|
||||
print(key)
|
||||
if len(key)==0:
|
||||
key = self.filterKey[0]
|
||||
key = self.filterKey
|
||||
else:
|
||||
key = key[0]
|
||||
key = key
|
||||
# print(f'getvaluesof {key = }')
|
||||
# for xdct in self.findKeyInDict(var, dataRetList):
|
||||
# print(f'{xdct = }', type(xdct), self.filterKey[0], key)
|
||||
_dct = [x[key] for x in self.findKeyInDict(var, dataRetList)]
|
||||
lstresult = []
|
||||
for x in self.findKeyInDict(var, dataRetList):
|
||||
templstresult = []
|
||||
for y in key:
|
||||
templstresult.append(x.get(y, ""))
|
||||
lstresult.append(templstresult)
|
||||
print(f'{lstresult[-1] =}')
|
||||
return lstresult
|
||||
_lst = [x[key] for x in self.findKeyInDict(var, dataRetList)]
|
||||
# print(_dct)
|
||||
return _dct
|
||||
return _lst
|
||||
|
||||
def all(self, var:dict=None, dataRetList:list=None) -> list:
|
||||
# print(f'{self.statusOk = }')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user