update InvoiceAdd class with lineadd

This commit is contained in:
bcomsugi 2025-02-23 04:35:57 +07:00
parent 2351d4d80b
commit 786ba1e6d1
2 changed files with 269 additions and 193 deletions

View File

@ -1,9 +1,9 @@
from .server import baseQBQuery from server import baseQBQuery
# from server import baseQBQuery, timing # from server import baseQBQuery, timing
import pprint import pprint
# import timeit # import timeit
# import xml.dom.minidom # import xml.dom.minidom
from .utils import timing, cleanIncludeRetElements, makeAList from utils import timing, cleanIncludeRetElements, makeAList
import json import json
from typing import Union from typing import Union
@ -22,7 +22,7 @@ class ItemInventoryQuery(baseQBQuery):
self.includeRetElements_allowed = ["ListID", "FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "BarCodeValue", self.includeRetElements_allowed = ["ListID", "FullName", "TimeCreated", "TimeModified", "EditSequence", "Name", "IsActive", "ClassRef", "ParentRef", "Sublevel", "BarCodeValue",
"ManufacturerPartNumber", "UnitOfMeasureSetRef", "IsTaxIncluded", "SalesTaxCodeRef", "SalesDesc,", "SalesPrice", "IncomeAccountRef", "ManufacturerPartNumber", "UnitOfMeasureSetRef", "IsTaxIncluded", "SalesTaxCodeRef", "SalesDesc,", "SalesPrice", "IncomeAccountRef",
"PurchaseDesc", "PurchaseCost", "PurchaseTaxCodeRef", "COGSAccountRef", "PrefVendorRef", "AssetAccountRef", "ReforderPoint", "Max", "QuantityOnHand", "PurchaseDesc", "PurchaseCost", "PurchaseTaxCodeRef", "COGSAccountRef", "PrefVendorRef", "AssetAccountRef", "ReforderPoint", "Max", "QuantityOnHand",
"AcerageCost", "QuantityOnOrder", "QuantityOnSalesOrder", "AverageCost", "QuantityOnOrder", "QuantityOnSalesOrder",
"ExternalGUID", "DataExtRet", "ExternalGUID", "DataExtRet",
] ]
self.onError = "stopOnError" self.onError = "stopOnError"
@ -494,15 +494,82 @@ class InvoiceAdd(baseQBQuery):
self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]={'CreditTxnID':{'@useMacro':"MACROTYPE", '#text':kwargs['SetCredit_CreditTxnID']}, 'AppliedAmount': kwargs['SetCredit_AppliedAmount']} self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]={'CreditTxnID':{'@useMacro':"MACROTYPE", '#text':kwargs['SetCredit_CreditTxnID']}, 'AppliedAmount': kwargs['SetCredit_AppliedAmount']}
if 'SetCredit_Override' in kwargs: if 'SetCredit_Override' in kwargs:
self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]["Override"]=kwargs['SetCredit_Override'] self.QBDict[self.classNameRq][self.__class__.__name__]["SetCredit"]["Override"]=kwargs['SetCredit_Override']
#add InvoiceLineAdd kwargs here #add InvoiceLineAdd kwargs here
self.InvoiceLineAdd = []
if 'InvoiceLineAdd' in kwargs:
LineAdd = kwargs.get('InvoiceLineAdd')
self.isLineAddOk = True
if isinstance(LineAdd, dict ):
LineAdd = [LineAdd]
elif isinstance(LineAdd, list):
pass
else:
self.isLineAddOk = False
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("InvoiceLineAdd 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 'Other2' in eachLineAdd:
self.LineAddDict["Other2"]=eachLineAdd['Other2']
if len(self.LineAddDict)>0:
self.InvoiceLineAdd.append(self.LineAddDict)
if 'LinkToTxn_TxnID' in eachLineAdd and 'LinkToTxn_TxnLineID' in eachLineAdd:
self.LineAddDict["LinkToTxn"]={'TxnID': eachLineAdd['LinkToTxn_TxnID'], 'TxnLineID': eachLineAdd['LinkToTxn_TxnLineID']}
#skip the rest, not too important
else:
print("InvoiceLineAdd has to be list of dict or a dict")
# print(f'{self.InvoiceLineAdd = }')
if len(self.InvoiceLineAdd)>0:
self.QBDict[self.classNameRq][self.__class__.__name__]['InvoiceLineAdd']=self.InvoiceLineAdd
if 'IncludeRetElement' in kwargs: if 'IncludeRetElement' in kwargs:
self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement'] self.QBDict[self.classNameRq]["IncludeRetElement"]=kwargs['IncludeRetElement']
# print(self.classNameRq) # print(self.classNameRq)
# print(self.QBDict) # pprint.pprint(self.QBDict, sort_dicts=False)
class CustomerQuery(baseQBQuery): class CustomerQuery(baseQBQuery):
@ -551,7 +618,9 @@ class CustomerQuery(baseQBQuery):
print(f'{IRE = }') print(f'{IRE = }')
if len(IRE)>0: if len(IRE)>0:
if self.defaultFilterKey not in IRE: if self.defaultFilterKey not in IRE:
IRE.append(self.defaultFilterKey) # IRE.append(self.defaultFilterKey)
self.QBDict[self.classNameRq]["IncludeRetElement"]=['ListID'] + IRE
else:
self.QBDict[self.classNameRq]["IncludeRetElement"]=IRE self.QBDict[self.classNameRq]["IncludeRetElement"]=IRE
else: else:
self.QBDict[self.classNameRq]["IncludeRetElement"]=self.includeRetElements_allowed self.QBDict[self.classNameRq]["IncludeRetElement"]=self.includeRetElements_allowed
@ -1302,7 +1371,13 @@ if __name__ == "__main__":
@timing @timing
def customerquery(): def customerquery():
g= CustomerQuery(MaxReturned=3, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock", "Notes", "AdditionalNotesRet", 'creditlimit']) FullName = 'Sentosa Jati Bening'
# FullName = "8, Toko"
FullName = "999 HPL"
g= CustomerQuery(MaxReturned=6, IncludeRetElement=["fullname", "name", "CompanyName", "ShipAddress", "ShipToAddress","Phone", "Notes", "AdditionalNotesRet", 'creditlimit'])
# g= CustomerQuery(MaxReturned=3, IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock", "Notes", "AdditionalNotesRet", 'creditlimit'])
# g=CustomerQuery(MaxReturned = None,)
# g= CustomerQuery(FullName= FullName,)# IncludeRetElement=["fullname", "name", "CompanyName", "BillAddressBlock", "ShipAddressBlock", "Notes", "AdditionalNotesRet", 'creditlimit'])
# g= CustomerQuery(MaxReturned=20, ActiveStatus="ActiveOnly", MatchCriterion="StartsWith", Name="to", IncludeRetElement=["fullname", "name", "billaddressblock", "currencyfilter"]) # g= CustomerQuery(MaxReturned=20, ActiveStatus="ActiveOnly", MatchCriterion="StartsWith", Name="to", IncludeRetElement=["fullname", "name", "billaddressblock", "currencyfilter"])
# print(g.IncludeRetElements_allowed) # print(g.IncludeRetElements_allowed)
print("init finish") print("init finish")
@ -1376,13 +1451,13 @@ if __name__ == "__main__":
print([y for y in x]) print([y for y in x])
print(f"{x.get('Name')} : {len(x.get('PriceLevelPerItemRet'))}") print(f"{x.get('Name')} : {len(x.get('PriceLevelPerItemRet'))}")
pricelevel() # pricelevel()
# invoicequery() # invoicequery()
# salesorderquery() # salesorderquery()
# transactionquery() # transactionquery()
# pprint.pprint(InventoryStockStatusByVendor(), sort_dicts=False) # pprint.pprint(InventoryStockStatusByVendor(), sort_dicts=False)
# iteminventoryquery() # iteminventoryquery()
# customerquery() customerquery()
# readxmltodict() # readxmltodict()
# g=SalesOrderQuery(MaxReturned=1) # g=SalesOrderQuery(MaxReturned=1)
# print(len(None)) # print(len(None))

View File

@ -102,6 +102,7 @@ class baseQBQuery:
# print(f'{self.response_string = }') # print(f'{self.response_string = }')
xml = minidom.parseString(self.response_string.replace("\n", "")) xml = minidom.parseString(self.response_string.replace("\n", ""))
self.response_string = xml.toprettyxml() self.response_string = xml.toprettyxml()
print(self.response_string)
# print(f'{self.response_string = }') # print(f'{self.response_string = }')
self.statusOk = self.isDataOK() self.statusOk = self.isDataOK()