update main and qb classes, adding on po info in checkstock

This commit is contained in:
bcomsugi 2025-03-15 15:27:59 +07:00
parent af437667b4
commit a09792ba8a
4 changed files with 137 additions and 15 deletions

View File

@ -1361,12 +1361,14 @@ if __name__ == "__main__":
@timing @timing
def main(): def main():
g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear") g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="ProfitAndLossStandard", ReportDateMacro="ThisYear")
print(g, type(g)) g= GeneralSummaryReportQuery(debug=True, GeneralSummaryReportType="InventoryStockStatusByItem", ReportItemFilter_FullName=['ECO:0:ECO-009', 'TACF:HNDL:TP-H04/MR','ECO:0:ECO-007', 'ECO:0:ECO-006'])
print(type(g.all())) # print(g, type(g))
print(g.all()) # print(type(g.all()))
print(g.response_string) # print(g.all())
pprint.pprint(g.filter("reportdata").all()) # print(g.response_string)
print(g.filter("reportdata").all())
print(g.count(), g.all()) print(g.count(), g.all())
print(f'{g.filter("datarow").getItemInventory_Report() = }')
@timing @timing
def iteminventoryquery(): def iteminventoryquery():
@ -1472,13 +1474,15 @@ 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'))}")
main()
# 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

@ -437,6 +437,84 @@ class baseQBQuery:
yield from self.findKeyInDict(var[_], ) yield from self.findKeyInDict(var[_], )
return dataRetList return dataRetList
def getShortName(self, FullName):
#print(FullName)
return FullName.split(":")[-1]
def getItemInventory_Report(self): #DataRow):
print(f'{self.filterKey=} {self.__class__.__name__ = }')
if self.filterKey[0].lower()!='datarow' or len(self.filterKey)>1:
return {}
DataRow = self.all()[0]
if not DataRow.get('DataRow'):
print('No DataRow Passed')
return {}
if not isinstance(DataRow.get('DataRow'), list):
DataRow = [DataRow.get('DataRow')]
else:
DataRow = DataRow.get('DataRow')
itemInvDict = {}
for ItemInvRet in DataRow:
try:
Rowdata = ItemInvRet.get("RowData")
fullName = Rowdata.get("@value")
ColDatas = ItemInvRet.get("ColData")
QOH, QOSO, QA, QOPO, UOM, ND = None, None, None, None, None, None
for ColData in ColDatas:
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"] =="13":
ND = ColData["@value"]
# Rowdata = ItemInvRet.find("RowData")
# fullName = Rowdata.attrib["value"]
# ColDatas = ItemInvRet.iter("ColData")
# for ColData in ColDatas:
# if ColData.attrib["colID"] == "5":
# QOH = ColData.attrib["value"]
# elif ColData.attrib["colID"] =="6":
# QOSO = ColData.attrib["value"]
# elif ColData.attrib["colID"] =="8":
# QA = ColData.attrib["value"]
# elif ColData.attrib["colID"] =="9":
# UOM = ColData.attrib["value"]
# elif ColData.attrib["colID"] =="11":
# QOPO = ColData.attrib["value"]
# elif ColData.attrib["colID"] =="13":
# ND = ColData.attrib["value"]
# print("IRQ Modul:",fullName, f'{QOH=} {QOSO=} {QA=} {QOPO=} {UOM=} {ND=} {self.getShortName(fullName)=}' )
# itemInvDict[fullName] = [self.getShortName(fullName), int(QOH) - int(QOSO)]
itemInvDict[self.getShortName(fullName)] = {'ShortName':self.getShortName(fullName), 'QOH':int(float(QOH)), 'QOSO':int(float(QOSO)), 'QA':int(float(QA)), 'QOPO':int(float(QOPO)), 'UOM':UOM, 'ND':ND}
#print(ItemInvRet.attrib, ItemInvRet.tag, ItemInvRet.text)
# QOH = ItemInvRet.find('QuantityOnHand').text
# QOSO = ItemInvRet.find('QuantityOnSalesOrder').text
# #txnid = ItemInvRet.find('ListID').text
# name = ItemInvRet.find('Name').text
# fullName = ItemInvRet.find('FullName').text
# itemInvDict[fullName] = [name, int(QOH) - int(QOSO)]
# #print(itemInvDict[name], name, QOH, QOSO)
except AttributeError:
pass
print(" Attribute err")
except Exception as e:
print("err:", e)
# print(f'{itemInvDict = }')
return itemInvDict
# def find_allListOfDict(self, key, var:dict=None, dataRetList:list=None): # def find_allListOfDict(self, key, var:dict=None, dataRetList:list=None):
# return [x for x in self.findKeyInDict(key, var, dataRetList)] # return [x for x in self.findKeyInDict(key, var, dataRetList)]

