dasaproject/qbItemInventoryQuery.py
2023-09-27 15:49:36 +07:00

66 lines
2.1 KiB
Python

#!usr/bin/python
import win32com.client
import xml.etree.ElementTree
# Connect to Quickbooks
sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor")
sessionManager.OpenConnection('', 'Test qbXML Request')
ticket = sessionManager.BeginSession("", 2)
# Send query and receive response
qbxml_query = """
<?qbxml version="6.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<InventoryAdjustmentQueryRq metaData="MetaDataAndResponseData">
</InventoryAdjustmentQueryRq>
</QBXMLMsgsRq>
</QBXML>
"""
qbxml_query1 = """
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<TransactionQueryRq metaData="ENUMTYPE" iterator="ENUMTYPE" iteratorID="UUIDTYPE">
<TxnTypeFilter >SalesOrder</TxnTypeFilter> <!-- required, may repeat -->
</TransactionQueryRq>
</QBXMLMsgsRq>
</QBXML>
"""
qbxml_query = """
<?qbxml version="6.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<ItemInventoryQueryRq metaData="MetaDataAndResponseData">
<ActiveStatus >ActiveOnly</ActiveStatus> <!-- optional -->
<IncludeRetElement >FullName</IncludeRetElement> <!-- optional, may repeat -->
<IncludeRetElement >Name</IncludeRetElement> <!-- optional, may repeat -->
</ItemInventoryQueryRq>
</QBXMLMsgsRq>
</QBXML>
"""
response_string = sessionManager.ProcessRequest(ticket, qbxml_query)
# Disconnect from Quickbooks
sessionManager.EndSession(ticket) # Close the company file
sessionManager.CloseConnection() # Close the connection
print (response_string)
# Parse the response into an Element Tree and peel away the layers of response
QBXML = xml.etree.ElementTree.fromstring(response_string)
print("")
print(QBXML)
QBXMLMsgsRs = QBXML.find('QBXMLMsgsRs')
#ItemInventoryQueryRs = QBXMLMsgsRs.getiterator("ItemInventoryRet")
ItemInventoryQueryRs = QBXMLMsgsRs.iter("ItemInventoryRet")
for ItemInv in ItemInventoryQueryRs:
# txnid = InvAdjRet.find('TxnID').text
print(ItemInv.find('FullName').text)
# FullName =
#memo = InvAdjRet.find('memo').text
# print(txnid)