From 86ff9951338dabd94c1a2f561645dea18a9c60f8 Mon Sep 17 00:00:00 2001 From: bcomsugi Date: Wed, 19 Feb 2025 06:58:18 +0700 Subject: [PATCH] add exim for export import --- Exim/__init__.py | 0 Exim/exim.py | 132 +++ QBClass/QBClasses.py | 2527 +++++++++++++++++++++--------------------- QBClass/server.py | 965 ++++++++-------- 4 files changed, 1882 insertions(+), 1742 deletions(-) create mode 100644 Exim/__init__.py create mode 100644 Exim/exim.py diff --git a/Exim/__init__.py b/Exim/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Exim/exim.py b/Exim/exim.py new file mode 100644 index 0000000..5f8f03d --- /dev/null +++ b/Exim/exim.py @@ -0,0 +1,132 @@ +# from . import QBClasses +from pprint import pprint +from QBClass.QBClasses import InvoiceQuery, SalesOrderQuery +# import timeit +import time + +print('succes Loading modules') + + + +def timer(func): + def wrapper(*args, **kwargs): + nonlocal total + start = time.time() + result = func(*args, **kwargs) + duration = time.time() - start + total += duration + print(f"Execution time: {duration} Total: {total}") + return result + + total = 0 + return wrapper + + +@timer +def get_all_so_from_invoice(): + # iq = InvoiceQuery(MaxReturned= 20, IncludeLinkedTxns='true', IncludeLineItems='true') + start = time.time() + print('Get Invoice Query List. Processing..... wait for at minute(1 month=90secs)') + iq = InvoiceQuery(TxnDateRangeFilter_FromTxnDate='2024-09-1', TxnDateRangeFilter_ToTxnDate='2024-09-31', IncludeLinkedTxns='true', IncludeLineItems='true') + # pprint(iq.all(), sort_dicts=False) + # print(iq.all()) + print(f"Execution time InvoiceQuery: {time.time()-start} {len(iq.all()) = }") + so_list = [] + iq_list = [] + dup_so_list = [] + for idx, txn in enumerate(iq.all()): + # iq_list.append(txn) + # print(f"{idx = } {txn['RefNumber'] = } {txn['TxnDate'] = } {txn['Subtotal'] = } ") + if 'LinkedTxn' in txn: + # pprint(txn['LinkedTxn'], sort_dicts=False) + if not isinstance(txn['LinkedTxn'], list): #if there is no receive payment and only 1 linked traction, need to change to a list. RECORD it + txn_linkedTxn = [txn['LinkedTxn']] + else: + txn_linkedTxn = txn['LinkedTxn'] + for linkedtxn in txn_linkedTxn: + if linkedtxn['TxnType']=='SalesOrder': + if linkedtxn['RefNumber'] not in so_list: + so_list.append(linkedtxn['RefNumber']) + else: + dup_so_list.append(linkedtxn['RefNumber']) + + print(f'{dup_so_list = }') + print() + so_dict = {} + print(f"Execution time before SO: {time.time()-start}") + print('Get Sales Order Query List. Processing..... wait for at minute(1 month=130 secs)') + so = SalesOrderQuery(RefNumber = so_list, IncludeLinkedTxns='true', IncludeLineItems='true', debug=False) + print(f"Execution time SalesOrderQuery: {time.time()-start}") + for idx, txn in enumerate(so.all()): + so_dict[txn['RefNumber']] = txn + # pprint(so.all(), sort_dicts=False) + res = next(iter(so_dict)) + print(f'{so_dict[res] = }') + print(f'{len(iq.all()) = } {len(so.all()) = } {len(so_list) = } {len(dup_so_list) = } {len(so_dict) = }') + + +@timer +def process(): + # iq = InvoiceQuery(MaxReturned= 20, IncludeLinkedTxns='true', IncludeLineItems='true') + iq = InvoiceQuery(TxnDateRangeFilter_FromTxnDate='2024-02-01', TxnDateRangeFilter_ToTxnDate='2024-02-29', IncludeLinkedTxns='true', IncludeLineItems='true') + # pprint(iq.all(), sort_dicts=False) + # print(iq.all()) + for idx, txn in enumerate(iq.all()): + print(f"{idx = } {txn['RefNumber'] = } {txn['TxnDate'] = } {txn['Subtotal'] = } ") + # print(f"{txn['Subtotal'] = }") + if 'LinkedTxn' in txn: + # pprint(txn['LinkedTxn'], sort_dicts=False) + + if not isinstance(txn['LinkedTxn'], list): #if there is no receive payment and only 1 linked traction, need to change to a list. RECORD it + txn_linkedTxn = [txn['LinkedTxn']] + else: + txn_linkedTxn = txn['LinkedTxn'] + + for linkedtxn in txn_linkedTxn: + try: + if linkedtxn['TxnType']=='SalesOrder': + so = SalesOrderQuery(RefNumber = linkedtxn['RefNumber'], IncludeLinkedTxns='true', debug=False) + is_soLinkedToOneInvoice = False + if 'LinkedTxn' in so.all(): + if not isinstance(so.all()['LinkedTxn'], list): + # print(so.all()) + so_linkedTxn = [so.all()['LinkedTxn']] + else: + so_linkedTxn = so.all()['LinkedTxn'] + # print(so.all()) + for solinkedtxn in so_linkedTxn: + # print(len(so_linkedTxn)) + if solinkedtxn['TxnType']=='Invoice' and len(so_linkedTxn)==1: + # print(so.all()['RefNumber'], 'the only one SO') + is_soLinkedToOneInvoice=True + # pass + else: + is_soLinkedToOneInvoice=False + print(so.all()['RefNumber'], 'NOT the only One, this SO have other Invoice number') + + if float(linkedtxn['Amount'])<0: + if so.all()['TotalAmount']!=linkedtxn['Amount'][1:]: + if is_soLinkedToOneInvoice: #maybe the SO is manually closed, check it item by item, find which item is not in invoice + if so.all()['IsManuallyClosed'] == 'true': + pass + print(f"{so.all()['TxnID'] = } {so.all()['RefNumber'] = }") + else: + print('SO TotalAmount<>Amount in Invoice. not Manually closed and not fully Invoiced') + pprint(f'{linkedtxn = }', sort_dicts=False) + print(f"{so.all()['TxnID'] = } {so.all()['RefNumber'] = }") + print(so.all()) + else: + pass # this is one SO is fully invoiced + else: + print('Linkedtxn amount is positif(should be negatif') + except Exception as e: + print('ERROR') + pprint(linkedtxn, sort_dicts=False) + print(f"{so.all()['TxnID'] = }") + print(so.all()) + print(e) + break + +# print(timeit.repeat(process, repeat=1)) +# process() +get_all_so_from_invoice() \ No newline at end of file diff --git a/QBClass/QBClasses.py b/QBClass/QBClasses.py index 85af421..c8a741e 100644 --- a/QBClass/QBClasses.py +++ b/QBClass/QBClasses.py @@ -8,302 +8,302 @@ import json from typing import Union ENUM_DateMacro = ['All', 'Today', 'ThisWeek', 'ThisWeekToDate', 'ThisMonth', 'ThisMonthToDate', 'ThisCalendarQuarter', 'ThisCalendarQuarterToDate', 'ThisFiscalQuarter', - 'ThisFiscalQuarterToDate', 'ThisCalendarYear', 'ThisCalendarYearToDate', 'ThisFiscalYear', 'ThisFiscalYearToDate', 'Yesterday', 'LastWeek', 'LastWeekToDate', 'LastMonth', - 'LastMonthToDate', 'LastCalendarQuarter', 'LastCalendarQuarterToDate', 'LastFiscalQuarter', 'LastFiscalQuarterToDate', 'LastCalendarYear', 'LastCalendarYearToDate', - 'LastFiscalYear', 'LastFiscalYearToDate', 'NextWeek', 'NextFourWeeks', 'NextMonth', 'NextCalendarQuarter', 'NextCalendarYear', 'NextFiscalQuarter', 'NextFiscalYear' - ] + 'ThisFiscalQuarterToDate', 'ThisCalendarYear', 'ThisCalendarYearToDate', 'ThisFiscalYear', 'ThisFiscalYearToDate', 'Yesterday', 'LastWeek', 'LastWeekToDate', 'LastMonth', + 'LastMonthToDate', 'LastCalendarQuarter', 'LastCalendarQuarterToDate', 'LastFiscalQuarter', 'LastFiscalQuarterToDate', 'LastCalendarYear', 'LastCalendarYearToDate', + 'LastFiscalYear', 'LastFiscalYearToDate', 'NextWeek', 'NextFourWeeks', 'NextMonth', 'NextCalendarQuarter', 'NextCalendarYear', 'NextFiscalQuarter', 'NextFiscalYear' + ] 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", - "AverageCost", "QuantityOnOrder", "QuantityOnSalesOrder", - "ExternalGUID", "DataExtRet", - ] - self.onError = "stopOnError" - self.retName = 'ItemInventoryRet' - self.defaultFilterKey = "ListID" - self.className = "ItemInventoryQuery" - self.classNameRq:str = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] + 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", + "AverageCost", "QuantityOnOrder", "QuantityOnSalesOrder", + "ExternalGUID", "DataExtRet", + ] + self.onError = "stopOnError" + self.retName = 'ItemInventoryRet' + self.defaultFilterKey = "ListID" + self.className = "ItemInventoryQuery" + self.classNameRq:str = self.__class__.__name__ + 'Rq' + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] - self.QBDict[self.classNameRq]={} - ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) + self.QBDict[self.classNameRq]={} + ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) - if 'ListID' in kwargs: - self.QBDict[self.classNameRq]["ListID"]=kwargs['ListID'] - elif 'FullName' in kwargs: - self.QBDict[self.classNameRq]["FullName"]=kwargs['FullName'] - else: - if 'MaxReturned' in kwargs: - self.QBDict[self.classNameRq]["MaxReturned"]=kwargs['MaxReturned'] - if 'ActiveStatus' in kwargs: - self.QBDict[self.classNameRq]["ActiveStatus"]=kwargs['ActiveStatus'] - if 'FromModifiedDate' in kwargs: - self.QBDict[self.classNameRq]["FromModifiedDate"]=kwargs['FromModifiedDate'] - if 'ToModifiedDate' in kwargs: - self.QBDict[self.classNameRq]["ToModifiedDate"]=kwargs['ToModifiedDate'] - if 'MatchCriterion' in kwargs and 'Name' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} + if 'ListID' in kwargs: + self.QBDict[self.classNameRq]["ListID"]=kwargs['ListID'] + elif 'FullName' in kwargs: + self.QBDict[self.classNameRq]["FullName"]=kwargs['FullName'] + else: + if 'MaxReturned' in kwargs: + self.QBDict[self.classNameRq]["MaxReturned"]=kwargs['MaxReturned'] + if 'ActiveStatus' in kwargs: + self.QBDict[self.classNameRq]["ActiveStatus"]=kwargs['ActiveStatus'] + if 'FromModifiedDate' in kwargs: + self.QBDict[self.classNameRq]["FromModifiedDate"]=kwargs['FromModifiedDate'] + if 'ToModifiedDate' in kwargs: + self.QBDict[self.classNameRq]["ToModifiedDate"]=kwargs['ToModifiedDate'] + if 'MatchCriterion' in kwargs and 'Name' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE + 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.classNameRq]["IncludeRetElement"]=IRE - if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data) - self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] + if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data) + self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] - # print(self.classNameRq) - # print(self.QBDict) - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + # print(self.classNameRq) + # print(self.QBDict) + if self.__class__.__name__==self.className: + 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", "DataRow"] - self.onError = "stopOnError" - self.retName = 'ReportRet' - self.defaultFilterKey = "ListID" - self.className = "GeneralSummaryReportQuery" - self.classNameRq:str = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] - - self.QBDict[self.classNameRq]={} #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"] + 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", "DataRow"] + self.onError = "stopOnError" + self.retName = 'ReportRet' + self.defaultFilterKey = "ListID" + self.className = "GeneralSummaryReportQuery" + self.classNameRq:str = self.__class__.__name__ + 'Rq' + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] + + self.QBDict[self.classNameRq]={} #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(f'{enum = }') - self.QBDict[self.classNameRq]["GeneralSummaryReportType"]=enum[0] - else: - print("Error -> GeneralSummaryReportType is required") - return + if 'GeneralSummaryReportType' in kwargs: + enum=cleanIncludeRetElements(self.ENUM_GeneralSummaryReportType, kwargs['GeneralSummaryReportType']) + print(f'{enum = }') + self.QBDict[self.classNameRq]["GeneralSummaryReportType"]=enum[0] + else: + print("Error -> GeneralSummaryReportType is required") + return - # if 'DisplayReport_ReportPeriod_FromReportDate' in kwargs or 'DisplayReport_ReportPeriod_ToReportDate' in kwargs: - # self.QBDict[self.classNameRq]['DisplayReport']={'ReportPeriod':{}} - # if 'DisplayReport_ReportPeriod_FromReportDate' in kwargs: - # self.QBDict[self.classNameRq]["DisplayReport"]['ReportPeriod']['FromReportDate']=kwargs['DisplayReport_ReportPeriod_FromReportDate'] - # if 'DisplayReport_ReportPeriod_ToReportDate' in kwargs: - # self.QBDict[self.classNameRq]["DisplayReport"]['ReportPeriod']['ToReportDate']=kwargs['DisplayReport_ReportPeriod_ToReportDate'] - # elif 'DisplayReport_ReportPeriod_ReportDateMacro' in kwargs: - # self.QBDict[self.classNameRq]['DisplayReport']={"ReportDateMacro":kwargs['DisplayReport_ReportPeriod_ReportDateMacro']} - - if 'DisplayReport' in kwargs: - self.QBDict[self.classNameRq]["DisplayReport"]=kwargs['DisplayReport'] + # if 'DisplayReport_ReportPeriod_FromReportDate' in kwargs or 'DisplayReport_ReportPeriod_ToReportDate' in kwargs: + # self.QBDict[self.classNameRq]['DisplayReport']={'ReportPeriod':{}} + # if 'DisplayReport_ReportPeriod_FromReportDate' in kwargs: + # self.QBDict[self.classNameRq]["DisplayReport"]['ReportPeriod']['FromReportDate']=kwargs['DisplayReport_ReportPeriod_FromReportDate'] + # if 'DisplayReport_ReportPeriod_ToReportDate' in kwargs: + # self.QBDict[self.classNameRq]["DisplayReport"]['ReportPeriod']['ToReportDate']=kwargs['DisplayReport_ReportPeriod_ToReportDate'] + # elif 'DisplayReport_ReportPeriod_ReportDateMacro' in kwargs: + # self.QBDict[self.classNameRq]['DisplayReport']={"ReportDateMacro":kwargs['DisplayReport_ReportPeriod_ReportDateMacro']} + + if 'DisplayReport' in kwargs: + self.QBDict[self.classNameRq]["DisplayReport"]=kwargs['DisplayReport'] - if 'ReportPeriod_FromReportDate' in kwargs or 'ReportPeriod_ToReportDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")} - self.QBDict[self.classNameRq]["ReportPeriod"]={'FromReportDate':kwargs.get('ReportPeriod_FromReportDate', None), 'ToReportDate':kwargs.get('ReportPeriod_ToReportDate', None)} - elif 'ReportDateMacro' in kwargs: - self.QBDict[self.classNameRq]["ReportDateMacro"]=kwargs['ReportDateMacro'] + if 'ReportPeriod_FromReportDate' in kwargs or 'ReportPeriod_ToReportDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")} + self.QBDict[self.classNameRq]["ReportPeriod"]={'FromReportDate':kwargs.get('ReportPeriod_FromReportDate', None), 'ToReportDate':kwargs.get('ReportPeriod_ToReportDate', None)} + elif 'ReportDateMacro' in kwargs: + self.QBDict[self.classNameRq]["ReportDateMacro"]=kwargs['ReportDateMacro'] - if 'ReportAccountFilter_AccountTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["ReportAccountFilter"]={'AccountTypeFilter':kwargs['ReportAccountFilter_AccountTypeFilter']} - elif 'ReportAccountFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["ReportAccountFilter"]={'ListID':kwargs['ReportAccountFilter_ListID']} - elif 'ReportAccountFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["ReportAccountFilter"]={'FullName':kwargs['ReportAccountFilter_FullName']} - elif 'ReportAccountFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportAccountFilter"]={'ListIDWithChildren':kwargs['ReportAccountFilter_ListIDWithChildren']} - elif 'ReportAccountFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportAccountFilter"]={'FullNameWithChildren':kwargs['ReportAccountFilter_FullNameWithChildren']} + if 'ReportAccountFilter_AccountTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["ReportAccountFilter"]={'AccountTypeFilter':kwargs['ReportAccountFilter_AccountTypeFilter']} + elif 'ReportAccountFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["ReportAccountFilter"]={'ListID':kwargs['ReportAccountFilter_ListID']} + elif 'ReportAccountFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["ReportAccountFilter"]={'FullName':kwargs['ReportAccountFilter_FullName']} + elif 'ReportAccountFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportAccountFilter"]={'ListIDWithChildren':kwargs['ReportAccountFilter_ListIDWithChildren']} + elif 'ReportAccountFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportAccountFilter"]={'FullNameWithChildren':kwargs['ReportAccountFilter_FullNameWithChildren']} - if 'ReportEntityFilter_EntityTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["ReportEntityFilter"]={'EntityTypeFilter':kwargs['ReportEntityFilter_EntityTypeFilter']} - elif 'ReportEntityFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["ReportEntityFilter"]={'ListID':kwargs['ReportEntityFilter_ListID']} - elif 'ReportEntityFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["ReportEntityFilter"]={'FullName':kwargs['ReportEntityFilter_FullName']} - elif 'ReportEntityFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportEntityFilter"]={'ListIDWithChildren':kwargs['ReportEntityFilter_ListIDWithChildren']} - elif 'ReportEntityFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportEntityFilter"]={'FullNameWithChildren':kwargs['ReportEntityFilter_FullNameWithChildren']} + if 'ReportEntityFilter_EntityTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["ReportEntityFilter"]={'EntityTypeFilter':kwargs['ReportEntityFilter_EntityTypeFilter']} + elif 'ReportEntityFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["ReportEntityFilter"]={'ListID':kwargs['ReportEntityFilter_ListID']} + elif 'ReportEntityFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["ReportEntityFilter"]={'FullName':kwargs['ReportEntityFilter_FullName']} + elif 'ReportEntityFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportEntityFilter"]={'ListIDWithChildren':kwargs['ReportEntityFilter_ListIDWithChildren']} + elif 'ReportEntityFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportEntityFilter"]={'FullNameWithChildren':kwargs['ReportEntityFilter_FullNameWithChildren']} - if 'ReportItemFilter_ItemTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["ReportItemFilter"]={'ItemTypeFilter':kwargs['ReportItemFilter_ItemTypeFilter']} - elif 'ReportItemFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["ReportItemFilter"]={'ListID':kwargs['ReportItemFilter_ListID']} - elif 'ReportItemFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["ReportItemFilter"]={'FullName':kwargs['ReportItemFilter_FullName']} - elif 'ReportItemFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportItemFilter"]={'ListIDWithChildren':kwargs['ReportItemFilter_ListIDWithChildren']} - elif 'ReportItemFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportItemFilter"]={'FullNameWithChildren':kwargs['ReportItemFilter_FullNameWithChildren']} + if 'ReportItemFilter_ItemTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["ReportItemFilter"]={'ItemTypeFilter':kwargs['ReportItemFilter_ItemTypeFilter']} + elif 'ReportItemFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["ReportItemFilter"]={'ListID':kwargs['ReportItemFilter_ListID']} + elif 'ReportItemFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["ReportItemFilter"]={'FullName':kwargs['ReportItemFilter_FullName']} + elif 'ReportItemFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportItemFilter"]={'ListIDWithChildren':kwargs['ReportItemFilter_ListIDWithChildren']} + elif 'ReportItemFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportItemFilter"]={'FullNameWithChildren':kwargs['ReportItemFilter_FullNameWithChildren']} - if 'ReportClassFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["ReportClassFilter"]={'ListID':kwargs['ReportClassFilter_ListID']} - elif 'ReportClassFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["ReportClassFilter"]={'FullName':kwargs['ReportClassFilter_FullName']} - elif 'ReportClassFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportClassFilter"]={'ListIDWithChildren':kwargs['ReportClassFilter_ListIDWithChildren']} - elif 'ReportClassFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["ReportClassFilter"]={'FullNameWithChildren':kwargs['ReportClassFilter_FullNameWithChildren']} + if 'ReportClassFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["ReportClassFilter"]={'ListID':kwargs['ReportClassFilter_ListID']} + elif 'ReportClassFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["ReportClassFilter"]={'FullName':kwargs['ReportClassFilter_FullName']} + elif 'ReportClassFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportClassFilter"]={'ListIDWithChildren':kwargs['ReportClassFilter_ListIDWithChildren']} + elif 'ReportClassFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["ReportClassFilter"]={'FullNameWithChildren':kwargs['ReportClassFilter_FullNameWithChildren']} - if 'ReportTxnTypeFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["ReportTxnTypeFilter"]={'TxnTypeFilter':makeAList(kwargs['ReportTxnTypeFilter_ListID'])} - - if 'ReportModifiedDateRangeFilter_FromReportModifiedDate' in kwargs or 'ReportModifiedDateRangeFilter_ToReportModifiedDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")} - self.QBDict[self.classNameRq]["ReportModifiedDateRangeFilter"]={'FromReportModifiedDate':kwargs.get('ReportModifiedDateRangeFilter_FromReportModifiedDate', None), 'ToReportModifiedDate':kwargs.get('ReportModifiedDateRangeFilter_ToReportModifiedDate', None)} - elif 'ReportModifiedDateRangeMacro' in kwargs: - self.QBDict[self.classNameRq]["ReportModifiedDateRangeMacro"]=cleanIncludeRetElements(ENUM_DateMacro, kwargs['ReportModifiedDateRangeMacro']) + if 'ReportTxnTypeFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["ReportTxnTypeFilter"]={'TxnTypeFilter':makeAList(kwargs['ReportTxnTypeFilter_ListID'])} + + if 'ReportModifiedDateRangeFilter_FromReportModifiedDate' in kwargs or 'ReportModifiedDateRangeFilter_ToReportModifiedDate' in kwargs: #if or then use {'key1':kwargs.get('key1',""), 'key2':kwargs.get('key2', "")} + self.QBDict[self.classNameRq]["ReportModifiedDateRangeFilter"]={'FromReportModifiedDate':kwargs.get('ReportModifiedDateRangeFilter_FromReportModifiedDate', None), 'ToReportModifiedDate':kwargs.get('ReportModifiedDateRangeFilter_ToReportModifiedDate', None)} + elif 'ReportModifiedDateRangeMacro' in kwargs: + self.QBDict[self.classNameRq]["ReportModifiedDateRangeMacro"]=cleanIncludeRetElements(ENUM_DateMacro, kwargs['ReportModifiedDateRangeMacro']) - if 'ReportDetailLevelFilter' in kwargs: - self.QBDict[self.classNameRq]["ReportDetailLevelFilter"]=cleanIncludeRetElements(['All', 'AllExceptSummary', 'SummaryOnly'], kwargs['ReportDetailLevelFilter'], 'All') - if 'ReportPostingStatusFilter' in kwargs: - self.QBDict[self.classNameRq]["ReportPostingStatusFilter"]=cleanIncludeRetElements(['Either', 'NonPosting', 'Posting'], kwargs['ReportPostingStatusFilter']) - if 'SummarizeColumnsBy' in kwargs: - self.ENUM_SummarizeColumnsBy=['Account', 'BalanceSheet', 'Class', 'Customer', 'CustomerType', 'Day', 'Employee', 'FourWeek', 'HalfMonth', 'IncomeStatement', 'ItemDetail', 'ItemType', 'Month', 'Payee', - 'PaymentMethod', 'PayrollItemDetail', 'PayrollYtdDetail', 'Quarter', 'SalesRep', 'SalesTaxCode', 'ShipMethod', 'Terms', 'TotalOnly', 'TwoWeek', 'Vendor', 'VendorType', 'Week', 'Year'] - self.QBDict[self.classNameRq]["SummarizeColumnsBy"]=cleanIncludeRetElements(self.ENUM_SummarizeColumnsBy, kwargs['SummarizeColumnsBy']) - if 'IncludeSubColumns' in kwargs: - self.QBDict[self.classNameRq]["IncludeSubColumns"]=kwargs['IncludeSubColumns'] - if 'ReportCalendar' in kwargs: - self.QBDict[self.classNameRq]["ReportCalendar"]=cleanIncludeRetElements(['CalendarYear', 'FiscalYear', 'TaxYear'], kwargs['ReportCalendar'], default_val='CalendarYear') - if 'ReturnRows' in kwargs: - self.QBDict[self.classNameRq]["ReturnRows"]=cleanIncludeRetElements(['ActiveOnly', 'NonZero', 'All'], kwargs['ReturnRows'], default_val='ActiveOnly') - if 'ReturnColumns' in kwargs: - self.QBDict[self.classNameRq]["ReturnColumns"]=cleanIncludeRetElements(['ActiveOnly', 'NonZero', 'All'], kwargs['ReturnColumns'], default_val='ActiveOnly') - if 'ReportBasis' in kwargs: - self.QBDict[self.classNameRq]["ReportBasis"]=cleanIncludeRetElements(['Accrual', 'Cash', 'None'], kwargs['ReportBasis'], default_val='None') + if 'ReportDetailLevelFilter' in kwargs: + self.QBDict[self.classNameRq]["ReportDetailLevelFilter"]=cleanIncludeRetElements(['All', 'AllExceptSummary', 'SummaryOnly'], kwargs['ReportDetailLevelFilter'], 'All') + if 'ReportPostingStatusFilter' in kwargs: + self.QBDict[self.classNameRq]["ReportPostingStatusFilter"]=cleanIncludeRetElements(['Either', 'NonPosting', 'Posting'], kwargs['ReportPostingStatusFilter']) + if 'SummarizeColumnsBy' in kwargs: + self.ENUM_SummarizeColumnsBy=['Account', 'BalanceSheet', 'Class', 'Customer', 'CustomerType', 'Day', 'Employee', 'FourWeek', 'HalfMonth', 'IncomeStatement', 'ItemDetail', 'ItemType', 'Month', 'Payee', + 'PaymentMethod', 'PayrollItemDetail', 'PayrollYtdDetail', 'Quarter', 'SalesRep', 'SalesTaxCode', 'ShipMethod', 'Terms', 'TotalOnly', 'TwoWeek', 'Vendor', 'VendorType', 'Week', 'Year'] + self.QBDict[self.classNameRq]["SummarizeColumnsBy"]=cleanIncludeRetElements(self.ENUM_SummarizeColumnsBy, kwargs['SummarizeColumnsBy']) + if 'IncludeSubColumns' in kwargs: + self.QBDict[self.classNameRq]["IncludeSubColumns"]=kwargs['IncludeSubColumns'] + if 'ReportCalendar' in kwargs: + self.QBDict[self.classNameRq]["ReportCalendar"]=cleanIncludeRetElements(['CalendarYear', 'FiscalYear', 'TaxYear'], kwargs['ReportCalendar'], default_val='CalendarYear') + if 'ReturnRows' in kwargs: + self.QBDict[self.classNameRq]["ReturnRows"]=cleanIncludeRetElements(['ActiveOnly', 'NonZero', 'All'], kwargs['ReturnRows'], default_val='ActiveOnly') + if 'ReturnColumns' in kwargs: + self.QBDict[self.classNameRq]["ReturnColumns"]=cleanIncludeRetElements(['ActiveOnly', 'NonZero', 'All'], kwargs['ReturnColumns'], default_val='ActiveOnly') + if 'ReportBasis' in kwargs: + self.QBDict[self.classNameRq]["ReportBasis"]=cleanIncludeRetElements(['Accrual', 'Cash', 'None'], kwargs['ReportBasis'], default_val='None') - 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.classNameRq]["IncludeRetElement"]=IRE + 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.classNameRq]["IncludeRetElement"]=IRE - # print(self.classNameRq) - # print(f'{self.QBDict = }') - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + # print(self.classNameRq) + # print(f'{self.QBDict = }') + if self.__class__.__name__==self.className: + self.runCheck() ### running the qbxml connection to get data ### class PriceLevelQuery(baseQBQuery): - def __init__(self, *args, **kwargs): - print(f'{args = }') - print(f'{kwargs = }') - super().__init__( ) - ## Required variable - self.includeRetElements_allowed = ["ListID", "TimeCreated", "TimeModified", "EditSequence", "Name", "isActive", "PriceLevelType", "PriceLevelFixedPercentage", - "PriceLevelPerItemRet", "ItemRef", "CustomPrice", "CustomePricePercent", "CurrencyRef"] - self.onError = "stopOnError" - self.retName = 'PriceLevelRet' - self.defaultFilterKey = "ListID" - self.className = "PriceLevelQuery" - self.classNameRq:str = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] - - self.QBDict[self.classNameRq]={} #Required - ### End Required variable + def __init__(self, *args, **kwargs): + print(f'{args = }') + print(f'{kwargs = }') + super().__init__( ) + ## Required variable + self.includeRetElements_allowed = ["ListID", "TimeCreated", "TimeModified", "EditSequence", "Name", "isActive", "PriceLevelType", "PriceLevelFixedPercentage", + "PriceLevelPerItemRet", "ItemRef", "CustomPrice", "CustomePricePercent", "CurrencyRef"] + self.onError = "stopOnError" + self.retName = 'PriceLevelRet' + self.defaultFilterKey = "ListID" + self.className = "PriceLevelQuery" + self.classNameRq:str = self.__class__.__name__ + 'Rq' + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] + + self.QBDict[self.classNameRq]={} #Required + ### End Required variable - self.ENUM_ActiveStatus = ['ActiveOnly', 'InactiveOnly', 'All'] - self.ENUM_MatchCriterion = ['StartsWith', 'Contains', 'EndsWith'] + self.ENUM_ActiveStatus = ['ActiveOnly', 'InactiveOnly', 'All'] + self.ENUM_MatchCriterion = ['StartsWith', 'Contains', 'EndsWith'] - if 'ListID' in kwargs: - self.QBDict[self.classNameRq]["ListID"]=kwargs['ListID'] - elif 'FullName' in kwargs: - self.QBDict[self.classNameRq]["FullName"]=kwargs['FullName'] - else: - if 'MaxReturned' in kwargs: - self.QBDict[self.classNameRq]["MaxReturned"]=kwargs['MaxReturned'] - if 'ActiveStatus' in kwargs: - enum=cleanIncludeRetElements(self.ENUM_ActiveStatus, kwargs['ActiveStatus']) - self.QBDict[self.classNameRq]["ActiveStatus"]=enum[0] - if 'FromModifiedDate' in kwargs: - self.QBDict[self.classNameRq]["FromModifiedDate"]=kwargs['FromModifiedDate'] - if 'ToModifiedDate' in kwargs: - self.QBDict[self.classNameRq]["ToModifiedDate"]=kwargs['ToModifiedDate'] - if 'NameFilter_MatchCriterion' in kwargs and 'NameFilter_Name' in kwargs: - enum= cleanIncludeRetElements(self.ENUM_MatchCriterion, kwargs['NameFilter_MatchCriterion']) - self.QBDict[self.classNameRq]["NameFilter"]={'MatchCriterion': enum[0], 'Name': kwargs['NameFilter_Name']} - elif 'NameRangeFilter_FromName' in kwargs or 'NameRangeFilter_ToName' in kwargs: - self.QBDict[self.classNameRq]["NameRangeFilter"]={'FromName':kwargs.get('NameRangeFilter_FromName', None), 'ToReportDate':kwargs.get('NameRangeFilter_ToName', None)} - if 'ItemRef_ListID' in kwargs or 'ItemRef_FullName' in kwargs: - self.QBDict[self.classNameRq]["ItemRef"]={'ListID':kwargs.get('ItemRef_ListID', None), 'FullName':kwargs.get('ItemRef_FullName', None)} - if 'CurrencyFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=kwargs['CurrencyFilter_ListID'] - elif 'CurrencyFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE + if 'ListID' in kwargs: + self.QBDict[self.classNameRq]["ListID"]=kwargs['ListID'] + elif 'FullName' in kwargs: + self.QBDict[self.classNameRq]["FullName"]=kwargs['FullName'] + else: + if 'MaxReturned' in kwargs: + self.QBDict[self.classNameRq]["MaxReturned"]=kwargs['MaxReturned'] + if 'ActiveStatus' in kwargs: + enum=cleanIncludeRetElements(self.ENUM_ActiveStatus, kwargs['ActiveStatus']) + self.QBDict[self.classNameRq]["ActiveStatus"]=enum[0] + if 'FromModifiedDate' in kwargs: + self.QBDict[self.classNameRq]["FromModifiedDate"]=kwargs['FromModifiedDate'] + if 'ToModifiedDate' in kwargs: + self.QBDict[self.classNameRq]["ToModifiedDate"]=kwargs['ToModifiedDate'] + if 'NameFilter_MatchCriterion' in kwargs and 'NameFilter_Name' in kwargs: + enum= cleanIncludeRetElements(self.ENUM_MatchCriterion, kwargs['NameFilter_MatchCriterion']) + self.QBDict[self.classNameRq]["NameFilter"]={'MatchCriterion': enum[0], 'Name': kwargs['NameFilter_Name']} + elif 'NameRangeFilter_FromName' in kwargs or 'NameRangeFilter_ToName' in kwargs: + self.QBDict[self.classNameRq]["NameRangeFilter"]={'FromName':kwargs.get('NameRangeFilter_FromName', None), 'ToReportDate':kwargs.get('NameRangeFilter_ToName', None)} + if 'ItemRef_ListID' in kwargs or 'ItemRef_FullName' in kwargs: + self.QBDict[self.classNameRq]["ItemRef"]={'ListID':kwargs.get('ItemRef_ListID', None), 'FullName':kwargs.get('ItemRef_FullName', None)} + if 'CurrencyFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["CurrencyFilter"]=kwargs['CurrencyFilter_ListID'] + elif 'CurrencyFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE - # print(self.classNameRq) - # print(f'{self.QBDict = }') - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + # print(self.classNameRq) + # print(f'{self.QBDict = }') + if self.__class__.__name__==self.className: + self.runCheck() ### running the qbxml connection to get data ### import xmltodict def LineAdd(lineAdd:Union[list, dict])->dict: - if not(isinstance(lineAdd, list) or isinstance(lineAdd, dict)): - raise Exception(f"LineAdd Error. {type(lineAdd)}, should use dictionary or list of dictionary. ") - if isinstance(lineAdd, dict): #convert to listofdict - lineAdd = [lineAdd] - ## process LineAdd dict - resultList = [] - resdict = {} - for xLineAdd in lineAdd: - resdict={'@defMacro':'MACROTYPE'} - resdict['abc']="" - # resdict['ItemRef']={} - if 'ItemRef_ListID' in xLineAdd and xLineAdd['ItemRef_ListID']: - print(":he") - if 'ItemRef' in resdict: - resdict['ItemRef']['ListID']= xLineAdd['ItemRef_ListID'] - else: - resdict['ItemRef']={'ListID': xLineAdd['ItemRef_ListID']} - print(resdict) - if 'ItemRef_FullName' in xLineAdd and xLineAdd['ItemRef_FullName']: - resdict['ItemRef']['FullName']= xLineAdd['ItemRef_FullName'] - if 'Desc' in xLineAdd and xLineAdd['Desc']: - resdict['Desc']= xLineAdd['Desc'] - - resultList.append(resdict) - print(f'{resultList = }') - xyz=xmltodict.unparse({'root':{'LineAdd':resultList}}, pretty=True) - print(xyz) - txt = ''' - - - - 1234 - Sugiarto - - lorem - - ''' - dct = xmltodict.parse(txt) - print(f'{dct = }') + if not(isinstance(lineAdd, list) or isinstance(lineAdd, dict)): + raise Exception(f"LineAdd Error. {type(lineAdd)}, should use dictionary or list of dictionary. ") + if isinstance(lineAdd, dict): #convert to listofdict + lineAdd = [lineAdd] + ## process LineAdd dict + resultList = [] + resdict = {} + for xLineAdd in lineAdd: + resdict={'@defMacro':'MACROTYPE'} + resdict['abc']="" + # resdict['ItemRef']={} + if 'ItemRef_ListID' in xLineAdd and xLineAdd['ItemRef_ListID']: + print(":he") + if 'ItemRef' in resdict: + resdict['ItemRef']['ListID']= xLineAdd['ItemRef_ListID'] + else: + resdict['ItemRef']={'ListID': xLineAdd['ItemRef_ListID']} + print(resdict) + if 'ItemRef_FullName' in xLineAdd and xLineAdd['ItemRef_FullName']: + resdict['ItemRef']['FullName']= xLineAdd['ItemRef_FullName'] + if 'Desc' in xLineAdd and xLineAdd['Desc']: + resdict['Desc']= xLineAdd['Desc'] + + resultList.append(resdict) + print(f'{resultList = }') + xyz=xmltodict.unparse({'root':{'LineAdd':resultList}}, pretty=True) + print(xyz) + txt = ''' + + + + 1234 + Sugiarto + + lorem + + ''' + dct = xmltodict.parse(txt) + print(f'{dct = }') # x=[{'ItemRef_FullName': 'Sugiarto', 'ItemRef_ListID':1234, 'Desc':"lorem"}, {'ItemRef_FullName': 'Sugiarto', 'ItemRef_ListID':1234, 'Desc':"lorem"}] # LineAdd(x) @@ -311,1079 +311,1084 @@ def LineAdd(lineAdd:Union[list, dict])->dict: # print(cleanIncludeRetElements(['ActiveOnly', 'NonZero', 'All'], "nonzero", 'ActiveOnly')) class InvoiceAdd(baseQBQuery): - def __init__(self, *args, **kwargs): - print(f'{args = }') - print(f'{kwargs = }') - super().__init__(*args, **kwargs) - # self.includeRetElements_allowed = ['TxnID', 'TimeCreated', 'TimeModified', 'EditSequence', 'TxnNumber', 'CustomerRef', 'ClassRef', 'ARAccontRef', 'TemplateRef'] - self.onError = "stopOnError" - self.retName = 'InvoiceAddRet' + def __init__(self, *args, **kwargs): + print(f'{args = }') + print(f'{kwargs = }') + super().__init__(*args, **kwargs) + # self.includeRetElements_allowed = ['TxnID', 'TimeCreated', 'TimeModified', 'EditSequence', 'TxnNumber', 'CustomerRef', 'ClassRef', 'ARAccontRef', 'TemplateRef'] + self.onError = "stopOnError" + self.retName = 'InvoiceAddRet' - self.defaultFilterKey = "TxnID" - self.className = "InvoiceAdd" - self.classNameRq:str = self.__class__.__name__ + 'Rq' - self.reqSubName = self.className - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] + self.defaultFilterKey = "TxnID" + self.className = "InvoiceAdd" + self.classNameRq:str = self.__class__.__name__ + 'Rq' + self.reqSubName = self.className + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] - self.QBDict[self.classNameRq]={} - - self.isRequiredFieldSatisfied = False - self.QBDict[self.classNameRq][self.__class__.__name__]={'@defMacro':'MACROTYPE'} - if 'CustomerRef_ListID' in kwargs: - if 'CustomerRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]['ListID']= kwargs['CustomerRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'ListID': kwargs['CustomerRef_ListID']} - self.isRequiredFieldSatisfied=True - if 'CustomerRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'FullName': kwargs['CustomerRef_FullName']} - self.isRequiredFieldSatisfied=True - - if not self.isRequiredFieldSatisfied: - raise Exception("Need CustomerRef FullName and/or ListID") + self.QBDict[self.classNameRq]={} + + self.isRequiredFieldSatisfied = False + self.QBDict[self.classNameRq][self.__class__.__name__]={'@defMacro':'MACROTYPE'} + if 'CustomerRef_ListID' in kwargs: + if 'CustomerRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]['ListID']= kwargs['CustomerRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'ListID': kwargs['CustomerRef_ListID']} + self.isRequiredFieldSatisfied=True + if 'CustomerRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'FullName': kwargs['CustomerRef_FullName']} + self.isRequiredFieldSatisfied=True + + if not self.isRequiredFieldSatisfied: + raise Exception("Need CustomerRef FullName and/or ListID") - if 'ClassRef_ListID' in kwargs: - if 'ClassRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]['ListID']= kwargs['ClassRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'ListID': kwargs['ClassRef_ListID']} - if 'ClassRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'FullName': kwargs['ClassRef_FullName']} - - if 'ARAccountRef_ListID' in kwargs: - if 'ARAccountRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]['ListID']= kwargs['ARAccountRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'ListID': kwargs['ARAccountRef_ListID']} - if 'ARAccountRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'FullName': kwargs['ARAccountRef_FullName']} - - if 'TemplateRef_ListID' in kwargs: - if 'TemplateRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]['ListID']= kwargs['TemplateRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'ListID': kwargs['TemplateRef_ListID']} - if 'TemplateRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'FullName': kwargs['TemplateRef_FullName']} - - if 'TxnDate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["TxnDate"]=kwargs['TxnDate'] - if 'RefNumber' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["RefNumber"]=kwargs['RefNumber'] - if 'BillAddress_Addr1' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr1': kwargs['BillAddress_Addr1']} - if 'BillAddress_Addr2' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr2': kwargs['BillAddress_Addr2']} - if 'BillAddress_Addr3' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr3': kwargs['BillAddress_Addr3']} - if 'BillAddress_Addr4' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr4': kwargs['BillAddress_Addr4']} - if 'BillAddress_Addr5' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr5': kwargs['BillAddress_Addr5']} - if 'BillAddress_City' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'City': kwargs['BillAddress_City']} - if 'BillAddress_State' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'State': kwargs['BillAddress_State']} - if 'BillAddress_PostalCode' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'PostalCode': kwargs['BillAddress_PostalCode']} - if 'BillAddress_Country' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Country': kwargs['BillAddress_Country']} - if 'BillAddress_Note' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Note': kwargs['BillAddress_Note']} + if 'ClassRef_ListID' in kwargs: + if 'ClassRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]['ListID']= kwargs['ClassRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'ListID': kwargs['ClassRef_ListID']} + if 'ClassRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'FullName': kwargs['ClassRef_FullName']} + + if 'ARAccountRef_ListID' in kwargs: + if 'ARAccountRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]['ListID']= kwargs['ARAccountRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'ListID': kwargs['ARAccountRef_ListID']} + if 'ARAccountRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'FullName': kwargs['ARAccountRef_FullName']} + + if 'TemplateRef_ListID' in kwargs: + if 'TemplateRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]['ListID']= kwargs['TemplateRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'ListID': kwargs['TemplateRef_ListID']} + if 'TemplateRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'FullName': kwargs['TemplateRef_FullName']} + + if 'TxnDate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["TxnDate"]=kwargs['TxnDate'] + if 'RefNumber' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["RefNumber"]=kwargs['RefNumber'] + if 'BillAddress_Addr1' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr1': kwargs['BillAddress_Addr1']} + if 'BillAddress_Addr2' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr2': kwargs['BillAddress_Addr2']} + if 'BillAddress_Addr3' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr3': kwargs['BillAddress_Addr3']} + if 'BillAddress_Addr4' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr4': kwargs['BillAddress_Addr4']} + if 'BillAddress_Addr5' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr5': kwargs['BillAddress_Addr5']} + if 'BillAddress_City' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'City': kwargs['BillAddress_City']} + if 'BillAddress_State' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'State': kwargs['BillAddress_State']} + if 'BillAddress_PostalCode' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'PostalCode': kwargs['BillAddress_PostalCode']} + if 'BillAddress_Country' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Country': kwargs['BillAddress_Country']} + if 'BillAddress_Note' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Note': kwargs['BillAddress_Note']} - if 'ShipAddress_Addr1' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr1': kwargs['ShipAddress_Addr1']} - if 'ShipAddress_Addr2' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr2': kwargs['ShipAddress_Addr2']} - if 'ShipAddress_Addr3' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr3': kwargs['ShipAddress_Addr3']} - if 'ShipAddress_Addr4' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr4': kwargs['ShipAddress_Addr4']} - if 'ShipAddress_Addr5' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr5': kwargs['ShipAddress_Addr5']} - if 'ShipAddress_City' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'City': kwargs['ShipAddress_City']} - if 'ShipAddress_State' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'State': kwargs['ShipAddress_State']} - if 'ShipAddress_PostalCode' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'PostalCode': kwargs['ShipAddress_PostalCode']} - if 'ShipAddress_Country' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Country': kwargs['ShipAddress_Country']} - if 'ShipAddress_Note' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Note': kwargs['ShipAddress_Note']} - - if 'IsPending' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsPending"]=kwargs['IsPending'] - if 'IsFinanceCharge' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsFinanceCharge"]=kwargs['IsFinanceCharge'] - if 'PONumber' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["PONumber"]=kwargs['PONumber'] - if 'TermsRef_ListID' in kwargs: - if 'TermsRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]['ListID']= kwargs['TermsRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'ListID': kwargs['TermsRef_ListID']} - if 'TermsRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'FullName': kwargs['TermsRef_FullName']} - - if 'DueDate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["DueDate"]=kwargs['DueDate'] - if 'SalesRepRef_ListID' in kwargs: - if 'SalesRepRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]['ListID']= kwargs['SalesRepRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'ListID': kwargs['SalesRepRef_ListID']} - if 'SalesRepRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'FullName': kwargs['SalesRepRef_FullName']} - - if 'FOB' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["FOB"]=kwargs['FOB'] - if 'ShipDate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipDate"]=kwargs['ShipDate'] - if 'ShipMethodRef_ListID' in kwargs: - if 'ShipMethodRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]['ListID']= kwargs['ShipMethodRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'ListID': kwargs['ShipMethodRef_ListID']} - if 'ShipMethodRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'FullName': kwargs['ShipMethodRef_FullName']} - - if 'ItemSalesTaxRef_ListID' in kwargs: - if 'ItemSalesTaxRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]['ListID']= kwargs['ItemSalesTaxRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'ListID': kwargs['ItemSalesTaxRef_ListID']} - if 'ItemSalesTaxRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'FullName': kwargs['ItemSalesTaxRef_FullName']} - - if 'Memo' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["Memo"]=kwargs['Memo'] - if 'CustomerMsgRef_ListID' in kwargs: - if 'CustomerMsgRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]['ListID']= kwargs['CustomerMsgRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'ListID': kwargs['CustomerMsgRef_ListID']} - if 'CustomerMsgRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'FullName': kwargs['CustomerMsgRef_FullName']} - - if 'IsToBePrinted' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBePrinted"]=kwargs['IsToBePrinted'] - if 'IsToBeEmailed' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBeEmailed"]=kwargs['IsToBeEmailed'] - if 'IsTaxIncluded' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsTaxIncluded"]=kwargs['IsTaxIncluded'] - if 'CustomerSalesTaxCodeRef_ListID' in kwargs: - if 'CustomerSalesTaxCodeRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]['ListID']= kwargs['CustomerSalesTaxCodeRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'ListID': kwargs['CustomerSalesTaxCodeRef_ListID']} - if 'CustomerSalesTaxCodeRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'FullName': kwargs['CustomerSalesTaxCodeRef_FullName']} - - if 'Other' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["Other"]=kwargs['Other'] - if 'ExchangeRate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ExchangeRate"]=kwargs['ExchangeRate'] - if 'ExternalGUID' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ExternalGUID"]=kwargs['ExternalGUID'] - if 'LinkToTxnID' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["LinkToTxnID"]=makeAList(kwargs['LinkToTxnID']) - - if 'SetCredit_CreditTxnID' in kwargs and 'SetCredit_AppliedAmount' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]={'CreditTxnID':{'@useMacro':"MACROTYPE", '#text':kwargs['SetCredit_CreditTxnID']}, 'AppliedAmount': kwargs['SetCredit_AppliedAmount']} - if 'SetCredit_Override' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]["Override"]=kwargs['SetCredit_Override'] - #add InvoiceLineAdd kwargs here - + if 'ShipAddress_Addr1' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr1': kwargs['ShipAddress_Addr1']} + if 'ShipAddress_Addr2' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr2': kwargs['ShipAddress_Addr2']} + if 'ShipAddress_Addr3' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr3': kwargs['ShipAddress_Addr3']} + if 'ShipAddress_Addr4' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr4': kwargs['ShipAddress_Addr4']} + if 'ShipAddress_Addr5' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr5': kwargs['ShipAddress_Addr5']} + if 'ShipAddress_City' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'City': kwargs['ShipAddress_City']} + if 'ShipAddress_State' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'State': kwargs['ShipAddress_State']} + if 'ShipAddress_PostalCode' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'PostalCode': kwargs['ShipAddress_PostalCode']} + if 'ShipAddress_Country' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Country': kwargs['ShipAddress_Country']} + if 'ShipAddress_Note' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Note': kwargs['ShipAddress_Note']} + + if 'IsPending' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsPending"]=kwargs['IsPending'] + if 'IsFinanceCharge' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsFinanceCharge"]=kwargs['IsFinanceCharge'] + if 'PONumber' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["PONumber"]=kwargs['PONumber'] + if 'TermsRef_ListID' in kwargs: + if 'TermsRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]['ListID']= kwargs['TermsRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'ListID': kwargs['TermsRef_ListID']} + if 'TermsRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'FullName': kwargs['TermsRef_FullName']} + + if 'DueDate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["DueDate"]=kwargs['DueDate'] + if 'SalesRepRef_ListID' in kwargs: + if 'SalesRepRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]['ListID']= kwargs['SalesRepRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'ListID': kwargs['SalesRepRef_ListID']} + if 'SalesRepRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'FullName': kwargs['SalesRepRef_FullName']} + + if 'FOB' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["FOB"]=kwargs['FOB'] + if 'ShipDate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipDate"]=kwargs['ShipDate'] + if 'ShipMethodRef_ListID' in kwargs: + if 'ShipMethodRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]['ListID']= kwargs['ShipMethodRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'ListID': kwargs['ShipMethodRef_ListID']} + if 'ShipMethodRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'FullName': kwargs['ShipMethodRef_FullName']} + + if 'ItemSalesTaxRef_ListID' in kwargs: + if 'ItemSalesTaxRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]['ListID']= kwargs['ItemSalesTaxRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'ListID': kwargs['ItemSalesTaxRef_ListID']} + if 'ItemSalesTaxRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'FullName': kwargs['ItemSalesTaxRef_FullName']} + + if 'Memo' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["Memo"]=kwargs['Memo'] + if 'CustomerMsgRef_ListID' in kwargs: + if 'CustomerMsgRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]['ListID']= kwargs['CustomerMsgRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'ListID': kwargs['CustomerMsgRef_ListID']} + if 'CustomerMsgRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'FullName': kwargs['CustomerMsgRef_FullName']} + + if 'IsToBePrinted' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBePrinted"]=kwargs['IsToBePrinted'] + if 'IsToBeEmailed' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBeEmailed"]=kwargs['IsToBeEmailed'] + if 'IsTaxIncluded' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsTaxIncluded"]=kwargs['IsTaxIncluded'] + if 'CustomerSalesTaxCodeRef_ListID' in kwargs: + if 'CustomerSalesTaxCodeRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]['ListID']= kwargs['CustomerSalesTaxCodeRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'ListID': kwargs['CustomerSalesTaxCodeRef_ListID']} + if 'CustomerSalesTaxCodeRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'FullName': kwargs['CustomerSalesTaxCodeRef_FullName']} + + if 'Other' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["Other"]=kwargs['Other'] + if 'ExchangeRate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ExchangeRate"]=kwargs['ExchangeRate'] + if 'ExternalGUID' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ExternalGUID"]=kwargs['ExternalGUID'] + if 'LinkToTxnID' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["LinkToTxnID"]=makeAList(kwargs['LinkToTxnID']) + + if 'SetCredit_CreditTxnID' in kwargs and 'SetCredit_AppliedAmount' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]={'CreditTxnID':{'@useMacro':"MACROTYPE", '#text':kwargs['SetCredit_CreditTxnID']}, 'AppliedAmount': kwargs['SetCredit_AppliedAmount']} + if 'SetCredit_Override' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]["Override"]=kwargs['SetCredit_Override'] +#add InvoiceLineAdd kwargs here + - if 'IncludeRetElement' in kwargs: - self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement'] + if 'IncludeRetElement' in kwargs: + self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement'] - # print(self.classNameRq) - # print(self.QBDict) + # print(self.classNameRq) + # 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" - self.className = "CustomerQuery" - self.classNameRq:str = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] - - self.QBDict[self.classNameRq]={} + 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" + self.className = "CustomerQuery" + self.classNameRq:str = self.__class__.__name__ + 'Rq' + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] + + self.QBDict[self.classNameRq]={} - if 'ListID' in kwargs: - self.QBDict[self.classNameRq]["ListID"]=kwargs['ListID'] - elif 'FullName' in kwargs: - self.QBDict[self.classNameRq]["FullName"]=kwargs['FullName'] - else: - if 'MaxReturned' in kwargs: - self.QBDict[self.classNameRq]["MaxReturned"]=kwargs['MaxReturned'] - if 'ActiveStatus' in kwargs: - self.QBDict[self.classNameRq]["ActiveStatus"]=kwargs['ActiveStatus'] - if 'FromModifiedDate' in kwargs: - self.QBDict[self.classNameRq]["FromModifiedDate"]=kwargs['FromModifiedDate'] - if 'ToModifiedDate' in kwargs: - self.QBDict[self.classNameRq]["ToModifiedDate"]=kwargs['ToModifiedDate'] - if 'MatchCriterion' in kwargs and 'Name' in kwargs: - self.QBDict[self.classNameRq]["NameFilter"]={'MatchCriterion':kwargs['MatchCriterion'], 'Name':kwargs['Name']} - elif 'FromName' in kwargs or 'ToName' in kwargs: - self.QBDict[self.classNameRq]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} + if 'ListID' in kwargs: + self.QBDict[self.classNameRq]["ListID"]=kwargs['ListID'] + elif 'FullName' in kwargs: + self.QBDict[self.classNameRq]["FullName"]=kwargs['FullName'] + else: + if 'MaxReturned' in kwargs: + self.QBDict[self.classNameRq]["MaxReturned"]=kwargs['MaxReturned'] + if 'ActiveStatus' in kwargs: + self.QBDict[self.classNameRq]["ActiveStatus"]=kwargs['ActiveStatus'] + if 'FromModifiedDate' in kwargs: + self.QBDict[self.classNameRq]["FromModifiedDate"]=kwargs['FromModifiedDate'] + if 'ToModifiedDate' in kwargs: + self.QBDict[self.classNameRq]["ToModifiedDate"]=kwargs['ToModifiedDate'] + if 'MatchCriterion' in kwargs and 'Name' in kwargs: + self.QBDict[self.classNameRq]["NameFilter"]={'MatchCriterion':kwargs['MatchCriterion'], 'Name':kwargs['Name']} + elif 'FromName' in kwargs or 'ToName' in kwargs: + self.QBDict[self.classNameRq]["NameRangeFilter"]={'FromName':kwargs.get('FromName', ""), 'ToName':kwargs.get('ToName', "")} - if 'Operator' in kwargs and 'Amount' in kwargs: - self.QBDict[self.classNameRq]["TotalBalanceFilter"]={'Operator':kwargs['Operator'], 'Amount':kwargs['Amount']} - if 'IncludeRetElement' in kwargs and kwargs['IncludeRetElement']: - 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.classNameRq]["IncludeRetElement"]=IRE - else: - self.QBDict[self.classNameRq]["IncludeRetElement"]=self.includeRetElements_allowed - if 'OwnerID' in kwargs: - self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] + if 'Operator' in kwargs and 'Amount' in kwargs: + self.QBDict[self.classNameRq]["TotalBalanceFilter"]={'Operator':kwargs['Operator'], 'Amount':kwargs['Amount']} + if 'IncludeRetElement' in kwargs and kwargs['IncludeRetElement']: + 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.classNameRq]["IncludeRetElement"]=IRE + else: + self.QBDict[self.classNameRq]["IncludeRetElement"]=self.includeRetElements_allowed + if 'OwnerID' in kwargs: + self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] - print(self.classNameRq) - print(f'{self.QBDict = }' ) - # print(f'{self.includeRetElements_allowed =}') - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + print(self.classNameRq) + print(f'{self.QBDict = }' ) + # print(f'{self.includeRetElements_allowed =}') + if self.__class__.__name__==self.className: + 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" - self.className = "TransactionQuery" - self.classNameRq = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] + 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" + self.className = "TransactionQuery" + self.classNameRq = self.__class__.__name__ + 'Rq' + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] - self.QBDict[self.classNameRq]={} - ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) + self.QBDict[self.classNameRq]={} + ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) - if 'TxnID' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["MaxReturned"]=MaxReturned + if 'TxnID' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["MaxReturned"]=MaxReturned - if 'RefNumber' in kwargs: - self.QBDict[self.classNameRq]["RefNumber"]=kwargs['RefNumber'] - elif 'RefNumberCaseSensitive' in kwargs: - self.QBDict[self.classNameRq]["RefNumberCaseSensitive"]=kwargs['RefNumberCaseSensitive'] - elif 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberFilter_ToRefNumber', "")} + if 'RefNumber' in kwargs: + self.QBDict[self.classNameRq]["RefNumber"]=kwargs['RefNumber'] + elif 'RefNumberCaseSensitive' in kwargs: + self.QBDict[self.classNameRq]["RefNumberCaseSensitive"]=kwargs['RefNumberCaseSensitive'] + elif 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["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.classNameRq]["TransactionModifiedDateRangeFilter"]={'FromModifiedDate':kwargs.get('TransactionModifiedDateRangeFilter_FromModifiedDate', ""), 'ToModifiedDate':kwargs.get('TransactionModifiedDateRangeFilter_ToModifiedDate', "")} - elif 'TransactionModifiedDateRangeFilter_DateMacro' in kwargs: - self.QBDict[self.classNameRq]["TransactionModifiedDateRangeFilter"]={'DateMacro':kwargs['TransactionModifiedDateRangeFilter_DateMacro']} + 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.classNameRq]["TransactionModifiedDateRangeFilter"]={'FromModifiedDate':kwargs.get('TransactionModifiedDateRangeFilter_FromModifiedDate', ""), 'ToModifiedDate':kwargs.get('TransactionModifiedDateRangeFilter_ToModifiedDate', "")} + elif 'TransactionModifiedDateRangeFilter_DateMacro' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["TransactionDateRangeFilter"]={'FromTxnDate':kwargs.get('TransactionDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TransactionDateRangeFilter_ToTxnDate', "")} - elif 'TransactionDateRangeFilter_DateMacro' in kwargs: - self.QBDict[self.classNameRq]["TransactionDateRangeFilter"]={'DateMacro':kwargs['TransactionDateRangeFilter_DateMacro']} - - # - if 'TransactionEntityFilter_EntityTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'EntityTypeFilter':kwargs['TransactionEntityFilter_EntityTypeFilter']} - elif 'TransactionEntityFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'ListID':kwargs['TransactionEntityFilter_ListID']} - elif 'TransactionEntityFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'FullName':kwargs['TransactionEntityFilter_FullName']} - elif 'TransactionEntityFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'ListIDWithChildren':kwargs['TransactionEntityFilter_ListIDWithChildren']} - elif 'TransactionEntityFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'FullNameWithChildren':kwargs['TransactionEntityFilter_FullNameWithChildren']} - - # - if 'TransactionAccountFilter_AccountTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'AccountTypeFilter':kwargs['TransactionAccountFilter_AccountTypeFilter']} - elif 'TransactionAccountFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'ListID':kwargs['TransactionAccountFilter_ListID']} - elif 'TransactionAccountFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'FullName':kwargs['TransactionAccountFilter_FullName']} - elif 'TransactionAccountFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'ListIDWithChildren':kwargs['TransactionAccountFilter_ListIDWithChildren']} - elif 'TransactionAccountFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'FullNameWithChildren':kwargs['TransactionAccountFilter_FullNameWithChildren']} + 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.classNameRq]["TransactionDateRangeFilter"]={'FromTxnDate':kwargs.get('TransactionDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TransactionDateRangeFilter_ToTxnDate', "")} + elif 'TransactionDateRangeFilter_DateMacro' in kwargs: + self.QBDict[self.classNameRq]["TransactionDateRangeFilter"]={'DateMacro':kwargs['TransactionDateRangeFilter_DateMacro']} + + # + if 'TransactionEntityFilter_EntityTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'EntityTypeFilter':kwargs['TransactionEntityFilter_EntityTypeFilter']} + elif 'TransactionEntityFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'ListID':kwargs['TransactionEntityFilter_ListID']} + elif 'TransactionEntityFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'FullName':kwargs['TransactionEntityFilter_FullName']} + elif 'TransactionEntityFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'ListIDWithChildren':kwargs['TransactionEntityFilter_ListIDWithChildren']} + elif 'TransactionEntityFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionEntityFilter"]={'FullNameWithChildren':kwargs['TransactionEntityFilter_FullNameWithChildren']} + + # + if 'TransactionAccountFilter_AccountTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'AccountTypeFilter':kwargs['TransactionAccountFilter_AccountTypeFilter']} + elif 'TransactionAccountFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'ListID':kwargs['TransactionAccountFilter_ListID']} + elif 'TransactionAccountFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'FullName':kwargs['TransactionAccountFilter_FullName']} + elif 'TransactionAccountFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'ListIDWithChildren':kwargs['TransactionAccountFilter_ListIDWithChildren']} + elif 'TransactionAccountFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionAccountFilter"]={'FullNameWithChildren':kwargs['TransactionAccountFilter_FullNameWithChildren']} - # - if 'TransactionItemFilter_ItemTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionItemFilter"]={'ItemTypeFilter':kwargs['TransactionItemFilter_ItemTypeFilter']} - elif 'TransactionItemFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["TransactionItemFilter"]={'ListID':kwargs['TransactionItemFilter_ListID']} - elif 'TransactionItemFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["TransactionItemFilter"]={'FullName':kwargs['TransactionItemFilter_FullName']} - elif 'TransactionItemFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionItemFilter"]={'ListIDWithChildren':kwargs['TransactionItemFilter_ListIDWithChildren']} - elif 'TransactionItemFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionItemFilter"]={'FullNameWithChildren':kwargs['TransactionItemFilter_FullNameWithChildren']} + # + if 'TransactionItemFilter_ItemTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionItemFilter"]={'ItemTypeFilter':kwargs['TransactionItemFilter_ItemTypeFilter']} + elif 'TransactionItemFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["TransactionItemFilter"]={'ListID':kwargs['TransactionItemFilter_ListID']} + elif 'TransactionItemFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["TransactionItemFilter"]={'FullName':kwargs['TransactionItemFilter_FullName']} + elif 'TransactionItemFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionItemFilter"]={'ListIDWithChildren':kwargs['TransactionItemFilter_ListIDWithChildren']} + elif 'TransactionItemFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionItemFilter"]={'FullNameWithChildren':kwargs['TransactionItemFilter_FullNameWithChildren']} - if 'TransactionClassFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["TransactionClassFilter"]={'ListID':kwargs['TransactionClassFilter_ListID']} - elif 'TransactionClassFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["TransactionClassFilter"]={'FullName':kwargs['TransactionClassFilter_FullName']} - elif 'TransactionClassFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionClassFilter"]={'ListIDWithChildren':kwargs['TransactionClassFilter_ListIDWithChildren']} - elif 'TransactionClassFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["TransactionClassFilter"]={'FullNameWithChildren':kwargs['TransactionClassFilter_FullNameWithChildren']} - - # - if 'TransactionTypeFilter_TxnTypeFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionTypeFilter"]={'TxnTypeFilter':kwargs['TransactionTypeFilter_TxnTypeFilter']} - - # - if 'TransactionDetailLevelFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionDetailLevelFilter"]=kwargs['TransactionDetailLevelFilter'] - - # - if 'TransactionPostingStatusFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionPostingStatusFilter"]=kwargs['TransactionPostingStatusFilter'] - - # - if 'TransactionPaidStatusFilter' in kwargs: - self.QBDict[self.classNameRq]["TransactionPaidStatusFilter"]=kwargs['TransactionPaidStatusFilter'] - - if 'CurrencyFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=kwargs['CurrencyFilter_ListID'] - elif 'CurrencyFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=kwargs['CurrencyFilter_FullName'] + if 'TransactionClassFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["TransactionClassFilter"]={'ListID':kwargs['TransactionClassFilter_ListID']} + elif 'TransactionClassFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["TransactionClassFilter"]={'FullName':kwargs['TransactionClassFilter_FullName']} + elif 'TransactionClassFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionClassFilter"]={'ListIDWithChildren':kwargs['TransactionClassFilter_ListIDWithChildren']} + elif 'TransactionClassFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["TransactionClassFilter"]={'FullNameWithChildren':kwargs['TransactionClassFilter_FullNameWithChildren']} + + # + if 'TransactionTypeFilter_TxnTypeFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionTypeFilter"]={'TxnTypeFilter':kwargs['TransactionTypeFilter_TxnTypeFilter']} + + # + if 'TransactionDetailLevelFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionDetailLevelFilter"]=kwargs['TransactionDetailLevelFilter'] + + # + if 'TransactionPostingStatusFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionPostingStatusFilter"]=kwargs['TransactionPostingStatusFilter'] + + # + if 'TransactionPaidStatusFilter' in kwargs: + self.QBDict[self.classNameRq]["TransactionPaidStatusFilter"]=kwargs['TransactionPaidStatusFilter'] + + if 'CurrencyFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["CurrencyFilter"]=kwargs['CurrencyFilter_ListID'] + elif 'CurrencyFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE + 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.classNameRq]["IncludeRetElement"]=IRE - # print(self.classNameRq) - # print(self.QBDict) - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + # print(self.classNameRq) + # print(self.QBDict) + if self.__class__.__name__==self.className: + self.runCheck() ### running the qbxml connection to get data ### class SalesOrderAdd(baseQBQuery): - def __init__(self, *args, **kwargs): - print(f'{args = }') - print(f'{kwargs = }') - super().__init__(*args, **kwargs) - # self.includeRetElements_allowed = ['TxnID', 'TimeCreated', 'TimeModified', 'EditSequence', 'TxnNumber', 'CustomerRef', 'ClassRef', 'ARAccontRef', 'TemplateRef'] - self.onError = "stopOnError" - self.retName = 'SalesOrderRet' + def __init__(self, *args, **kwargs): + print(f'{args = }') + print(f'{kwargs = }') + super().__init__(*args, **kwargs) + # self.includeRetElements_allowed = ['TxnID', 'TimeCreated', 'TimeModified', 'EditSequence', 'TxnNumber', 'CustomerRef', 'ClassRef', 'ARAccontRef', 'TemplateRef'] + self.onError = "stopOnError" + self.retName = 'SalesOrderRet' - self.defaultFilterKey = "TxnID" - self.className = "SalesOrderAdd" - self.classNameRq:str = self.__class__.__name__ + 'Rq' - self.reqSubName = self.className - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] + self.defaultFilterKey = "TxnID" + self.className = "SalesOrderAdd" + self.classNameRq:str = self.__class__.__name__ + 'Rq' + self.reqSubName = self.className + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] - self.QBDict[self.classNameRq]={} - + self.QBDict[self.classNameRq]={} + - - self.isRequiredFieldSatisfied = False - if 'requestID' in kwargs: - self.QBDict[self.classNameRq]={'@requestID':kwargs.get('requestID', '1')} - self.QBDict[self.classNameRq][self.__class__.__name__]={'@defMacro':'MACROTYPE'} - if 'CustomerRef_ListID' in kwargs: - if 'CustomerRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]['ListID']= kwargs['CustomerRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'ListID': kwargs['CustomerRef_ListID']} - self.isRequiredFieldSatisfied=True - if 'CustomerRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'FullName': kwargs['CustomerRef_FullName']} - self.isRequiredFieldSatisfied=True - - if not self.isRequiredFieldSatisfied: - raise Exception("Need CustomerRef FullName and/or ListID") + + self.isRequiredFieldSatisfied = False + if 'requestID' in kwargs: + self.QBDict[self.classNameRq]={'@requestID':kwargs.get('requestID', '1')} + self.QBDict[self.classNameRq][self.__class__.__name__]={'@defMacro':'MACROTYPE'} + if 'CustomerRef_ListID' in kwargs: + if 'CustomerRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]['ListID']= kwargs['CustomerRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'ListID': kwargs['CustomerRef_ListID']} + self.isRequiredFieldSatisfied=True + if 'CustomerRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerRef"]={'FullName': kwargs['CustomerRef_FullName']} + self.isRequiredFieldSatisfied=True + + if not self.isRequiredFieldSatisfied: + raise Exception("Need CustomerRef FullName and/or ListID") - if 'ClassRef_ListID' in kwargs: - if 'ClassRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]['ListID']= kwargs['ClassRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'ListID': kwargs['ClassRef_ListID']} - if 'ClassRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'FullName': kwargs['ClassRef_FullName']} - - # if 'ARAccountRef_ListID' in kwargs: - # if 'ARAccountRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - # self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]['ListID']= kwargs['ARAccountRef_ListID'] - # else: - # self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'ListID': kwargs['ARAccountRef_ListID']} - # if 'ARAccountRef_FullName' in kwargs: - # self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'FullName': kwargs['ARAccountRef_FullName']} - - if 'TemplateRef_ListID' in kwargs: - if 'TemplateRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]['ListID']= kwargs['TemplateRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'ListID': kwargs['TemplateRef_ListID']} - if 'TemplateRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'FullName': kwargs['TemplateRef_FullName']} - - if 'TxnDate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["TxnDate"]=kwargs['TxnDate'] - if 'RefNumber' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["RefNumber"]=kwargs['RefNumber'] - if 'BillAddress_Addr1' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr1': kwargs['BillAddress_Addr1']} - if 'BillAddress_Addr2' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr2': kwargs['BillAddress_Addr2']} - if 'BillAddress_Addr3' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr3': kwargs['BillAddress_Addr3']} - if 'BillAddress_Addr4' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr4': kwargs['BillAddress_Addr4']} - if 'BillAddress_Addr5' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr5': kwargs['BillAddress_Addr5']} - if 'BillAddress_City' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'City': kwargs['BillAddress_City']} - if 'BillAddress_State' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'State': kwargs['BillAddress_State']} - if 'BillAddress_PostalCode' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'PostalCode': kwargs['BillAddress_PostalCode']} - if 'BillAddress_Country' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Country': kwargs['BillAddress_Country']} - if 'BillAddress_Note' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Note': kwargs['BillAddress_Note']} + if 'ClassRef_ListID' in kwargs: + if 'ClassRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]['ListID']= kwargs['ClassRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'ListID': kwargs['ClassRef_ListID']} + if 'ClassRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ClassRef"]={'FullName': kwargs['ClassRef_FullName']} + + # if 'ARAccountRef_ListID' in kwargs: + # if 'ARAccountRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + # self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]['ListID']= kwargs['ARAccountRef_ListID'] + # else: + # self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'ListID': kwargs['ARAccountRef_ListID']} + # if 'ARAccountRef_FullName' in kwargs: + # self.QBDict[self.classNameRq][self.__class__.__name__]["ARAccountRef"]={'FullName': kwargs['ARAccountRef_FullName']} + + if 'TemplateRef_ListID' in kwargs: + if 'TemplateRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]['ListID']= kwargs['TemplateRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'ListID': kwargs['TemplateRef_ListID']} + if 'TemplateRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["TemplateRef"]={'FullName': kwargs['TemplateRef_FullName']} + + if 'TxnDate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["TxnDate"]=kwargs['TxnDate'] + if 'RefNumber' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["RefNumber"]=kwargs['RefNumber'] + if 'BillAddress_Addr1' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr1': kwargs['BillAddress_Addr1']} + if 'BillAddress_Addr2' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr2': kwargs['BillAddress_Addr2']} + if 'BillAddress_Addr3' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr3': kwargs['BillAddress_Addr3']} + if 'BillAddress_Addr4' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr4': kwargs['BillAddress_Addr4']} + if 'BillAddress_Addr5' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Addr5': kwargs['BillAddress_Addr5']} + if 'BillAddress_City' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'City': kwargs['BillAddress_City']} + if 'BillAddress_State' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'State': kwargs['BillAddress_State']} + if 'BillAddress_PostalCode' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'PostalCode': kwargs['BillAddress_PostalCode']} + if 'BillAddress_Country' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Country': kwargs['BillAddress_Country']} + if 'BillAddress_Note' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["BillAddress"]={'Note': kwargs['BillAddress_Note']} - if 'ShipAddress_Addr1' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr1': kwargs['ShipAddress_Addr1']} - if 'ShipAddress_Addr2' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr2': kwargs['ShipAddress_Addr2']} - if 'ShipAddress_Addr3' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr3': kwargs['ShipAddress_Addr3']} - if 'ShipAddress_Addr4' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr4': kwargs['ShipAddress_Addr4']} - if 'ShipAddress_Addr5' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr5': kwargs['ShipAddress_Addr5']} - if 'ShipAddress_City' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'City': kwargs['ShipAddress_City']} - if 'ShipAddress_State' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'State': kwargs['ShipAddress_State']} - if 'ShipAddress_PostalCode' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'PostalCode': kwargs['ShipAddress_PostalCode']} - if 'ShipAddress_Country' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Country': kwargs['ShipAddress_Country']} - if 'ShipAddress_Note' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Note': kwargs['ShipAddress_Note']} - - if 'IsPending' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsPending"]=kwargs['IsPending'] - if 'IsFinanceCharge' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsFinanceCharge"]=kwargs['IsFinanceCharge'] - if 'PONumber' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["PONumber"]=kwargs['PONumber'] - if 'TermsRef_ListID' in kwargs: - if 'TermsRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]['ListID']= kwargs['TermsRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'ListID': kwargs['TermsRef_ListID']} - if 'TermsRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'FullName': kwargs['TermsRef_FullName']} - - if 'DueDate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["DueDate"]=kwargs['DueDate'] - if 'SalesRepRef_ListID' in kwargs: - if 'SalesRepRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]['ListID']= kwargs['SalesRepRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'ListID': kwargs['SalesRepRef_ListID']} - if 'SalesRepRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'FullName': kwargs['SalesRepRef_FullName']} - - if 'FOB' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["FOB"]=kwargs['FOB'] - if 'ShipDate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipDate"]=kwargs['ShipDate'] - if 'ShipMethodRef_ListID' in kwargs: - if 'ShipMethodRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]['ListID']= kwargs['ShipMethodRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'ListID': kwargs['ShipMethodRef_ListID']} - if 'ShipMethodRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'FullName': kwargs['ShipMethodRef_FullName']} - - if 'ItemSalesTaxRef_ListID' in kwargs: - if 'ItemSalesTaxRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]['ListID']= kwargs['ItemSalesTaxRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'ListID': kwargs['ItemSalesTaxRef_ListID']} - if 'ItemSalesTaxRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'FullName': kwargs['ItemSalesTaxRef_FullName']} - - if 'IsManuallyClosed' in kwargs: #only SalesOrderAdd. not in InvoiceAdd - self.QBDict[self.classNameRq][self.__class__.__name__]["IsManuallyClosed"]=kwargs['IsManuallyClosed'] - if 'Memo' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["Memo"]=kwargs['Memo'] - if 'CustomerMsgRef_ListID' in kwargs: - if 'CustomerMsgRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]['ListID']= kwargs['CustomerMsgRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'ListID': kwargs['CustomerMsgRef_ListID']} - if 'CustomerMsgRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'FullName': kwargs['CustomerMsgRef_FullName']} - - if 'IsToBePrinted' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBePrinted"]=kwargs['IsToBePrinted'] - if 'IsToBeEmailed' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBeEmailed"]=kwargs['IsToBeEmailed'] - if 'IsTaxIncluded' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["IsTaxIncluded"]=kwargs['IsTaxIncluded'] - if 'CustomerSalesTaxCodeRef_ListID' in kwargs: - if 'CustomerSalesTaxCodeRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]['ListID']= kwargs['CustomerSalesTaxCodeRef_ListID'] - else: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'ListID': kwargs['CustomerSalesTaxCodeRef_ListID']} - if 'CustomerSalesTaxCodeRef_FullName' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'FullName': kwargs['CustomerSalesTaxCodeRef_FullName']} - - if 'Other' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["Other"]=kwargs['Other'] - if 'ExchangeRate' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ExchangeRate"]=kwargs['ExchangeRate'] - if 'ExternalGUID' in kwargs: - self.QBDict[self.classNameRq][self.__class__.__name__]["ExternalGUID"]=kwargs['ExternalGUID'] - - # if 'LinkToTxnID' in kwargs: - # self.QBDict[self.classNameRq][self.__class__.__name__]["LinkToTxnID"]=makeAList(kwargs['LinkToTxnID']) - - # if 'SetCredit_CreditTxnID' in kwargs and 'SetCredit_AppliedAmount' in kwargs: - # self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]={'CreditTxnID':{'@useMacro':"MACROTYPE", '#text':kwargs['SetCredit_CreditTxnID']}, 'AppliedAmount': kwargs['SetCredit_AppliedAmount']} - # if 'SetCredit_Override' in kwargs: - # self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]["Override"]=kwargs['SetCredit_Override'] + if 'ShipAddress_Addr1' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr1': kwargs['ShipAddress_Addr1']} + if 'ShipAddress_Addr2' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr2': kwargs['ShipAddress_Addr2']} + if 'ShipAddress_Addr3' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr3': kwargs['ShipAddress_Addr3']} + if 'ShipAddress_Addr4' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr4': kwargs['ShipAddress_Addr4']} + if 'ShipAddress_Addr5' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Addr5': kwargs['ShipAddress_Addr5']} + if 'ShipAddress_City' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'City': kwargs['ShipAddress_City']} + if 'ShipAddress_State' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'State': kwargs['ShipAddress_State']} + if 'ShipAddress_PostalCode' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'PostalCode': kwargs['ShipAddress_PostalCode']} + if 'ShipAddress_Country' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Country': kwargs['ShipAddress_Country']} + if 'ShipAddress_Note' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipAddress"]={'Note': kwargs['ShipAddress_Note']} + + if 'IsPending' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsPending"]=kwargs['IsPending'] + if 'IsFinanceCharge' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsFinanceCharge"]=kwargs['IsFinanceCharge'] + if 'PONumber' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["PONumber"]=kwargs['PONumber'] + if 'TermsRef_ListID' in kwargs: + if 'TermsRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]['ListID']= kwargs['TermsRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'ListID': kwargs['TermsRef_ListID']} + if 'TermsRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["TermsRef"]={'FullName': kwargs['TermsRef_FullName']} + + if 'DueDate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["DueDate"]=kwargs['DueDate'] + if 'SalesRepRef_ListID' in kwargs: + if 'SalesRepRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]['ListID']= kwargs['SalesRepRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'ListID': kwargs['SalesRepRef_ListID']} + if 'SalesRepRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["SalesRepRef"]={'FullName': kwargs['SalesRepRef_FullName']} + + if 'FOB' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["FOB"]=kwargs['FOB'] + if 'ShipDate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipDate"]=kwargs['ShipDate'] + if 'ShipMethodRef_ListID' in kwargs: + if 'ShipMethodRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]['ListID']= kwargs['ShipMethodRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'ListID': kwargs['ShipMethodRef_ListID']} + if 'ShipMethodRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ShipMethodRef"]={'FullName': kwargs['ShipMethodRef_FullName']} + + if 'ItemSalesTaxRef_ListID' in kwargs: + if 'ItemSalesTaxRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]['ListID']= kwargs['ItemSalesTaxRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'ListID': kwargs['ItemSalesTaxRef_ListID']} + if 'ItemSalesTaxRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ItemSalesTaxRef"]={'FullName': kwargs['ItemSalesTaxRef_FullName']} + + if 'IsManuallyClosed' in kwargs: #only SalesOrderAdd. not in InvoiceAdd + self.QBDict[self.classNameRq][self.__class__.__name__]["IsManuallyClosed"]=kwargs['IsManuallyClosed'] + if 'Memo' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["Memo"]=kwargs['Memo'] + if 'CustomerMsgRef_ListID' in kwargs: + if 'CustomerMsgRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]['ListID']= kwargs['CustomerMsgRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'ListID': kwargs['CustomerMsgRef_ListID']} + if 'CustomerMsgRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerMsgRef"]={'FullName': kwargs['CustomerMsgRef_FullName']} + + if 'IsToBePrinted' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBePrinted"]=kwargs['IsToBePrinted'] + if 'IsToBeEmailed' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsToBeEmailed"]=kwargs['IsToBeEmailed'] + if 'IsTaxIncluded' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["IsTaxIncluded"]=kwargs['IsTaxIncluded'] + if 'CustomerSalesTaxCodeRef_ListID' in kwargs: + if 'CustomerSalesTaxCodeRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]['ListID']= kwargs['CustomerSalesTaxCodeRef_ListID'] + else: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'ListID': kwargs['CustomerSalesTaxCodeRef_ListID']} + if 'CustomerSalesTaxCodeRef_FullName' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["CustomerSalesTaxCodeRef"]={'FullName': kwargs['CustomerSalesTaxCodeRef_FullName']} + + if 'Other' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["Other"]=kwargs['Other'] + if 'ExchangeRate' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ExchangeRate"]=kwargs['ExchangeRate'] + if 'ExternalGUID' in kwargs: + self.QBDict[self.classNameRq][self.__class__.__name__]["ExternalGUID"]=kwargs['ExternalGUID'] + + # if 'LinkToTxnID' in kwargs: + # self.QBDict[self.classNameRq][self.__class__.__name__]["LinkToTxnID"]=makeAList(kwargs['LinkToTxnID']) + + # if 'SetCredit_CreditTxnID' in kwargs and 'SetCredit_AppliedAmount' in kwargs: + # self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]={'CreditTxnID':{'@useMacro':"MACROTYPE", '#text':kwargs['SetCredit_CreditTxnID']}, 'AppliedAmount': kwargs['SetCredit_AppliedAmount']} + # if 'SetCredit_Override' in kwargs: + # self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]["Override"]=kwargs['SetCredit_Override'] - #add InvoiceLineAdd kwargs here - - self.SalesOrderLineAdd = [] - if 'SalesOrderLineAdd' in kwargs: - LineAdd = kwargs.get('SalesOrderLineAdd') - self.isLineAddOk = True - if isinstance(LineAdd, dict ): - LineAdd = [LineAdd] - elif isinstance(LineAdd, list): - pass - else: - self.isLineAddOk = False +#add InvoiceLineAdd kwargs here - if self.isLineAddOk: #check if each instance in the list are all dictionary. - for eachLineAdd in LineAdd: - if not isinstance(eachLineAdd, dict): - self.isLineAddOk = False - break - else: - print("SalesOrderLineAdd Not OK. has to be lisst of dict or a dict") - - - if self.isLineAddOk: #if everything good - for eachLineAdd in LineAdd: - self.LineAddDict = {} - if 'ItemRef_ListID' in eachLineAdd: - if 'ItemRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.LineAddDict["ItemRef"]['ListID']= eachLineAdd['ItemRef_ListID'] - else: - self.LineAddDict["ItemRef"]={'ListID': eachLineAdd['ItemRef_ListID']} - if 'ItemRef_FullName' in eachLineAdd: - self.LineAddDict["ItemRef"]={'FullName': eachLineAdd['ItemRef_FullName']} - if 'Desc' in eachLineAdd: - self.LineAddDict["Desc"]=eachLineAdd['Desc'] - if 'Quantity' in eachLineAdd: - self.LineAddDict["Quantity"]=eachLineAdd['Quantity'] - if 'UnitOfMeasure' in eachLineAdd: - self.LineAddDict["UnitOfMeasure"]=eachLineAdd['UnitOfMeasure'] - if 'Rate' in eachLineAdd: - self.LineAddDict["Rate"]=eachLineAdd['Rate'] - elif 'RatePercent' in eachLineAdd: - self.LineAddDict["RatePercent"]=eachLineAdd['RatePercent'] - elif 'PriceLevelRef_ListID' in eachLineAdd: - if 'PriceLevelRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: - self.LineAddDict["PriceLevelRef"]['ListID']= eachLineAdd['PriceLevelRef_ListID'] - else: - self.LineAddDict["PriceLevelRef"]={'ListID': eachLineAdd['PriceLevelRef_ListID']} - elif 'PriceLevelRef_FullName' in eachLineAdd: - self.LineAddDict["PriceLevelRef"]={'FullName': eachLineAdd['PriceLevelRef_FullName']} - - if 'Amount ' in eachLineAdd: - self.LineAddDict["Amount "]=eachLineAdd['Amount '] - # Others - if 'Other1' in eachLineAdd: - self.LineAddDict["Other1"]=eachLineAdd['Other1'] - if len(self.LineAddDict)>0: - self.SalesOrderLineAdd.append(self.LineAddDict) - - #skip the rest, not too important - else: - print("SalesOrderLineAdd has to be list of dict or a dict") - print(f'{self.SalesOrderLineAdd = }') - if len(self.SalesOrderLineAdd)>0: - self.QBDict[self.classNameRq][self.__class__.__name__]['SalesOrderLineAdd']=self.SalesOrderLineAdd - if 'IncludeRetElement' in kwargs: - self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement'] + self.SalesOrderLineAdd = [] + if 'SalesOrderLineAdd' in kwargs: + LineAdd = kwargs.get('SalesOrderLineAdd') + self.isLineAddOk = True + if isinstance(LineAdd, dict ): + LineAdd = [LineAdd] + elif isinstance(LineAdd, list): + pass + else: + self.isLineAddOk = False - # print(self.classNameRq) - print(f'{self.QBDict = }') + if self.isLineAddOk: #check if each instance in the list are all dictionary. + for eachLineAdd in LineAdd: + if not isinstance(eachLineAdd, dict): + self.isLineAddOk = False + break + else: + print("SalesOrderLineAdd Not OK. has to be lisst of dict or a dict") + + + if self.isLineAddOk: #if everything good + for eachLineAdd in LineAdd: + self.LineAddDict = {} + if 'ItemRef_ListID' in eachLineAdd: + if 'ItemRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.LineAddDict["ItemRef"]['ListID']= eachLineAdd['ItemRef_ListID'] + else: + self.LineAddDict["ItemRef"]={'ListID': eachLineAdd['ItemRef_ListID']} + if 'ItemRef_FullName' in eachLineAdd: + self.LineAddDict["ItemRef"]={'FullName': eachLineAdd['ItemRef_FullName']} + if 'Desc' in eachLineAdd: + self.LineAddDict["Desc"]=eachLineAdd['Desc'] + if 'Quantity' in eachLineAdd: + self.LineAddDict["Quantity"]=eachLineAdd['Quantity'] + if 'UnitOfMeasure' in eachLineAdd: + self.LineAddDict["UnitOfMeasure"]=eachLineAdd['UnitOfMeasure'] + if 'Rate' in eachLineAdd: + self.LineAddDict["Rate"]=eachLineAdd['Rate'] + elif 'RatePercent' in eachLineAdd: + self.LineAddDict["RatePercent"]=eachLineAdd['RatePercent'] + elif 'PriceLevelRef_ListID' in eachLineAdd: + if 'PriceLevelRef' in self.QBDict[self.classNameRq][self.__class__.__name__]: + self.LineAddDict["PriceLevelRef"]['ListID']= eachLineAdd['PriceLevelRef_ListID'] + else: + self.LineAddDict["PriceLevelRef"]={'ListID': eachLineAdd['PriceLevelRef_ListID']} + elif 'PriceLevelRef_FullName' in eachLineAdd: + self.LineAddDict["PriceLevelRef"]={'FullName': eachLineAdd['PriceLevelRef_FullName']} + + if 'Amount ' in eachLineAdd: + self.LineAddDict["Amount "]=eachLineAdd['Amount '] + # Others + if 'Other1' in eachLineAdd: + self.LineAddDict["Other1"]=eachLineAdd['Other1'] + if len(self.LineAddDict)>0: + self.SalesOrderLineAdd.append(self.LineAddDict) + + #skip the rest, not too important + else: + print("SalesOrderLineAdd has to be list of dict or a dict") + print(f'{self.SalesOrderLineAdd = }') + if len(self.SalesOrderLineAdd)>0: + self.QBDict[self.classNameRq][self.__class__.__name__]['SalesOrderLineAdd']=self.SalesOrderLineAdd + if 'IncludeRetElement' in kwargs: + self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement'] + + # print(self.classNameRq) + print(f'{self.QBDict = }') 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", - "SalesRepRef", "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" - self.className = 'SalesOrderQuery' #Hardcoded because for check if self.__class__.__name__==self.className - self.classNameRq:str = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] + def __init__(self, *args, **kwargs): + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] + else: + self.class_debug=False + if self.class_debug: + 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", + "SalesRepRef", "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" + self.className = 'SalesOrderQuery' #Hardcoded because for check if self.__class__.__name__==self.className + self.classNameRq:str = self.__class__.__name__ + 'Rq' - self.QBDict[self.classNameRq]={} - ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) - # self.ENUM_DateMacro = ['All', 'Today', 'ThisWeek', 'ThisWeekToDate', 'ThisMonth', 'ThisMonthToDate', 'ThisCalendarQuarter', 'ThisCalendarQuarterToDate', 'ThisFiscalQuarter', - # 'ThisFiscalQuarterToDate', 'ThisCalendarYear', 'ThisCalendarYearToDate', 'ThisFiscalYear', 'ThisFiscalYearToDate', 'Yesterday', 'LastWeek', 'LastWeekToDate', 'LastMonth', - # 'LastMonthToDate', 'LastCalendarQuarter', 'LastCalendarQuarterToDate', 'LastFiscalQuarter', 'LastFiscalQuarterToDate', 'LastCalendarYear', 'LastCalendarYearToDate', - # 'LastFiscalYear', 'LastFiscalYearToDate', 'NextWeek', 'NextFourWeeks', 'NextMonth', 'NextCalendarQuarter', 'NextCalendarYear', 'NextFiscalQuarter', 'NextFiscalYear' - # ] - self.ENUM_MatchCriterion = ['StartsWith', 'Contains', 'EndsWith'] - if 'TxnID' in kwargs and kwargs['TxnID'] and len(kwargs['TxnID'])>0: - self.QBDict[self.classNameRq]["TxnID"]=makeAList(kwargs['TxnID']) - elif 'RefNumber' in kwargs and kwargs['RefNumber']: - self.QBDict[self.classNameRq]["RefNumber"]=makeAList(kwargs['RefNumber']) - elif 'RefNumberCaseSensitive' in kwargs and kwargs['RefNumberCaseSensitive']: - self.QBDict[self.classNameRq]["RefNumberCaseSensitive"]=makeAList(kwargs['RefNumberCaseSensitive']) - else: - if 'MaxReturned' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["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.classNameRq]["TxnDateRangeFilter"]={'FromTxnDate':kwargs.get('TxnDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TxnDateRangeFilter_ToTxnDate', "")} - elif 'TxnDateRangeFilter_DateMacro' in kwargs: - DM=cleanIncludeRetElements(ENUM_DateMacro, kwargs['TxnDateRangeFilter_DateMacro']) - if len(DM)>0: - self.QBDict[self.classNameRq]["TxnDateRangeFilter"]={'DateMacro':DM} + self.QBDict[self.classNameRq]={} + ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) + # self.ENUM_DateMacro = ['All', 'Today', 'ThisWeek', 'ThisWeekToDate', 'ThisMonth', 'ThisMonthToDate', 'ThisCalendarQuarter', 'ThisCalendarQuarterToDate', 'ThisFiscalQuarter', + # 'ThisFiscalQuarterToDate', 'ThisCalendarYear', 'ThisCalendarYearToDate', 'ThisFiscalYear', 'ThisFiscalYearToDate', 'Yesterday', 'LastWeek', 'LastWeekToDate', 'LastMonth', + # 'LastMonthToDate', 'LastCalendarQuarter', 'LastCalendarQuarterToDate', 'LastFiscalQuarter', 'LastFiscalQuarterToDate', 'LastCalendarYear', 'LastCalendarYearToDate', + # 'LastFiscalYear', 'LastFiscalYearToDate', 'NextWeek', 'NextFourWeeks', 'NextMonth', 'NextCalendarQuarter', 'NextCalendarYear', 'NextFiscalQuarter', 'NextFiscalYear' + # ] + self.ENUM_MatchCriterion = ['StartsWith', 'Contains', 'EndsWith'] - if 'EntityFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["EntityFilter"]={'ListID':makeAList(kwargs['EntityFilter_ListID'])} - elif 'EntityFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["EntityFilter"]={'FullName':makeAList(kwargs['EntityFilter_FullName'])} - elif 'EntityFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["EntityFilter"]={'ListIDWithChildren':kwargs['EntityFilter_ListIDWithChildren']} - elif 'EntityFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["EntityFilter"]={'FullNameWithChildren':kwargs['EntityFilter_FullNameWithChildren']} + if 'TxnID' in kwargs and kwargs['TxnID'] and len(kwargs['TxnID'])>0: + self.QBDict[self.classNameRq]["TxnID"]=makeAList(kwargs['TxnID']) + elif 'RefNumber' in kwargs and kwargs['RefNumber']: + self.QBDict[self.classNameRq]["RefNumber"]=makeAList(kwargs['RefNumber']) + elif 'RefNumberCaseSensitive' in kwargs and kwargs['RefNumberCaseSensitive']: + self.QBDict[self.classNameRq]["RefNumberCaseSensitive"]=makeAList(kwargs['RefNumberCaseSensitive']) + else: + if 'MaxReturned' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["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.classNameRq]["TxnDateRangeFilter"]={'FromTxnDate':kwargs.get('TxnDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TxnDateRangeFilter_ToTxnDate', "")} + elif 'TxnDateRangeFilter_DateMacro' in kwargs: + DM=cleanIncludeRetElements(ENUM_DateMacro, kwargs['TxnDateRangeFilter_DateMacro']) + if len(DM)>0: + self.QBDict[self.classNameRq]["TxnDateRangeFilter"]={'DateMacro':DM} - if 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs: - RNFMC = cleanIncludeRetElements(self.ENUM_MatchCriterion, kwargs['RefNumberFilter_MatchCriterion']) - if len(RNFMC)>0: - self.QBDict[self.classNameRq]["RefNumberFilter"]={'MatchCriterion':RNFMC, '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.classNameRq]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberRangeFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberRangeFilter_ToRefNumber', "")} + if 'EntityFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["EntityFilter"]={'ListID':makeAList(kwargs['EntityFilter_ListID'])} + elif 'EntityFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["EntityFilter"]={'FullName':makeAList(kwargs['EntityFilter_FullName'])} + elif 'EntityFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["EntityFilter"]={'ListIDWithChildren':kwargs['EntityFilter_ListIDWithChildren']} + elif 'EntityFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["EntityFilter"]={'FullNameWithChildren':kwargs['EntityFilter_FullNameWithChildren']} - if 'CurrencyFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_ListID']) - elif 'CurrencyFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_FullName']) + if 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs: + RNFMC = cleanIncludeRetElements(self.ENUM_MatchCriterion, kwargs['RefNumberFilter_MatchCriterion']) + if len(RNFMC)>0: + self.QBDict[self.classNameRq]["RefNumberFilter"]={'MatchCriterion':RNFMC, '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.classNameRq]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberRangeFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberRangeFilter_ToRefNumber', "")} - if 'IncludeLineItems' in kwargs: - self.QBDict[self.classNameRq]["IncludeLineItems"]=kwargs['IncludeLineItems'] - if 'IncludeLinkedTxns' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE + if 'CurrencyFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_ListID']) + elif 'CurrencyFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_FullName']) - if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data) - self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] + if 'IncludeLineItems' in kwargs: + self.QBDict[self.classNameRq]["IncludeLineItems"]=kwargs['IncludeLineItems'] + if 'IncludeLinkedTxns' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE - # print(self.classNameRq) - print(self.QBDict) - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data) + self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] + + # print(self.classNameRq) + if self.class_debug: + print(self.QBDict) + if self.__class__.__name__==self.className: + self.runCheck() ### running the qbxml connection to get data ### class InvoiceQuery(baseQBQuery): - def __init__(self, *args, **kwargs): + 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", "ARAccountRef", "TemplateRef", - "TxnDate", "RefNumber", "BillAddress", "BillAddressBlock", "ShipAddress", "ShipAddressBlock", "IsPending", "IsFinanceCharge", "PONumber,", "TermsRef", "DueDate", - "SalesRepRef", "FOB", "ShipDate", "ShipMethodRef", "SubTotal", "ItemSalesTaxRef", "SalesTaxPercentage", "SalesTaxTotal", "AppliedAmount", "BalanceRemaining", - "CurrencyRef", "ExchangeRate", "BalanceRemainingInHomeCurrency", "Memo", "IsPaid", "CustomerMsgRef", "IsToBePrinted", - "IsToBeEmailed", "IsTaxIncluded", "CustomerSalesTaxCodeRef", "SuggestedDiscountAmount", "SuggestedDiscountDate", "Other", "ExternalGUID", - "LinkedTxn", "InvoiceLineRet", "InvoiceLineGroupRet", - ] - self.onError = "stopOnError" - self.retName = 'InvoiceRet' - self.defaultFilterKey = "TxnID" - self.className = 'InvoiceQuery' - self.classNameRq:str = self.__class__.__name__ + 'Rq' - if 'debug' in kwargs and isinstance(kwargs['debug'], bool): - self.class_debug=kwargs["debug"] + print(f'{args = }') + print(f'{kwargs = }') + super().__init__(*args, **kwargs) + ### Required Variable + self.includeRetElements_allowed = ["TxnID", "TimeCreated", "TimeModified", "EditSequence", "TxnNumber", "CustomerRef", "ClassRef", "ARAccountRef", "TemplateRef", + "TxnDate", "RefNumber", "BillAddress", "BillAddressBlock", "ShipAddress", "ShipAddressBlock", "IsPending", "IsFinanceCharge", "PONumber,", "TermsRef", "DueDate", + "SalesRepRef", "FOB", "ShipDate", "ShipMethodRef", "SubTotal", "ItemSalesTaxRef", "SalesTaxPercentage", "SalesTaxTotal", "AppliedAmount", "BalanceRemaining", + "CurrencyRef", "ExchangeRate", "BalanceRemainingInHomeCurrency", "Memo", "IsPaid", "CustomerMsgRef", "IsToBePrinted", + "IsToBeEmailed", "IsTaxIncluded", "CustomerSalesTaxCodeRef", "SuggestedDiscountAmount", "SuggestedDiscountDate", "Other", "ExternalGUID", + "LinkedTxn", "InvoiceLineRet", "InvoiceLineGroupRet", + ] + self.onError = "stopOnError" + self.retName = 'InvoiceRet' + self.defaultFilterKey = "TxnID" + self.className = 'InvoiceQuery' + self.classNameRq:str = self.__class__.__name__ + 'Rq' + if 'debug' in kwargs and isinstance(kwargs['debug'], bool): + self.class_debug=kwargs["debug"] - self.QBDict[self.classNameRq]={} - ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) - # self.ENUM_DateMacro = ['All', 'Today', 'ThisWeek', 'ThisWeekToDate', 'ThisMonth', 'ThisMonthToDate', 'ThisCalendarQuarter', 'ThisCalendarQuarterToDate', 'ThisFiscalQuarter', - # 'ThisFiscalQuarterToDate', 'ThisCalendarYear', 'ThisCalendarYearToDate', 'ThisFiscalYear', 'ThisFiscalYearToDate', 'Yesterday', 'LastWeek', 'LastWeekToDate', 'LastMonth', - # 'LastMonthToDate', 'LastCalendarQuarter', 'LastCalendarQuarterToDate', 'LastFiscalQuarter', 'LastFiscalQuarterToDate', 'LastCalendarYear', 'LastCalendarYearToDate', - # 'LastFiscalYear', 'LastFiscalYearToDate', 'NextWeek', 'NextFourWeeks', 'NextMonth', 'NextCalendarQuarter', 'NextCalendarYear', 'NextFiscalQuarter', 'NextFiscalYear' - # ] ## disabled, and move to outside class, on top of page - self.ENUM_MatchCriterion = ['StartsWith', 'Contains', 'EndsWith'] + self.QBDict[self.classNameRq]={} + ### End Required Variable. can put ENUM list below this (eg: self.ENUM_GeneralSummaryReportQuery=[]) + # self.ENUM_DateMacro = ['All', 'Today', 'ThisWeek', 'ThisWeekToDate', 'ThisMonth', 'ThisMonthToDate', 'ThisCalendarQuarter', 'ThisCalendarQuarterToDate', 'ThisFiscalQuarter', + # 'ThisFiscalQuarterToDate', 'ThisCalendarYear', 'ThisCalendarYearToDate', 'ThisFiscalYear', 'ThisFiscalYearToDate', 'Yesterday', 'LastWeek', 'LastWeekToDate', 'LastMonth', + # 'LastMonthToDate', 'LastCalendarQuarter', 'LastCalendarQuarterToDate', 'LastFiscalQuarter', 'LastFiscalQuarterToDate', 'LastCalendarYear', 'LastCalendarYearToDate', + # 'LastFiscalYear', 'LastFiscalYearToDate', 'NextWeek', 'NextFourWeeks', 'NextMonth', 'NextCalendarQuarter', 'NextCalendarYear', 'NextFiscalQuarter', 'NextFiscalYear' + # ] ## disabled, and move to outside class, on top of page + self.ENUM_MatchCriterion = ['StartsWith', 'Contains', 'EndsWith'] - if 'TxnID' in kwargs and kwargs['TxnID'] and len(kwargs['TxnID'])>0: - _txnIDs=makeAList(kwargs['TxnID']) - self.QBDict[self.classNameRq]["TxnID"]= makeAList(kwargs['TxnID']) - elif 'RefNumber' in kwargs and kwargs['RefNumber']: - self.QBDict[self.classNameRq]['RefNumber']=makeAList(kwargs['RefNumber']) - elif 'RefNumberCaseSensitive' in kwargs and kwargs['RefNumberCaseSensitive']: - self.QBDict[self.classNameRq]["RefNumberCaseSensitive"]=makeAList(kwargs['RefNumberCaseSensitive']) - else: - if 'MaxReturned' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["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.classNameRq]["TxnDateRangeFilter"]={'FromTxnDate':kwargs.get('TxnDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TxnDateRangeFilter_ToTxnDate', "")} - elif 'TxnDateRangeFilter_DateMacro' in kwargs: - DM=cleanIncludeRetElements(ENUM_DateMacro, kwargs['TxnDateRangeFilter_DateMacro']) - if len(DM)>0: - self.QBDict[self.classNameRq]["TxnDateRangeFilter"]={'DateMacro':DM} + if 'TxnID' in kwargs and kwargs['TxnID'] and len(kwargs['TxnID'])>0: + _txnIDs=makeAList(kwargs['TxnID']) + self.QBDict[self.classNameRq]["TxnID"]= makeAList(kwargs['TxnID']) + elif 'RefNumber' in kwargs and kwargs['RefNumber']: + self.QBDict[self.classNameRq]['RefNumber']=makeAList(kwargs['RefNumber']) + elif 'RefNumberCaseSensitive' in kwargs and kwargs['RefNumberCaseSensitive']: + self.QBDict[self.classNameRq]["RefNumberCaseSensitive"]=makeAList(kwargs['RefNumberCaseSensitive']) + else: + if 'MaxReturned' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["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.classNameRq]["TxnDateRangeFilter"]={'FromTxnDate':kwargs.get('TxnDateRangeFilter_FromTxnDate', ""), 'ToTxnDate':kwargs.get('TxnDateRangeFilter_ToTxnDate', "")} + elif 'TxnDateRangeFilter_DateMacro' in kwargs: + DM=cleanIncludeRetElements(ENUM_DateMacro, kwargs['TxnDateRangeFilter_DateMacro']) + if len(DM)>0: + self.QBDict[self.classNameRq]["TxnDateRangeFilter"]={'DateMacro':DM} - if 'EntityFilter_ListID' in kwargs: - # self.QBDict[self.classNameRq]["EntityFilter"]={'ListID':kwargs['EntityFilter_ListID']} - self.QBDict[self.classNameRq]['EntityFilter']={'ListID':makeAList(kwargs['EntityFilter_ListID'])} - elif 'EntityFilter_FullName' in kwargs: - # self.QBDict[self.classNameRq]["EntityFilter"]={'FullName':kwargs['EntityFilter_FullName']} - self.QBDict[self.classNameRq]['EntityFilter']={'FullName':makeAList(kwargs['EntityFilter_FullName'])} - elif 'EntityFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["EntityFilter"]={'ListIDWithChildren':kwargs['EntityFilter_ListIDWithChildren']} - elif 'EntityFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["EntityFilter"]={'FullNameWithChildren':kwargs['EntityFilter_FullNameWithChildren']} + if 'EntityFilter_ListID' in kwargs: + # self.QBDict[self.classNameRq]["EntityFilter"]={'ListID':kwargs['EntityFilter_ListID']} + self.QBDict[self.classNameRq]['EntityFilter']={'ListID':makeAList(kwargs['EntityFilter_ListID'])} + elif 'EntityFilter_FullName' in kwargs: + # self.QBDict[self.classNameRq]["EntityFilter"]={'FullName':kwargs['EntityFilter_FullName']} + self.QBDict[self.classNameRq]['EntityFilter']={'FullName':makeAList(kwargs['EntityFilter_FullName'])} + elif 'EntityFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["EntityFilter"]={'ListIDWithChildren':kwargs['EntityFilter_ListIDWithChildren']} + elif 'EntityFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["EntityFilter"]={'FullNameWithChildren':kwargs['EntityFilter_FullNameWithChildren']} - if 'AccountFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["AccountFilter"]={'ListID':makeAList(kwargs['AccountFilter_ListID'])} - elif 'AccountFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["AccountFilter"]={'FullName':makeAList(kwargs['AccountFilter_FullName'])} - elif 'AccountFilter_ListIDWithChildren' in kwargs: - self.QBDict[self.classNameRq]["AccountFilter"]={'ListIDWithChildren':kwargs['AccountFilter_ListIDWithChildren']} - elif 'AccountFilter_FullNameWithChildren' in kwargs: - self.QBDict[self.classNameRq]["AccountFilter"]={'FullNameWithChildren':kwargs['AccountFilter_FullNameWithChildren']} + if 'AccountFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["AccountFilter"]={'ListID':makeAList(kwargs['AccountFilter_ListID'])} + elif 'AccountFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["AccountFilter"]={'FullName':makeAList(kwargs['AccountFilter_FullName'])} + elif 'AccountFilter_ListIDWithChildren' in kwargs: + self.QBDict[self.classNameRq]["AccountFilter"]={'ListIDWithChildren':kwargs['AccountFilter_ListIDWithChildren']} + elif 'AccountFilter_FullNameWithChildren' in kwargs: + self.QBDict[self.classNameRq]["AccountFilter"]={'FullNameWithChildren':kwargs['AccountFilter_FullNameWithChildren']} - if 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs: - RNFMC = cleanIncludeRetElements(self.ENUM_MatchCriterion, kwargs['RefNumberFilter_MatchCriterion']) - if len(RNFMC)>0: - self.QBDict[self.classNameRq]["RefNumberFilter"]={'MatchCriterion':RNFMC, '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', "")} - ##### CAREFULL with the get() coz "" will get anything - self.QBDict[self.classNameRq]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberRangeFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberRangeFilter_ToRefNumber', "")} + if 'RefNumberFilter_MatchCriterion' in kwargs and 'RefNumberFilter_RefNumber' in kwargs: + RNFMC = cleanIncludeRetElements(self.ENUM_MatchCriterion, kwargs['RefNumberFilter_MatchCriterion']) + if len(RNFMC)>0: + self.QBDict[self.classNameRq]["RefNumberFilter"]={'MatchCriterion':RNFMC, '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', "")} + ##### CAREFULL with the get() coz "" will get anything + self.QBDict[self.classNameRq]["RefNumberRangeFilter"]={'FromRefNumber':kwargs.get('RefNumberRangeFilter_FromRefNumber', ""), 'ToRefNumber':kwargs.get('RefNumberRangeFilter_ToRefNumber', "")} - if 'CurrencyFilter_ListID' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_ListID']) - elif 'CurrencyFilter_FullName' in kwargs: - self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_FullName']) + if 'CurrencyFilter_ListID' in kwargs: + self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_ListID']) + elif 'CurrencyFilter_FullName' in kwargs: + self.QBDict[self.classNameRq]["CurrencyFilter"]=makeAList(kwargs['CurrencyFilter_FullName']) - if 'IncludeLineItems' in kwargs: - print(f'{self.QBDict} = ') - self.QBDict[self.classNameRq]["IncludeLineItems"]=kwargs['IncludeLineItems'] - if 'IncludeLinkedTxns' in kwargs: - self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE + if 'IncludeLineItems' in kwargs: + print(f'{self.QBDict} = ') + self.QBDict[self.classNameRq]["IncludeLineItems"]=kwargs['IncludeLineItems'] + if 'IncludeLinkedTxns' in kwargs: + self.QBDict[self.classNameRq]["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.classNameRq]["IncludeRetElement"]=IRE - if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data) - self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] - # print(self.classNameRq) - # print(self.QBDict) - if self.__class__.__name__==self.className: - self.runCheck() ### running the qbxml connection to get data ### + if 'OwnerID' in kwargs: # usually value=0 to get to DataExtRet (additional data) + self.QBDict[self.classNameRq]["OwnerID"]=kwargs['OwnerID'] + # print(self.classNameRq) + # print(self.QBDict) + if self.__class__.__name__==self.className: + self.runCheck() ### running the qbxml connection to get data ### @timing def InventoryStockStatusByVendor(ReportEntityFilter_FullName:str='TACO') -> dict: - # g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear") - g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="InventoryStockStatusByVendor", ReportEntityFilter_FullName=ReportEntityFilter_FullName, ) - # g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="InventoryStockStatusByVendor", ReportItemFilter_FullName=['TACH:RLC:BBS009PO45-500','TACH:RLC:BBS009PO45-400'], ReportEntityFilter_FullName='TACO' ) - # print(g, type(g)) - # print(type(g.all())) - # print(g.all()) - # print(g.response_string) - # print(g.all()) - # pprint.pprint(g.filter("reportdata").all()) - # abc = g.filter("reportdata").all() - # print(abc) - # print() - # pprint.pprint(g.filter('datarow').all(abc), sort_dicts=False) - datarows = g.filter('datarow').all() - # pprint.pprint(datarows, sort_dicts=False) - # print(type(datarows)) - dt = {} - if len(datarows[0]['DataRow'])==0: - return dt - for datarow in datarows[0]['DataRow']: - # print(datarow,) - FullName=datarow['RowData']['@value'] - if len(FullName.split(':'))==3: - ShortName=datarow['ColData'][0]['@value'] - QOH, QOSO, QA, UOM, QOPO, min, max, ND = None, None, None, None, None, None, None, None - for coldata in datarow['ColData']: - if coldata['@colID']=='5': - QOH=coldata['@value'] - elif coldata['@colID']=='6': - QOSO=coldata['@value'] - elif coldata['@colID']=='8': - QA=coldata['@value'] - elif coldata['@colID']=='9': - UOM=coldata['@value'] - elif coldata['@colID']=='11': - QOPO=coldata['@value'] - elif coldata['@colID']=='3': - min=coldata['@value'] - elif coldata['@colID']=='4': - max=coldata['@value'] - elif coldata['@colID']=='13': - ND=coldata['@value'] #Next Delivery Date - dt[FullName]={'ShortName':ShortName, 'QOH':QOH, 'QOSO':QOSO, 'QA':QA, 'QOPO':QOPO, 'UOM':UOM, 'min':min, 'max':max, 'ND':ND} - # print(f'{dt = }') - print(f'InventoryStockStatusByVendor {len(dt) = }') - return dt - """ - {'@rowNumber': '1016', - 'ColData': [{'@colID': '1', - '@value': 'EDG-P1251-1/42'}, - {'@colID': '2', - '@value': 'EDGING 42 X 1 MM P1251'}, - {'@colID': '5', '@value': '1'}, # QOH - {'@colID': '6', '@value': '0'}, # QOSO - {'@colID': '7', '@value': '0'}, #assembly - {'@colID': '8', '@value': '1'}, # QA(available)(QOH-QOSO-assembly) - {'@colID': '9', '@value': 'Roll'}, #base_uom - {'@colID': '10', '@value': 'false'}, - {'@colID': '11', '@value': '0'}, #QOPO - {'@colID': '12', '@value': '0'}, #ReorderqTY - {'@colID': '13', '@value': '13/04/2022'}, #NextDeliver - {'@colID': '14', '@value': '0'}], - 'RowData': {'@rowType': 'item', - '@value': 'TEDG:P142:EDG-P1251-1/42'}}, - """ + # g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear") + g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="InventoryStockStatusByVendor", ReportEntityFilter_FullName=ReportEntityFilter_FullName, ) + # g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="InventoryStockStatusByVendor", ReportItemFilter_FullName=['TACH:RLC:BBS009PO45-500','TACH:RLC:BBS009PO45-400'], ReportEntityFilter_FullName='TACO' ) + # print(g, type(g)) + # print(type(g.all())) + # print(g.all()) + # print(g.response_string) + # print(g.all()) + # pprint.pprint(g.filter("reportdata").all()) + # abc = g.filter("reportdata").all() + # print(abc) + # print() + # pprint.pprint(g.filter('datarow').all(abc), sort_dicts=False) + datarows = g.filter('datarow').all() + # pprint.pprint(datarows, sort_dicts=False) + # print(type(datarows)) + dt = {} + if len(datarows[0]['DataRow'])==0: + return dt + for datarow in datarows[0]['DataRow']: + # print(datarow,) + FullName=datarow['RowData']['@value'] + if len(FullName.split(':'))==3: + ShortName=datarow['ColData'][0]['@value'] + QOH, QOSO, QA, UOM, QOPO, min, max, ND = None, None, None, None, None, None, None, None + for coldata in datarow['ColData']: + if coldata['@colID']=='5': + QOH=coldata['@value'] + elif coldata['@colID']=='6': + QOSO=coldata['@value'] + elif coldata['@colID']=='8': + QA=coldata['@value'] + elif coldata['@colID']=='9': + UOM=coldata['@value'] + elif coldata['@colID']=='11': + QOPO=coldata['@value'] + elif coldata['@colID']=='3': + min=coldata['@value'] + elif coldata['@colID']=='4': + max=coldata['@value'] + elif coldata['@colID']=='13': + ND=coldata['@value'] #Next Delivery Date + dt[FullName]={'ShortName':ShortName, 'QOH':QOH, 'QOSO':QOSO, 'QA':QA, 'QOPO':QOPO, 'UOM':UOM, 'min':min, 'max':max, 'ND':ND} + # print(f'{dt = }') + print(f'InventoryStockStatusByVendor {len(dt) = }') + return dt + """ + {'@rowNumber': '1016', + 'ColData': [{'@colID': '1', + '@value': 'EDG-P1251-1/42'}, + {'@colID': '2', + '@value': 'EDGING 42 X 1 MM P1251'}, + {'@colID': '5', '@value': '1'}, # QOH + {'@colID': '6', '@value': '0'}, # QOSO + {'@colID': '7', '@value': '0'}, #assembly + {'@colID': '8', '@value': '1'}, # QA(available)(QOH-QOSO-assembly) + {'@colID': '9', '@value': 'Roll'}, #base_uom + {'@colID': '10', '@value': 'false'}, + {'@colID': '11', '@value': '0'}, #QOPO + {'@colID': '12', '@value': '0'}, #ReorderqTY + {'@colID': '13', '@value': '13/04/2022'}, #NextDeliver + {'@colID': '14', '@value': '0'}], + 'RowData': {'@rowType': 'item', + '@value': 'TEDG:P142:EDG-P1251-1/42'}}, + """ if __name__ == "__main__": - @timing - def invoicequery(): - g=InvoiceQuery(debug=False, MaxReturned = 2, IncludeLineItems="true", IncludeLinkedTxns="true", - RefNumber="24010022")#"2023-08-22") - print(json.dumps(g.filter().all(), indent=3)) - print(g.count()) + @timing + def invoicequery(): + g=InvoiceQuery(debug=False, MaxReturned = 2, IncludeLineItems="true", IncludeLinkedTxns="true", + RefNumber="24010022")#"2023-08-22") + print(json.dumps(g.filter().all(), indent=3)) + print(g.count()) - @timing - def salesorderquery(): - g=SalesOrderQuery(debug=False, MaxReturned = 1, TxnID=None, IncludeLineItems="true", IncludeLinkedTxns="true", - )#RefNumber="24010022" )#"B23070857") - print(json.dumps(g.filter().all(), indent=3)) - print(g.count()) + @timing + def salesorderquery(): + g=SalesOrderQuery(debug=False, MaxReturned = 1, TxnID=None, IncludeLineItems="true", IncludeLinkedTxns="true", + )#RefNumber="24010022" )#"B23070857") + 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)) + @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(json.dumps(g.filter().all(), indent=3)) - print(g.count()) + 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 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") = }') + @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(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()) + # print(g.filter(["DataExtRet"]).all()) - @timing - def customerquery(): - g= CustomerQuery(MaxReturned=3, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock", "Notes", "AdditionalNotesRet", 'creditlimit']) - g= CustomerQuery(MaxReturned=2, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddress", "ShipToAddress","Phone", "Notes", "AdditionalNotesRet", 'creditlimit']) - # 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", "Notes"]).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() = }') + @timing + def customerquery(): + g= CustomerQuery(MaxReturned=3, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock", "Notes", "AdditionalNotesRet", 'creditlimit']) + g= CustomerQuery(MaxReturned=2, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddress", "ShipToAddress","Phone", "Notes", "AdditionalNotesRet", 'creditlimit']) + # 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", "Notes"]).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 + 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 - @timing - def pricelevel(): - g = PriceLevelQuery(FullName = 'B 202112', ItemRef_FullName = "TEDG:WG42:EDG-905/42") - g = PriceLevelQuery( NameFilter_MatchCriterion='Contains', NameFilter_Name='202112' ) - # print(g.filter('PriceLevelPerItemRet').all()) - print(g.all()) - print(len(g.filter('PriceLevelPerItemRet').all())) - for x in g.all(): - print([y for y in x]) - print(f"{x.get('Name')} : {len(x.get('PriceLevelPerItemRet'))}") + @timing + def pricelevel(): + g = PriceLevelQuery(FullName = 'B 202112', ItemRef_FullName = "TEDG:WG42:EDG-905/42") + g = PriceLevelQuery( NameFilter_MatchCriterion='Contains', NameFilter_Name='202112' ) + # print(g.filter('PriceLevelPerItemRet').all()) + print(g.all()) + print(len(g.filter('PriceLevelPerItemRet').all())) + for x in g.all(): + print([y for y in x]) + print(f"{x.get('Name')} : {len(x.get('PriceLevelPerItemRet'))}") - # pricelevel() - # invoicequery() - # salesorderquery() - # transactionquery() - # pprint.pprint(InventoryStockStatusByVendor(), sort_dicts=False) - # iteminventoryquery() - customerquery() - # readxmltodict() - # g=SalesOrderQuery(MaxReturned=1) - # print(len(None)) + # pricelevel() + # invoicequery() + # salesorderquery() + # transactionquery() + # pprint.pprint(InventoryStockStatusByVendor(), sort_dicts=False) + # iteminventoryquery() + customerquery() + # readxmltodict() + # g=SalesOrderQuery(MaxReturned=1) + # print(len(None)) diff --git a/QBClass/server.py b/QBClass/server.py index 92d7344..33f0247 100644 --- a/QBClass/server.py +++ b/QBClass/server.py @@ -8,508 +8,511 @@ from .utils import cleanIncludeRetElements import json 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 + # @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 class baseQBQuery: - def __init__(self, *args, **kwargs, ) -> None: - # print(f'{kwargs = }') - # print(f'{args = }') - self.QBXML = None - self.QBDict = {} - self.response_string = None - self.Rs = None - self.varDict = {} - ### start ### variable to be replace with other class init value - self.onError = "continueOnError" - # self.cleanIncludeRetElements = None - self.includeRetElements_allowed = None - self.retName = None - self.defaultFilterKey = None - self.class_debug = False - ### end ### variable to be replace with other class init value - self.listOfDict = self.ListOfDict(None, self.varDict, self.retName, False) - self.requestID = None - self.statusCode = -1 - self.statusMessage = "" - self.statusSeverity = "" - self.statusOk = False - if self.__class__.__name__=="baseQBQuery": - print("baseqbquey same with classname") - else: - print("accessed from child class") - print("basequery is accessed from ", self.__class__.__name__ + "Rq") + def __init__(self, *args, **kwargs, ) -> None: + # print(f'{kwargs = }') + # print(f'{args = }') + self.QBXML = None + self.QBDict = {} + self.response_string = None + self.Rs = None + self.varDict = {} + ### start ### variable to be replace with other class init value + self.onError = "continueOnError" + # self.cleanIncludeRetElements = None + self.includeRetElements_allowed = None + self.retName = None + self.defaultFilterKey = None + self.class_debug = False + ### end ### variable to be replace with other class init value + self.listOfDict = self.ListOfDict(None, self.varDict, self.retName, False) + self.requestID = None + self.statusCode = -1 + self.statusMessage = "" + self.statusSeverity = "" + self.statusOk = False + if self.class_debug: + if self.__class__.__name__=="baseQBQuery": + print("baseqbquey same with classname") + else: + print("accessed from child class") + + print("basequery is accessed from ", self.__class__.__name__ + "Rq") - # @timing - def create_QBXML(self): - version = "13.0" - dataDict = { ### Header for qmxml with version attribute - "?qbxml": { - "@version": version, - } - } - # dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Simple Example ### - # "@onError": "continueOnError", - # "GeneralSummaryReportQueryRq": { - # "GeneralSummaryReportType": self.GeneralSummaryReportType, - # } - # } - # } + # @timing + def create_QBXML(self): + version = "13.0" + dataDict = { ### Header for qmxml with version attribute + "?qbxml": { + "@version": version, + } + } + # dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Simple Example ### + # "@onError": "continueOnError", + # "GeneralSummaryReportQueryRq": { + # "GeneralSummaryReportType": self.GeneralSummaryReportType, + # } + # } + # } - # dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Example with multiple FullName Item ### - # "@onError": "continueOnError", - # "ItemInventoryQueryRq": { - # "FullName": ["TACO:AA:TH-003AA", - # "TACO:AA:TH-010AA"] - # }, - # } - # } - firstKey = str(list(self.QBDict.keys())[0]) - dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Example with multiple FullName Item ### - "@onError": self.onError, - firstKey: self.QBDict[firstKey]}} - # print(f'{dataDict = }') + # dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Example with multiple FullName Item ### + # "@onError": "continueOnError", + # "ItemInventoryQueryRq": { + # "FullName": ["TACO:AA:TH-003AA", + # "TACO:AA:TH-010AA"] + # }, + # } + # } + firstKey = str(list(self.QBDict.keys())[0]) + dataDict["?qbxml"]["QBXML"] = {"QBXMLMsgsRq": { ### Example with multiple FullName Item ### + "@onError": self.onError, + firstKey: self.QBDict[firstKey]}} + # print(f'{dataDict = }') # # QBXML = '' + xmltodict.unparse(dataDict, pretty=True) - self.QBXML = xmltodict.unparse(dataDict, pretty=True).replace("", "").replace(f'version="{version}"', f'version="{version}"?') - print(self.QBXML, type(self.QBXML)) - return self.QBXML + self.QBXML = xmltodict.unparse(dataDict, pretty=True).replace("", "").replace(f'version="{version}"', f'version="{version}"?') + if self.class_debug: + print(self.QBXML, type(self.QBXML)) + return self.QBXML - # @timing - def connect_to_quickbooks(self, qbxml_query=None): - # Connect to Quickbooks - sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor") - sessionManager.OpenConnection('', 'DASA2') - # ticket = sessionManager.BeginSession("z:\\DBW Bogor.qbw", 2) - ticket = sessionManager.BeginSession("", 2) + # @timing + def connect_to_quickbooks(self, qbxml_query=None): + # Connect to Quickbooks + sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor") + sessionManager.OpenConnection('', 'DASA2') + # ticket = sessionManager.BeginSession("z:\\DBW Bogor.qbw", 2) + ticket = sessionManager.BeginSession("", 2) - # Send query and receive response - self.response_string = sessionManager.ProcessRequest(ticket, self.QBXML) + # Send query and receive response + self.response_string = sessionManager.ProcessRequest(ticket, self.QBXML) - # Disconnect from Quickbooks - sessionManager.EndSession(ticket) # Close the company file - sessionManager.CloseConnection() # Close the connection + # Disconnect from Quickbooks + sessionManager.EndSession(ticket) # Close the company file + sessionManager.CloseConnection() # Close the connection - # Beautify response_string - # print(f'{self.response_string = }') - xml = minidom.parseString(self.response_string.replace("\n", "")) - self.response_string = xml.toprettyxml() - # print(f'{self.response_string = }') + # Beautify response_string + # print(f'{self.response_string = }') + xml = minidom.parseString(self.response_string.replace("\n", "")) + self.response_string = xml.toprettyxml() + # print(f'{self.response_string = }') - self.statusOk = self.isDataOK() - return self.statusOk - return self.response_string + self.statusOk = self.isDataOK() + return self.statusOk + return self.response_string - def isDataOK(self): - # print("isdataok") - # QBXML = ET.fromstring(self.response_string) - # print(xmltodict.parse(self.response_string)) - self.varDict = xmltodict.parse(self.response_string) - if self.class_debug: - pprint.pprint("isDataOK", self.varDict) - self.listOfDict.varDict = self.varDict - self.listOfDict.filterKey = ["@requestID"] - self.requestID = self.listOfDict.firstValue().get('@requestID',None) - self.listOfDict.filterKey = ["@statusCode"] - self.statusCode = self.listOfDict.firstValue().get('@statusCode',None) - self.listOfDict.filterKey = ["@statusMessage"] - self.statusMessage = self.listOfDict.firstValue().get('@statusMessage',None) - self.listOfDict.filterKey = ["@statusSeverity"] - self.statusSeverity = self.listOfDict.firstValue().get('@statusSeverity') - self.listOfDict.filterKey = [self.retName] - if self.class_debug: - print(f'isDataOK -> {self.listOfDict.firstValue() = }') - if self.listOfDict.firstValue().get(self.retName,None)==None: - return False - - print(f'{self.statusCode = }, {self.statusMessage = }, {self.statusSeverity = }') - varDict = self.varDict['QBXML']['QBXMLMsgsRs'][self.__class__.__name__+"Rs"] - return True - # isStatusOK=None + def isDataOK(self): + # print("isdataok") + # QBXML = ET.fromstring(self.response_string) + # print(xmltodict.parse(self.response_string)) + self.varDict = xmltodict.parse(self.response_string) + if self.class_debug: + pprint.pprint("isDataOK", self.varDict) + self.listOfDict.varDict = self.varDict + self.listOfDict.filterKey = ["@requestID"] + self.requestID = self.listOfDict.firstValue().get('@requestID',None) + self.listOfDict.filterKey = ["@statusCode"] + self.statusCode = self.listOfDict.firstValue().get('@statusCode',None) + self.listOfDict.filterKey = ["@statusMessage"] + self.statusMessage = self.listOfDict.firstValue().get('@statusMessage',None) + self.listOfDict.filterKey = ["@statusSeverity"] + self.statusSeverity = self.listOfDict.firstValue().get('@statusSeverity') + self.listOfDict.filterKey = [self.retName] + if self.class_debug: + print(f'isDataOK -> {self.listOfDict.firstValue() = }') + if self.listOfDict.firstValue().get(self.retName,None)==None: + return False + if self.class_debug: + print(f'{self.statusCode = }, {self.statusMessage = }, {self.statusSeverity = }') + varDict = self.varDict['QBXML']['QBXMLMsgsRs'][self.__class__.__name__+"Rs"] + return True + # isStatusOK=None - # for _ in self.findKeyInDict("FullName", ): ###berhasil - # print(f'{_ = }') - # for _ in self.gen_dict_extract("@statusMessage", self.varDict): - # print(_) - # if 'Status OK'.lower()==_.lower(): - # print(_) - # isStatusOK = True - # break - # else: - # isStatusOK=False - - # if self.ListOfDict.find_firstListOfDict("@statusMessage")['@statusMessage'].lower()=="status OK".lower(): - # # print(f'{self.retName = }') - # self.Rs = self.find_firstListOfDict(self.retName)[self.retName] - # # self.Rs=self.returnRet(self.varDict) - # # # print(self.findKeyInDict("FullName", )) ###test - # # print(self.findKeyInDict("FullName", self.findKeyInDict("QBXMLMsgsRs1", ))) ###test - # # # print(self.findKeyInDict("@statusMessage", )) ###test - # # for _ in self.findKeyInDict("QBXMLMsgsRs",): ###trial blm berhasil - # # print(f'2{_ = }') - # # print(f'{self.Rs = }') - # # print(type(self.Rs)) - # # print(self.find_firstListOfDict("FullName")['FullName']) - # # print(self.find_firstListOfDict("FullName")) - # # print(self.find_allListOfDict("FullName")) + # for _ in self.findKeyInDict("FullName", ): ###berhasil + # print(f'{_ = }') + # for _ in self.gen_dict_extract("@statusMessage", self.varDict): + # print(_) + # if 'Status OK'.lower()==_.lower(): + # print(_) + # isStatusOK = True + # break + # else: + # isStatusOK=False + + # if self.ListOfDict.find_firstListOfDict("@statusMessage")['@statusMessage'].lower()=="status OK".lower(): + # # print(f'{self.retName = }') + # self.Rs = self.find_firstListOfDict(self.retName)[self.retName] + # # self.Rs=self.returnRet(self.varDict) + # # # print(self.findKeyInDict("FullName", )) ###test + # # print(self.findKeyInDict("FullName", self.findKeyInDict("QBXMLMsgsRs1", ))) ###test + # # # print(self.findKeyInDict("@statusMessage", )) ###test + # # for _ in self.findKeyInDict("QBXMLMsgsRs",): ###trial blm berhasil + # # print(f'2{_ = }') + # # print(f'{self.Rs = }') + # # print(type(self.Rs)) + # # print(self.find_firstListOfDict("FullName")['FullName']) + # # print(self.find_firstListOfDict("FullName")) + # # print(self.find_allListOfDict("FullName")) - def returnRet(self, varDict:dict = None): - if varDict== None: - varDict=self.varDict - # pprint.pprint(self.varDict) - - # print(f'{varDict = }') - varDict = varDict['QBXML']['QBXMLMsgsRs'][self.__class__.__name__+"Rs"] - # print(f'{varDict = }') - - for idx, key in enumerate(varDict): - # print(idx, key, len(varDict)) - if self.retName in key: - return varDict[key] - return None + def returnRet(self, varDict:dict = None): + if varDict== None: + varDict=self.varDict + # pprint.pprint(self.varDict) + + # print(f'{varDict = }') + varDict = varDict['QBXML']['QBXMLMsgsRs'][self.__class__.__name__+"Rs"] + # print(f'{varDict = }') + + for idx, key in enumerate(varDict): + # print(idx, key, len(varDict)) + if self.retName in key: + return varDict[key] + return None - def runCheck(self): - # print("runCheck") - if self.varDict: - return True - if self.response_string: - return True - if self.Rs: - return True - if self.QBDict: - self.create_QBXML() - if self.connect_to_quickbooks(): - return True - return False + def runCheck(self): + # print("runCheck") + if self.varDict: + return True + if self.response_string: + return True + if self.Rs: + return True + if self.QBDict: + self.create_QBXML() + if self.connect_to_quickbooks(): + return True + return False - def __repr__(self) -> str: - self.all() - # print(f'{self.returnRet() = }') - return self.response_string + def __repr__(self) -> str: + self.all() + # print(f'{self.returnRet() = }') + 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 count(self) -> int: + # objs = self.filter(self.defaultFilterKey).all() + # print(f"{objs = }", type(objs)) + return len(self.filter(self.defaultFilterKey).all()) - def filter(self, key=None): - print(f'{key = }') - # print(f'{self.statusOk = }') - if not self.runCheck(): - print("not runcheck") - return self.ListOfDict(["abc"], self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk) - return [] - if isinstance(key, str): - key = [key] - elif isinstance(key, list): - pass - elif isinstance(key, dict): - key = [x for x,y in key.items()] - elif key is None: - # print(f"key is none. {self.retName = }") - return self.ListOfDict(self.retName, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk)#.firstValue()#[self.retName] - else: - return [] - key = cleanIncludeRetElements(self.includeRetElements_allowed, key) - # print(f'f {key = }') - if key: - return self.ListOfDict(key, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk) - else: - return self.ListOfDict(["abc"], self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk) - ### dont use this way, better returning class because the value if you assign to variable, the valu will be the last filterKey inputed - ### if return class, every filterKey is an object, different from other filterKey - self.listOfDict.varDict = self.varDict - self.listOfDict.filterKey = key - return self.listOfDict - ### + def filter(self, key=None): + print(f'{key = }') + # print(f'{self.statusOk = }') + if not self.runCheck(): + print("not runcheck") + return self.ListOfDict(["abc"], self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk) + return [] + if isinstance(key, str): + key = [key] + elif isinstance(key, list): + pass + elif isinstance(key, dict): + key = [x for x,y in key.items()] + elif key is None: + # print(f"key is none. {self.retName = }") + return self.ListOfDict(self.retName, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk)#.firstValue()#[self.retName] + else: + return [] + key = cleanIncludeRetElements(self.includeRetElements_allowed, key) + # print(f'f {key = }') + if key: + return self.ListOfDict(key, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk) + else: + return self.ListOfDict(["abc"], self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk) + ### dont use this way, better returning class because the value if you assign to variable, the valu will be the last filterKey inputed + ### if return class, every filterKey is an object, different from other filterKey + self.listOfDict.varDict = self.varDict + self.listOfDict.filterKey = key + return self.listOfDict + ### - def all(self) -> dict: - if not self.runCheck(): - return None - # return self.ListOfDict(None, self.varDict, self.retName).firstValue() - temp = self.ListOfDict(None, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk).firstValue() - if temp: - temp = temp[self.retName] - else: - return {'status':"Error", 'statusCode': self.statusCode, 'statusMessage':self.statusMessage, 'statusSeverity': self.statusSeverity} - if self.requestID: - temp['requestID']=self.requestID - # print(f'{temp = }') - return temp - # return self.ListOfDict(None, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk).firstValue()[self.retName] - ### dont use this way - self.listOfDict.varDict = self.varDict - self.listOfDict.filterKey = self.retName - return self.listOfDict - ### - - def to_json(self) -> str: - return json.dumps(self.all()) - - - class ListOfDict: - def __init__(self, key, var, retName, includeRetElements_allowed:list ,statusOk:bool = True) -> None: - # print(f'{key =}, {var =}') - # self.first = self.find_firstListOfDict(key) - if key: - if isinstance(key, str): - self.filterKey = [key] - else: - self.filterKey = key - else: - self.filterKey = [retName] - # print(f"{self.filterKey = }") - self.varDict = var - self.statusOk = statusOk - self._includeRetElements_allowed = includeRetElements_allowed - # print("listofDict") - - - def __repr__(self) -> str: - return str(self.all()) - - # 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 - 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 - else: - key = key - # print(f'getvaluesof {key = }') - # for xdct in self.findKeyInDict(var, dataRetList): - # print(f'{xdct = }', type(xdct), self.filterKey[0], key) - 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 _lst - - def all(self, var:dict=None, dataRetList:list=None) -> list: - # print(f'{self.statusOk = }') - if not self.statusOk: - return [] - _lst = [x for x in self.findKeyInDict(var, dataRetList)] - # _lst = [x[self.filterKey] for x in self.findKeyInDict(var, dataRetList)] - # if _lst: - return _lst - # else: - # return [] - - def allOnlyValue(self, var:dict=None, dataRetList:list=None): - if not self.statusOk: - return [] - _lst = [x for x in self.findKeyInDict(var, dataRetList)] - return _lst - - def first(self, var:dict=None, dataRetList:list=None) -> dict: - if not self.statusOk: - return {} - return next(self.findKeyInDict( var, dataRetList), {}) - - def firstValue(self, var:dict=None, dataRetList:list=None) ->dict: - if not self.statusOk: - print("firstValue statusOk is False") - return {} - # return self.first(var, dataRetList)[self.filterKey] - _val=self.first(var, dataRetList) - # print(f'{_val = }') - if _val: - # return _val[self.filterKey] - return _val - else: - return {} - - def last(self, var:dict=None, dataRetList:list=None) -> dict: - if not self.statusOk: - return {} - # *_, last = self.findKeyInDict( var, dataRetList) - _val= self.all(var, dataRetList) - if _val:return _val[-1] - else: return {} - - def lastValue(self, var:dict=None, dataRetList:list=None) -> dict: - if not self.statusOk: - return {} - _val=self.last(var, dataRetList) - # print(f"lastValue {_val =}") - if _val: - # return _val[self.filterKey] - return _val - else: - return {} - - def count(self, var:dict=None, dataRetList:list=None) -> int: - if not self.statusOk: - return 0 - # print(len(self.all())) - return len(self.all()) - - # def findKeyInDict(self, var:dict=None, dataRetList:list=None, ): - # # print("genfinekeys") - # if var==None: - # var=self.varDict - # # print(f"{var = }") - # if dataRetList is None: - # dataRetList = [] - # if isinstance(var, list): - # # print("list var") - # for _ in var: - # yield from self.findKeyInDict( _, ) - # elif isinstance(var, dict): - # # print("dict var") - # if self.filterKey in var: - # dataRetList.append({self.filterKey: var[self.filterKey]}) - # print(f"{dataRetList = }") - # yield {self.filterKey: var[self.filterKey]} - # else: - # # print(f'dict else var={var}') - # for _ in var: - # # print(_) - # yield from self.findKeyInDict(var[_], ) - # return dataRetList - - def findKeyInDict(self, var:dict=None, dataRetList:list=None, ): - # print("genfinekeys") - if var==None: - var=self.varDict - # print(f"{var = }") - if dataRetList is None: - dataRetList = [] - if isinstance(var, list): - # print("list var") - for _ in var: - yield from self.findKeyInDict( _, ) - elif isinstance(var, dict): - # print("dict var") - found = False - tempDct = {} - for fKey in self.filterKey: - # if self.filterKey in var: - if fKey in var: - found = True - tempDct[fKey]=var[fKey] - # print(f'{tempDct = }') - if found: - # dataRetList.append({self.filterKey: var[self.filterKey]}) - dataRetList.append(tempDct) - # print(f"{dataRetList = }") - yield tempDct #{self.filterKey: var[self.filterKey]} - else: - # print(f'dict else var={var}') - for _ in var: - # print(_) - yield from self.findKeyInDict(var[_], ) - return dataRetList - - - # def find_allListOfDict(self, key, var:dict=None, dataRetList:list=None): - # return [x for x in self.findKeyInDict(key, var, dataRetList)] - - # def find_firstListOfDictValue(self, key, var:dict=None, dataRetList:list=None): - # return self.find_firstListOfDict(key, var, dataRetList)[key] - - # def find_firstListOfDict(self, key, var:dict=None, dataRetList:list=None): - # return next(self.findKeyInDict(key, var, dataRetList), None) - - # def findKeyInDict(self, key, var:dict=None, dataRetList:list=None, ): - # # print("genfinekeys") - # if var==None: - # var=self.varDict - # # print(f"{var = }") - # if dataRetList is None: - # dataRetList = [] - # if isinstance(var, list): - # # print("list var") - # for _ in var: - # yield from self.findKeyInDict(key, _, ) - # elif isinstance(var, dict): - # # print("dict var") - # if key in var: - # dataRetList.append({key: var[key]}) - # # print(f"{dataRetList = }") - # yield {key: var[key]} - # else: - # # print(f'dict else var={var}') - # for _ in var: - # # print(_) - # yield from self.findKeyInDict(key, var[_], ) - # return dataRetList - - - #### dont delete. - ### Example of extracting dictionary value by key - def gen_dict_extract(self, key, var:dict=None): ### Utils - if var==None: - var=self.response_string - # print("var") - if hasattr(var,'items'): # hasattr(var,'items') for python 3, hasattr(var,'iteritems') for python 2 - # print("hassattr") - for k, v in var.items(): # var.items() for python 3, var.iteritems() for python 2 - # print(k,v) - if k == key: - yield v - if isinstance(v, dict): - for result in self.gen_dict_extract(key, v): - yield result - elif isinstance(v, list): - for d in v: - for result in self.gen_dict_extract(key, d): - yield result - - def __str__(self, *args, **kwargs) -> str: - # return str(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML()))) - # print("__str__") - return str(self.all()) - return self.__class__.__name__ - return str(self.get_datarow()) - - - # def get_datarow(self, *args): - # return self._get_datarow(self.connect_to_quickbooks(self.create_QBXML())) + def all(self) -> dict: + if not self.runCheck(): + return None + # return self.ListOfDict(None, self.varDict, self.retName).firstValue() + temp = self.ListOfDict(None, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk).firstValue() + if temp: + temp = temp[self.retName] + else: + return {'status':"Error", 'statusCode': self.statusCode, 'statusMessage':self.statusMessage, 'statusSeverity': self.statusSeverity} + if self.requestID: + temp['requestID']=self.requestID + # print(f'{temp = }') + return temp + # return self.ListOfDict(None, self.varDict, self.retName, self.includeRetElements_allowed, self.statusOk).firstValue()[self.retName] + ### dont use this way + self.listOfDict.varDict = self.varDict + self.listOfDict.filterKey = self.retName + return self.listOfDict + ### + + def to_json(self) -> str: + return json.dumps(self.all()) - # def get_dict(self, *args): - # return pd.DataFrame(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML()))) - def status_ok(self, QBXML): - GSRQRs=QBXML.find('.//GeneralSummaryReportQueryRs') - status_code = GSRQRs.attrib #.get('statusCode') - # print(GSRQRs.attrib) - # print(GSRQRs.attrib['statusCode']) - status=GSRQRs.attrib.get('statusMessage') - - print(f'status={status}') - if 'OK' in status: - return True, status_code - else: - return False, status_code + class ListOfDict: + def __init__(self, key, var, retName, includeRetElements_allowed:list ,statusOk:bool = True) -> None: + # print(f'{key =}, {var =}') + # self.first = self.find_firstListOfDict(key) + if key: + if isinstance(key, str): + self.filterKey = [key] + else: + self.filterKey = key + else: + self.filterKey = [retName] + # print(f"{self.filterKey = }") + self.varDict = var + self.statusOk = statusOk + self._includeRetElements_allowed = includeRetElements_allowed + # print("listofDict") + + + def __repr__(self) -> str: + return str(self.all()) + + # 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 + 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 + else: + key = key + # print(f'getvaluesof {key = }') + # for xdct in self.findKeyInDict(var, dataRetList): + # print(f'{xdct = }', type(xdct), self.filterKey[0], key) + 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 _lst + + def all(self, var:dict=None, dataRetList:list=None) -> list: + # print(f'{self.statusOk = }') + if not self.statusOk: + return [] + _lst = [x for x in self.findKeyInDict(var, dataRetList)] + # _lst = [x[self.filterKey] for x in self.findKeyInDict(var, dataRetList)] + # if _lst: + return _lst + # else: + # return [] + + def allOnlyValue(self, var:dict=None, dataRetList:list=None): + if not self.statusOk: + return [] + _lst = [x for x in self.findKeyInDict(var, dataRetList)] + return _lst + + def first(self, var:dict=None, dataRetList:list=None) -> dict: + if not self.statusOk: + return {} + return next(self.findKeyInDict( var, dataRetList), {}) + + def firstValue(self, var:dict=None, dataRetList:list=None) ->dict: + if not self.statusOk: + print("firstValue statusOk is False") + return {} + # return self.first(var, dataRetList)[self.filterKey] + _val=self.first(var, dataRetList) + # print(f'{_val = }') + if _val: + # return _val[self.filterKey] + return _val + else: + return {} + + def last(self, var:dict=None, dataRetList:list=None) -> dict: + if not self.statusOk: + return {} + # *_, last = self.findKeyInDict( var, dataRetList) + _val= self.all(var, dataRetList) + if _val:return _val[-1] + else: return {} + + def lastValue(self, var:dict=None, dataRetList:list=None) -> dict: + if not self.statusOk: + return {} + _val=self.last(var, dataRetList) + # print(f"lastValue {_val =}") + if _val: + # return _val[self.filterKey] + return _val + else: + return {} + + def count(self, var:dict=None, dataRetList:list=None) -> int: + if not self.statusOk: + return 0 + # print(len(self.all())) + return len(self.all()) + + # def findKeyInDict(self, var:dict=None, dataRetList:list=None, ): + # # print("genfinekeys") + # if var==None: + # var=self.varDict + # # print(f"{var = }") + # if dataRetList is None: + # dataRetList = [] + # if isinstance(var, list): + # # print("list var") + # for _ in var: + # yield from self.findKeyInDict( _, ) + # elif isinstance(var, dict): + # # print("dict var") + # if self.filterKey in var: + # dataRetList.append({self.filterKey: var[self.filterKey]}) + # print(f"{dataRetList = }") + # yield {self.filterKey: var[self.filterKey]} + # else: + # # print(f'dict else var={var}') + # for _ in var: + # # print(_) + # yield from self.findKeyInDict(var[_], ) + # return dataRetList + + def findKeyInDict(self, var:dict=None, dataRetList:list=None, ): + # print("genfinekeys") + if var==None: + var=self.varDict + # print(f"{var = }") + if dataRetList is None: + dataRetList = [] + if isinstance(var, list): + # print("list var") + for _ in var: + yield from self.findKeyInDict( _, ) + elif isinstance(var, dict): + # print("dict var") + found = False + tempDct = {} + for fKey in self.filterKey: + # if self.filterKey in var: + if fKey in var: + found = True + tempDct[fKey]=var[fKey] + # print(f'{tempDct = }') + if found: + # dataRetList.append({self.filterKey: var[self.filterKey]}) + dataRetList.append(tempDct) + # print(f"{dataRetList = }") + yield tempDct #{self.filterKey: var[self.filterKey]} + else: + # print(f'dict else var={var}') + for _ in var: + # print(_) + yield from self.findKeyInDict(var[_], ) + return dataRetList + + + # def find_allListOfDict(self, key, var:dict=None, dataRetList:list=None): + # return [x for x in self.findKeyInDict(key, var, dataRetList)] + + # def find_firstListOfDictValue(self, key, var:dict=None, dataRetList:list=None): + # return self.find_firstListOfDict(key, var, dataRetList)[key] + + # def find_firstListOfDict(self, key, var:dict=None, dataRetList:list=None): + # return next(self.findKeyInDict(key, var, dataRetList), None) + + # def findKeyInDict(self, key, var:dict=None, dataRetList:list=None, ): + # # print("genfinekeys") + # if var==None: + # var=self.varDict + # # print(f"{var = }") + # if dataRetList is None: + # dataRetList = [] + # if isinstance(var, list): + # # print("list var") + # for _ in var: + # yield from self.findKeyInDict(key, _, ) + # elif isinstance(var, dict): + # # print("dict var") + # if key in var: + # dataRetList.append({key: var[key]}) + # # print(f"{dataRetList = }") + # yield {key: var[key]} + # else: + # # print(f'dict else var={var}') + # for _ in var: + # # print(_) + # yield from self.findKeyInDict(key, var[_], ) + # return dataRetList + + + #### dont delete. + ### Example of extracting dictionary value by key + def gen_dict_extract(self, key, var:dict=None): ### Utils + if var==None: + var=self.response_string + # print("var") + if hasattr(var,'items'): # hasattr(var,'items') for python 3, hasattr(var,'iteritems') for python 2 + # print("hassattr") + for k, v in var.items(): # var.items() for python 3, var.iteritems() for python 2 + # print(k,v) + if k == key: + yield v + if isinstance(v, dict): + for result in self.gen_dict_extract(key, v): + yield result + elif isinstance(v, list): + for d in v: + for result in self.gen_dict_extract(key, d): + yield result + + def __str__(self, *args, **kwargs) -> str: + # return str(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML()))) + # print("__str__") + return str(self.all()) + return self.__class__.__name__ + return str(self.get_datarow()) + + + # def get_datarow(self, *args): + # return self._get_datarow(self.connect_to_quickbooks(self.create_QBXML())) + + # def get_dict(self, *args): + # return pd.DataFrame(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML()))) + + def status_ok(self, QBXML): + GSRQRs=QBXML.find('.//GeneralSummaryReportQueryRs') + status_code = GSRQRs.attrib #.get('statusCode') + # print(GSRQRs.attrib) + # print(GSRQRs.attrib['statusCode']) + status=GSRQRs.attrib.get('statusMessage') + + print(f'status={status}') + if 'OK' in status: + return True, status_code + else: + return False, status_code + - if __name__ == '__main__': - pass \ No newline at end of file + pass \ No newline at end of file