31
main.py
View File

@ -21,6 +21,7 @@ import os
from QBClass.QBClasses import SalesOrderAdd, InventoryStockStatusByVendor, PriceLevelQuery, TransactionQuery from QBClass.QBClasses import SalesOrderAdd, InventoryStockStatusByVendor, PriceLevelQuery, TransactionQuery
from QBClass.QBClasses import CustomerQuery as CQ from QBClass.QBClasses import CustomerQuery as CQ
from QBClass.QBClasses import ItemInventoryQuery as IIQ from QBClass.QBClasses import ItemInventoryQuery as IIQ
from QBClass.QBClasses import GeneralSummaryReportQuery as GSRQuery
import pprint import pprint
@ -276,6 +277,36 @@ async def get_stock(request: Request):
print("") print("")
return responseRt return responseRt
@app.post('/get-iteminventory_report')
async def getiteminventory_report(request:Request):
print('masuk getiteminventoryreport')
params = await request.body()
print('getiteminventoryrepot')
try:
params = json.loads(params)
except:
print('error get-iteminventory_report')
return {'message':'error get-iteminventory_report'}
# print(f'{request.query_params = }')
# params = await request.json()
print(f'{params = }')
# print(type(params), params)
# params = request.query_params._dict
print(type(params), f'{params = }')
# iteminventory = CustomerQuery.CustomerQuery(**params)
iteminventory_report = GSRQuery(**params, debug=False)
# print(iteminventory.all())
# status, data = iteminventory.to_json()
# print(f'{MaxReturned = }')
# print(f'{request.query_params = }')
# print(iteminventory_report.filter('datarow').getItemInventory_Report())
ret = iteminventory_report.filter('DataRow').getItemInventory_Report()
# print(f'{ret = } {type(ret) = } {len(ret) = }')
if len(ret)>0:
return ret
else:
return {'Info': f"CANNOT Get", 'Status':'ERROR', 'msg':f'Cannot Get /getiteminventory_report with params: {params}'}
@app.post('/dasa2/get_generalsalesreport') @app.post('/dasa2/get_generalsalesreport')
async def get_generalsalesreport(request: Request): async def get_generalsalesreport(request: Request):
getdict = await request.body() getdict = await request.body()

View File

@ -1,5 +1,6 @@
import win32com.client import win32com.client
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from QBClass.QBClasses import GeneralSummaryReportQuery
class QuickBooksSDK: class QuickBooksSDK:
def __init__(self): def __init__(self):
@ -113,16 +114,24 @@ class QuickBooksSDK:
# **🔹 Main Execution** # **🔹 Main Execution**
if __name__ == "__main__": if __name__ == "__main__":
qb = QuickBooksSDK() # qb = QuickBooksSDK()
try: # try:
qb.open_connection() # qb.open_connection()
# Query sales orders from January 1, 2024 to January 5, 2024 # # Query sales orders from January 1, 2024 to January 5, 2024
sales_orders = qb.get_sales_orders("2024-01-01", "2024-01-05") # sales_orders = qb.get_sales_orders("2024-01-01", "2024-01-05")
# Print hasil dalam format dictionary # # Print hasil dalam format dictionary
print("Sales Orders:", sales_orders) # print("Sales Orders:", sales_orders)
finally: # finally:
qb.close_connection() # qb.close_connection()
g= GeneralSummaryReportQuery(debug=False, GeneralSummaryReportType="InventoryStockStatusByItem", ReportItemFilter_FullName=['ECO:0:ECO-009', 'TACF:HNDL:TP-H04/MR','ECO:0:ECO-007', 'ECO:0:ECO-006'])
# print(g, type(g))
# print(type(g.all()))
# print(g.all())
# print(g.response_string)
# print(g.filter("reportdata").all())
# print(g.all())
print(f'{g.filter("datarow").getItemInventory_Report() = }')