Quickbooks-API/QBClasses.py

573 lines
35 KiB
Python

from server import baseQBQuery, timing
import pprint
import timeit
import xml.dom.minidom
from utils import timing, cleanIncludeRetElements
import json
# from functools import wraps
# def cleanIncludeRetElements(includeRetElements_allowed:list, includeRetElements:list):
# iREs = []
# # print(f'{includeRetElements_allowed = }\n{includeRetElements = }')
# if isinstance(includeRetElements, str): #if user put 1 str argument in IncludeRetElements, change it to list
# includeRetElements = [includeRetElements]
# for iRE in includeRetElements:
# for iRE_a in includeRetElements_allowed:
# if iRE.lower() == iRE_a.lower():
# iREs.append(iRE_a)
# break
# return iREs
class ItemInventoryQuery(baseQBQuery):
def __init__(self, *args, **kwargs):
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.onError = "stopOnError"
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"]={}
### 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:
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: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")}
if 'IncludeRetElement' in kwargs:
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
if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data)
self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID']
# print(self.__class__.__name__ + "Rq")
# print(self.QBDict)
self.runCheck() ### running the qbxml connection to get data ###
class GeneralSummaryReportQuery(baseQBQuery):
def __init__(self, *args, **kwargs):
print(f'{args = }')
print(f'{kwargs = }')
super().__init__( )
## Required variable
self.includeRetElements_allowed = ["ReportTitle", "ReportSubtitle", "ReportBasis", "NumRows", "NumColumns", "NumColTitleRows", "ReportData", ]
self.onError = "stopOnError"
self.retName = 'ReportRet'
self.defaultFilterKey = "ListID"
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
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:
enum=cleanIncludeRetElements(self.ENUM_GeneralSummaryReportType, kwargs['GeneralSummaryReportType'])
print(enum)
self.QBDict[self.__class__.__name__ + "Rq"]["GeneralSummaryReportType"]=enum[0]
else:
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:
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']]}
elif '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 = 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
# print(self.__class__.__name__ + "Rq")
# print(f'{self.QBDict = }')
self.runCheck() ### running the qbxml connection to get data ###
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)
class CustomerQuery(baseQBQuery):
def __init__(self, *args, **kwargs):
print(f'{args = }')
print(f'{kwargs = }')
super().__init__(*args, **kwargs)
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.onError = "stopOnError"
self.retName = 'CustomerRet'
self.defaultFilterKey = "ListID"
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
self.class_debug=kwargs["debug"]
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:
IRE = cleanIncludeRetElements(self.includeRetElements_allowed, kwargs['IncludeRetElement'])
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']
print(self.__class__.__name__ + "Rq")
print(f'{self.QBDict = }' )
# print(f'{self.includeRetElements_allowed =}')
self.runCheck() ### running the qbxml connection to get data ###
class TransactionQuery(baseQBQuery):
def __init__(self, *args, **kwargs):
print(f'{args = }')
print(f'{kwargs = }')
super().__init__(*args, **kwargs)
### Required Variable
self.includeRetElements_allowed = ["TxnType", "TxnID", "TxnLineID", "TimeCreated", "TimeModified", "EntityRef", "AccountRef", "TxnDate", "RefNumber",
"Amount", "CurrencyRef", "ExchangeRate", "AmountInHomeCurrency", "Memo",
]
self.onError = "stopOnError"
self.retName = 'TransactionRet'
self.defaultFilterKey = "TxnID"
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
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 'TxnID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TxnID"]=kwargs['TxnID']
else:
if 'MaxReturned' in kwargs:
if kwargs['MaxReturned'] is None:
if 'TxnID' in kwargs:
MaxReturned = None
elif len(kwargs)>1 :
MaxReturned = None
else:
MaxReturned = 1000
elif isinstance(kwargs['MaxReturned'], str) and not kwargs['MaxReturned'].isdigit():
MaxReturned = 0
elif not isinstance(kwargs['MaxReturned'], int):
MaxReturned = 0
elif int(kwargs['MaxReturned']) > 1000:
MaxReturned = 1000
elif int(kwargs['MaxReturned']) > 0:
MaxReturned = kwargs['MaxReturned']
else:
MaxReturned = 0
else:
MaxReturned = 0
self.QBDict[self.__class__.__name__ + "Rq"]["MaxReturned"]=MaxReturned
if 'RefNumber' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumber"]=kwargs['RefNumber']
elif 'RefNumberCaseSensitive' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumberCaseSensitive"]=kwargs['RefNumberCaseSensitive']
elif 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumberFilter"]={'MatchCriterion':kwargs['RefNumberFilter_MatchCriterion', 'RefNumber':kwargs['RefNumberFilter_RefNumber']]}
elif 'RefNumberFilter_FromRefNumber' in kwargs or 'RefNumberFilter_ToRefNumber' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberFilter_ToRefNumber', "")}
if 'TransactionModifiedDateRangeFilter_FromModifiedDate' in kwargs or 'TransactionModifiedDateRangeFilter_ToModifiedDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionModifiedDateRangeFilter"]={'FromModifiedDate':kwargs.get('TransactionModifiedDateRangeFilter_FromModifiedDate', ""), 'ToModifiedDate':kwargs.get('TransactionModifiedDateRangeFilter_ToModifiedDate', "")}
elif 'TransactionModifiedDateRangeFilter_DateMacro' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionModifiedDateRangeFilter"]={'DateMacro':kwargs['TransactionModifiedDateRangeFilter_DateMacro']}
if 'TransactionDateRangeFilter_FromTxnDate' in kwargs or 'TransactionDateRangeFilter_ToTxnDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionDateRangeFilter"]={'FromTxnDate':kwargs.get('TransactionDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TransactionDateRangeFilter_ToTxnDate', "")}
elif 'TransactionDateRangeFilter_DateMacro' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionDateRangeFilter"]={'DateMacro':kwargs['TransactionDateRangeFilter_DateMacro']}
if 'TransactionEntityFilter_EntityTypeFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionEntityFilter"]={'EntityTypeFilter':kwargs['TransactionEntityFilter_EntityTypeFilter']}
elif 'TransactionEntityFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionEntityFilter"]={'ListID':kwargs['TransactionEntityFilter_ListID']}
elif 'TransactionEntityFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionEntityFilter"]={'FullName':kwargs['TransactionEntityFilter_FullName']}
elif 'TransactionEntityFilter_ListIDWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionEntityFilter"]={'ListIDWithChildren':kwargs['TransactionEntityFilter_ListIDWithChildren']}
elif 'TransactionEntityFilter_FullNameWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionEntityFilter"]={'FullNameWithChildren':kwargs['TransactionEntityFilter_FullNameWithChildren']}
if 'TransactionAccountFilter_AccountTypeFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionAccountFilter"]={'AccountTypeFilter':kwargs['TransactionAccountFilter_AccountTypeFilter']}
elif 'TransactionAccountFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionAccountFilter"]={'ListID':kwargs['TransactionAccountFilter_ListID']}
elif 'TransactionAccountFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionAccountFilter"]={'FullName':kwargs['TransactionAccountFilter_FullName']}
elif 'TransactionAccountFilter_ListIDWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionAccountFilter"]={'ListIDWithChildren':kwargs['TransactionAccountFilter_ListIDWithChildren']}
elif 'TransactionAccountFilter_FullNameWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionAccountFilter"]={'FullNameWithChildren':kwargs['TransactionAccountFilter_FullNameWithChildren']}
if 'TransactionItemFilter_ItemTypeFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionItemFilter"]={'ItemTypeFilter':kwargs['TransactionItemFilter_ItemTypeFilter']}
elif 'TransactionItemFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionItemFilter"]={'ListID':kwargs['TransactionItemFilter_ListID']}
elif 'TransactionItemFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionItemFilter"]={'FullName':kwargs['TransactionItemFilter_FullName']}
elif 'TransactionItemFilter_ListIDWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionItemFilter"]={'ListIDWithChildren':kwargs['TransactionItemFilter_ListIDWithChildren']}
elif 'TransactionItemFilter_FullNameWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionItemFilter"]={'FullNameWithChildren':kwargs['TransactionItemFilter_FullNameWithChildren']}
if 'TransactionClassFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionClassFilter"]={'ListID':kwargs['TransactionClassFilter_ListID']}
elif 'TransactionClassFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionClassFilter"]={'FullName':kwargs['TransactionClassFilter_FullName']}
elif 'TransactionClassFilter_ListIDWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionClassFilter"]={'ListIDWithChildren':kwargs['TransactionClassFilter_ListIDWithChildren']}
elif 'TransactionClassFilter_FullNameWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionClassFilter"]={'FullNameWithChildren':kwargs['TransactionClassFilter_FullNameWithChildren']}
if 'TransactionTypeFilter_TxnTypeFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionTypeFilter"]={'TxnTypeFilter':kwargs['TransactionTypeFilter_TxnTypeFilter']}
if 'TransactionDetailLevelFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionDetailLevelFilter"]=kwargs['TransactionDetailLevelFilter']
if 'TransactionPostingStatusFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionPostingStatusFilter"]=kwargs['TransactionPostingStatusFilter']
if 'TransactionPaidStatusFilter' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TransactionPaidStatusFilter"]=kwargs['TransactionPaidStatusFilter']
if 'CurrencyFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["CurrencyFilter"]=kwargs['CurrencyFilter_ListID']
elif 'CurrencyFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["CurrencyFilter"]=kwargs['CurrencyFilter_FullName']
if 'IncludeRetElement' in kwargs:
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
# print(self.__class__.__name__ + "Rq")
# print(self.QBDict)
self.runCheck() ### running the qbxml connection to get data ###
class SalesOrderQuery(baseQBQuery):
def __init__(self, *args, **kwargs):
print(f'{args = }')
print(f'{kwargs = }')
super().__init__(*args, **kwargs)
### Required Variable
self.includeRetElements_allowed = ["TxnID", "TimeCreated", "TimeModified", "EditSequence", "TxnNumber", "CustomerRef", "ClassRef", "TemplateRef",
"TxnDate", "RefNumber", "BillAddress", "BillAddressBlock", "ShipAddress", "ShipAddressBlock", "PONumber,", "TermsRef", "DueDate",
"SalesRefRef", "FOB", "ShipDate", "ShipMethodRef", "SubTotal", "ItemSalesTaxRef", "SalesTaxPercentage", "SalesTaxTotal", "TotalAmount",
"CurrencyRef", "ExchangeRate", "TotalAmountInHomeCurrency", "IsManuallyClosed", "IsFullyInvoiced", "Memo", "CustomerMsgRef", "IsToBePrinted",
"IsToBeEmailed", "IsTaxIncluded", "CustomerSalesTaxCodeRef", "Other", "ExternalGUID", "LinkedTxn", "SalesOrderLineRet", "SalesOrderLineGroupRet"
]
self.onError = "stopOnError"
self.retName = 'SalesOrderRet'
self.defaultFilterKey = "TxnID"
if 'debug' in kwargs and isinstance(kwargs['debug'], bool):
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 'TxnID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TxnID"]=kwargs['TxnID']
elif 'RefNumber' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumber"]=kwargs['RefNumber']
elif 'RefNumberCaseSensitive' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumberCaseSensitive"]=kwargs['RefNumberCaseSensitive']
else:
if 'MaxReturned' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["MaxReturned"]=kwargs['MaxReturned']
if 'ModifiedDateRangeFilter_FromModifiedDate' in kwargs or 'ModifiedDateRangeFilter_ToModifiedDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["ModifiedDateRangeFilter"]={'FromModifiedDate':kwargs.get('ModifiedDateRangeFilter_FromModifiedDate', ""), 'ToModifiedDate':kwargs.get('ModifiedDateRangeFilter_ToModifiedDate', "")}
elif 'TxnDateRangeFilter_FromTxnDate' in kwargs or 'TxnDateRangeFilter_ToTxnDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["TxnDateRangeFilter"]={'FromTxnDate':kwargs.get('TxnDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TxnDateRangeFilter_ToTxnDate', "")}
elif 'TxnDateRangeFilter_DateMacro' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["TxnDateRangeFilter"]={'DateMacro':kwargs['TxnDateRangeFilter_DateMacro']}
if 'EntityFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["EntityFilter"]={'ListID':kwargs['EntityFilter_ListID']}
elif 'EntityFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["EntityFilter"]={'FullName':kwargs['EntityFilter_FullName']}
elif 'EntityFilter_ListIDWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["EntityFilter"]={'ListIDWithChildren':kwargs['EntityFilter_ListIDWithChildren']}
elif 'EntityFilter_FullNameWithChildren' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["EntityFilter"]={'FullNameWithChildren':kwargs['EntityFilter_FullNameWithChildren']}
if 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumberFilter"]={'MatchCriterion':kwargs['RefNumberFilter_MatchCriterion', 'RefNumber':kwargs['RefNumberFilter_RefNumber']]}
elif 'RefNumberRangeFilter_FromRefNumber' in kwargs or 'RefNumberRangeFilter_ToRefNumber' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")}
self.QBDict[self.__class__.__name__ + "Rq"]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberRangeFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberRangeFilter_ToRefNumber', "")}
if 'CurrencyFilter_ListID' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["CurrencyFilter"]=kwargs['CurrencyFilter_ListID']
elif 'CurrencyFilter_FullName' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["CurrencyFilter"]=kwargs['CurrencyFilter_FullName']
if 'IncludeLineItems' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["IncludeLineItems"]=kwargs['IncludeLineItems']
if 'IncludeLinkedTxns' in kwargs:
self.QBDict[self.__class__.__name__ + "Rq"]["IncludeLinkedTxns"]=kwargs['IncludeLinkedTxns']
if 'IncludeRetElement' in kwargs:
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
if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data)
self.QBDict[self.__class__.__name__ + "Rq"]["OwnerID"]=kwargs['OwnerID']
# print(self.__class__.__name__ + "Rq")
# print(self.QBDict)
self.runCheck() ### running the qbxml connection to get data ###
if __name__ == "__main__":
@timing
def salesorderquery():
g=SalesOrderQuery(debug=False, MaxReturned = 2, EntityFilter_FullName="Abadi Serpong", TxnID="1786D5-1689047665", IncludeLineItems="true", IncludeLinkedTxns="true")
print(json.dumps(g.filter().all(), indent=3))
print(g.count())
@timing
def transactionquery():
g=TransactionQuery(debug=False, MaxReturned=None, TransactionTypeFilter_TxnTypeFilter="Invoice", TransactionEntityFilter_FullName="Abadi Serpong",
TransactionDetailLevelFilter="All", TransactionPaidStatusFilter="Open", TransactionDateRangeFilter_DateMacro="ThisFiscalYear")
# print(g.response_string)
# pprint.pprint({"temp":g.filter(['TxnType', 'TxnID', 'Entityref', 'accountref', 'txndate', 'refnumber'])})
# print(json.dumps(g.filter(['TxnType', 'TxnID', 'Entityref', 'accountref', 'refnumber','txndate',"amount" ]).all(), indent=3))
print(json.dumps(g.filter().all(), indent=3))
print(g.count())
@timing
def main():
g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear")
print(g, type(g))
print(type(g.all()))
print(g.all())
print(g.response_string)
pprint.pprint(g.filter("reportdata").all())
print(g.count(), g.all())
@timing
def iteminventoryquery():
# g=ItemInventoryQuery()
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")
# print("")
# pprint.pprint(g.filter(["FullName", "Name", "sublevel"]).all())
# print(f'{g.filter("fullname") = }')
# print(f'{g = }')
# pprint.pprint(g.response_string,indent=4 )
print(g.response_string, type(g.response_string))
print("before")
# print(g.filter([ "Name", "QuantityOnHand", "QUantityOnSalesOrder", "QuantityonOrder"]).first())
c = g.filter([ "Name", "QuantityOnHand", "QUantityOnSalesOrder", "QuantityonOrder"]).first()
print("c:",type(c), c)
# pprint.pprint(g.returnRet())
# print(g.filter("name").firstValue())
print(g.count())
print(g.statusOk)
print(g.filter(["name", "manufacturerpartnumber", "quantityonhand"]).getValuesOf(["Name","quantityonhand", "manufacturerpartnumber"]))
# print(g.filter(["DataExtRet"]).all())
@timing
def customerquery():
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"])
# print(g.IncludeRetElements_allowed)
print("init finish")
# print(f'{type(g.all()) = }')
print("before g.all")
print(f'{g.all() = }')
print("after g.all")
pprint.pprint(f'{g.filter(["FullName", "Name"]).all() = }')
print(f'{g.filter() = }')
# pprint.pprint(g.filter(["FullName", "abc", "BillAddressBlock"]).all())
print(f'{g.filter(["FullName", "abc", "BillAddressBlock"]).all() = }')
print("")
print(f'{g.filter([ "Addr1", "Addr2", "Addr3", "Addr4", "Addr5"]).all() = }')
print(f'{g.filter([ "Addr1", "Addr2", "Addr3", "Addr4", "Addr5"]) = }')
print(f'{g.filter(["fullname", "name"]).lastValue() = }')
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
salesorderquery()
# transactionquery()
# main()
# iteminventoryquery()
# customerquery()
# readxmltodict()