mirror of
https://github.com/bcomsugi/dasaproject.git
synced 2026-01-10 16:52:38 +07:00
prepare data init
This commit is contained in:
parent
104b1021b7
commit
b2bd10e596
@ -179,7 +179,8 @@ if __name__ == "__main__":
|
||||
# ini= ItemInventoryQuery(IncludeRetElement=['FullName', 'DataExtRet'] , OwnerID = str(x), MaxReturned=None)
|
||||
# ini= ItemInventoryQuery( OwnerID = str(x), MaxReturned="10", NameRangeFilter=["TSHT:TS WOODGRAIN:TS-252", "TSHT:TS WOODGRAIN:TS-252"])
|
||||
# ini= ItemInventoryQuery( OwnerID = str(x), MaxReturned="10", NameRangeFilter=["TSHT:TS LUXURY:TS-L-252", "TSHT:TS LUXURY:TS-L-252"])
|
||||
ini= ItemInventoryQuery( OwnerID = str(x), MaxReturned="10")
|
||||
# ini= ItemInventoryQuery( OwnerID = str(x), MaxReturned="10")
|
||||
ini= ItemInventoryQuery( OwnerID ="0", MaxReturned=None)
|
||||
# ini= ItemInventoryQuery( OwnerID = str(x))
|
||||
# ini.to_excel('ItemInventory\ItemInventory_FromQB.xlsx')
|
||||
itu = ini.connect_to_quickbooks(ini.create_QBXML())
|
||||
@ -189,7 +190,7 @@ if __name__ == "__main__":
|
||||
print("YEAH")
|
||||
df = pd.DataFrame.from_dict(ini.get_data(itu))
|
||||
print(df)
|
||||
# df.to_excel('ItemInventory\ItemInventory_FromQB.xlsx', index=False)
|
||||
df.to_excel('ItemInventory\ItemInventory_FromQB.xlsx', index=False)
|
||||
modtime = datetime.fromtimestamp(os.path.getmtime('ItemInventory\ItemInventory_FromQB.xlsx'))
|
||||
print(f"modified Time:{modtime}")
|
||||
break
|
||||
|
||||
@ -6,6 +6,8 @@ import datetime
|
||||
import pandas as pd
|
||||
from datetime import date
|
||||
import timeit
|
||||
import pythoncom
|
||||
|
||||
|
||||
class PriceLevelQuery:
|
||||
def __init__(self, **kwargs) -> None:
|
||||
@ -16,8 +18,13 @@ class PriceLevelQuery:
|
||||
self.IncludeRetElement = kwargs['IncludeRetElement'] if 'IncludeRetElement' in kwargs else []
|
||||
self.TxnDateRangeFilter = kwargs['TxnDateRangeFilter'] if 'TxnDateRangeFilter' in kwargs else None
|
||||
self.FullName = kwargs['FullName'] if 'FullName' in kwargs and isinstance(kwargs['FullName'], list) else []
|
||||
print(f'FULLNAME:{self.FullName}')
|
||||
self.NameFilter = kwargs['NameFilter'] if 'NameFilter' in kwargs else None
|
||||
self.ItemRef = kwargs['ItemRef'] if 'ItemRef' in kwargs else None
|
||||
self.QBXML = None
|
||||
self.response_string = None
|
||||
self.status_ok = False
|
||||
self.status_msg = None
|
||||
|
||||
def create_sub_element(self, ET, parentNode, thisNode, text="\n", whiteSpace = 0, attrib =None):
|
||||
if type(attrib) is not dict:
|
||||
@ -62,7 +69,8 @@ class PriceLevelQuery:
|
||||
qbxml_query = qbxml_query + """<?qbxml version="13.0"?>"""
|
||||
qbxml_query = qbxml_query + "\n" + mydata
|
||||
# print(f'create_QBXML->qbxml_query: {qbxml_query}')
|
||||
return qbxml_query
|
||||
self.QBXML = qbxml_query
|
||||
return self.QBXML
|
||||
|
||||
def create_invoiceadd_QBXML(self):
|
||||
root = ET.Element("QBXML")
|
||||
@ -124,7 +132,7 @@ class PriceLevelQuery:
|
||||
# enumfodnc= win32com.client.Dispatch('QBXMLRP2.RequestProcessor')
|
||||
# print(enumfodnc)
|
||||
# print(enumfodnc.qbFileOpenDoNotCare)
|
||||
sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor")
|
||||
sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor", pythoncom.CoInitialize())
|
||||
sessionManager.OpenConnection('', 'DASA2')
|
||||
# ticket = sessionManager.BeginSession("z:\\DBW Bogor.qbw", 2)
|
||||
|
||||
@ -137,7 +145,8 @@ class PriceLevelQuery:
|
||||
sessionManager.EndSession(ticket) # Close the company file
|
||||
sessionManager.CloseConnection() # Close the connection
|
||||
# print (f'response_string:{response_string}')
|
||||
return response_string
|
||||
self.response_string = response_string
|
||||
return self.response_string
|
||||
|
||||
def __str__(self, *args) -> str:
|
||||
# return str(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML())))
|
||||
@ -148,10 +157,11 @@ class PriceLevelQuery:
|
||||
def get_sales_order_header(self, *args):
|
||||
return self. _get_sales_order_header(self.connect_to_quickbooks(self.create_QBXML()))
|
||||
|
||||
def status_ok(self, QBXML): #for InvoiceAddRS
|
||||
|
||||
tree = ET.fromstring(QBXML)
|
||||
|
||||
def get_status(self, QBXML=None): #for InvoiceAddRS
|
||||
if not QBXML:
|
||||
tree = ET.fromstring(self.response_string)
|
||||
else:
|
||||
tree = ET.fromstring(QBXML)
|
||||
GSRQRs = tree.find(".//PriceLevelQueryRs")
|
||||
# print(f"GSRQRs:{GSRQRs}")
|
||||
status_code = GSRQRs.attrib #.get('statusCode')
|
||||
@ -159,10 +169,13 @@ class PriceLevelQuery:
|
||||
# print(GSRQRs.attrib['statusCode'])
|
||||
status=GSRQRs.attrib.get('statusMessage')
|
||||
|
||||
print(f'status={status}')
|
||||
print(f'get_status={status}')
|
||||
self.status_msg = status_code
|
||||
if 'OK' in status:
|
||||
self.status_ok = True
|
||||
return True, status_code
|
||||
else:
|
||||
self.status_ok = False
|
||||
return False, status_code
|
||||
|
||||
|
||||
@ -346,7 +359,7 @@ class PriceLevelQuery:
|
||||
def get_pricelevel(self, response_string=None):
|
||||
if not response_string:
|
||||
response_string = self.connect_to_quickbooks(self.create_QBXML())
|
||||
statusok, status = self.status_ok(response_string)
|
||||
statusok, status = self.get_status(response_string)
|
||||
if statusok:
|
||||
QBXML = ET.fromstring(response_string)
|
||||
PriceLevellist = {}
|
||||
@ -356,7 +369,6 @@ class PriceLevelQuery:
|
||||
PriceLevelNamelist = []
|
||||
# PriceLevelName = QBXML.find('.//Name').text
|
||||
|
||||
# print(f'PriceLevelPerItemRets count:{len(PriceLevelPerItemRets)}')
|
||||
for PriceLevelRet in PriceLevelRets:
|
||||
PriceLevelPerItemRets = PriceLevelRet.findall('.//PriceLevelPerItemRet')
|
||||
PriceLevelName = PriceLevelRet.find('.//Name').text
|
||||
@ -377,9 +389,9 @@ class PriceLevelQuery:
|
||||
print(PriceLeveldf)
|
||||
PriceLeveldf.to_excel('ItemInventory\PriceLevel.xlsx', sheet_name=PriceLevelName, index=False )
|
||||
# print(PriceLevellist)
|
||||
return PriceLevellist
|
||||
return PriceLevellist, status
|
||||
else:
|
||||
return None
|
||||
return None, status
|
||||
|
||||
def create_open_sales_order_qbxml(self, txnid:list, IncludeLineItems=True):
|
||||
root = ET.Element("QBXML")
|
||||
@ -421,19 +433,40 @@ class PriceLevelQuery:
|
||||
return None
|
||||
return None
|
||||
|
||||
def name_list(self):
|
||||
self.get_status(self.connect_to_quickbooks(self.create_QBXML()))
|
||||
namelist = []
|
||||
if self.status_ok:
|
||||
tree = ET.fromstring(self.response_string)
|
||||
|
||||
for _ in tree.iter('Name'):
|
||||
# print(_.text)
|
||||
namelist.append(_.text)
|
||||
if len(namelist)>0:
|
||||
return namelist
|
||||
return None
|
||||
|
||||
|
||||
print('### PriceLevelQuery ###')
|
||||
if __name__ == '__main__':
|
||||
starttime = timeit.default_timer()
|
||||
# ini=PriceLevelQuery(FullName= '999 HPL', IncludeRetElement = ['TxnID', 'TimeCreated', 'TimeModified','TxnNumber', 'CustomerRef', 'IsManuallyClosed', 'IsFullyInvoiced'])
|
||||
# ini=PriceLevelQuery(FullName= 'abadi serpong', IncludeRetElement = ['TxnID', 'TimeCreated', 'TimeModified','TxnNumber', 'CustomerRef', 'TxnDate', 'RefNumber', 'IsManuallyClosed', 'IsFullyInvoiced','TotalAmount'])
|
||||
ini = PriceLevelQuery(FullName = ['t 202202', 'M 202202'], )
|
||||
FullName = ['t 202202', 'M 202202', 'b 202202']
|
||||
FullName = None
|
||||
ini = PriceLevelQuery(FullName = FullName, IncludeRetElement=['Name'] )
|
||||
# ini = PriceLevelQuery( ItemRef="ECO:0:ECO-002")
|
||||
itu = ini.create_QBXML()
|
||||
print(f'createQBXML->main:{itu}')
|
||||
response_string = ini.connect_to_quickbooks(itu)
|
||||
print(f'response_string:{response_string}')
|
||||
response_string = None
|
||||
pricelevel = ini.get_pricelevel()
|
||||
print(ini.name_list())
|
||||
# itu = ini.create_QBXML()
|
||||
# print(f'createQBXML->main:{itu}')
|
||||
# response_string = ini.connect_to_quickbooks(itu)
|
||||
# print(f'response_string:{response_string}')
|
||||
# response_string = None
|
||||
# pricelevel, status = ini.get_pricelevel()
|
||||
# if pricelevel:
|
||||
# print(f'Success Save Price Level : {FullName}')
|
||||
# else:
|
||||
# print(f"Saving Not Success. status: {status}")
|
||||
|
||||
|
||||
# print(f'pricelevel:{pricelevel}')
|
||||
|
||||
# print(ini.get_open_sales_order(open_sales_orders))
|
||||
|
||||
30
django/Invoice/templates/Invoice/prepare_data.html
Normal file
30
django/Invoice/templates/Invoice/prepare_data.html
Normal file
@ -0,0 +1,30 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load humanize %}
|
||||
{% block title %}Prepare Data{% endblock title %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<form action="" method="POST" class="card border-info-subtle p-3 mt-2" autocomplete="off" id="form">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-primary mt-2 me-2 ms-2" name="subject" value="Item Inventory">Item Inventory</button>
|
||||
<button type="submit" class="btn btn-primary mt-2 me-2 ms-2" name="subject" value="Customer List">Customer List</button>
|
||||
<div class="container-fluid card border-info p-3 mt-3">
|
||||
{% for so_no in objects %}
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="checkbox" id="inlineCheckbox{{forloop.count}}" name="selected_items" value="{{so_no}}">{{so_no}}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-2 me-2 ms-2" name="subject" value="Price Level List">Price Level List</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<datalist id='itemname'>
|
||||
{% for customer in customers %}
|
||||
<option value="{{customer|first}}" data-pk="{{customer|first}}" data-desc="{{customer|first}}" data-rate="{{customer|first}}">
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
|
||||
{% endblock body %}
|
||||
@ -12,6 +12,7 @@ urlpatterns = [
|
||||
path('selectso', views.select_so, name="select_so" ),
|
||||
path('showinv', views.choose_inv, name="choose_inv" ),
|
||||
path('saveinv', views.save_inv, name="save_inv" ),
|
||||
path('preparedata', views.prepare_data, name="prepare_data" ),
|
||||
|
||||
|
||||
path('', views.index, name="index"),
|
||||
|
||||
@ -17,6 +17,7 @@ from django.conf import settings
|
||||
from icecream import ic
|
||||
import timeit
|
||||
from decimal import Decimal
|
||||
from datetime import datetime
|
||||
|
||||
ic.configureOutput(includeContext= True)
|
||||
|
||||
@ -435,6 +436,88 @@ def save_inv(request):
|
||||
# return HttpResponse('')
|
||||
|
||||
|
||||
def prepare_data(request):
|
||||
starttime = timeit.default_timer()
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
sys.path.append('..')
|
||||
|
||||
context = {}
|
||||
FullName = ""
|
||||
if request.method=='POST':
|
||||
print(request.POST)
|
||||
subject = request.POST.get("subject", None)
|
||||
print(subject, type(subject))
|
||||
if subject and isinstance(subject, str):
|
||||
ret=False
|
||||
# import sys
|
||||
# sys.path.append('.')
|
||||
# sys.path.append('..')
|
||||
if subject.upper() == "ITEM INVENTORY":
|
||||
# try:
|
||||
print("try iteminventory import")
|
||||
from ItemInventoryQuery import ItemInventoryQuery
|
||||
|
||||
ini= ItemInventoryQuery( OwnerID ="0")
|
||||
itu = ini.connect_to_quickbooks(ini.create_QBXML())
|
||||
ret, msg = ini.status_ok(itu)
|
||||
if ret:
|
||||
print("YEAH")
|
||||
df = pd.DataFrame.from_dict(ini.get_data(itu))
|
||||
print(df)
|
||||
df.to_excel('ItemInventory\ItemInventory_FromQB.xlsx', index=False)
|
||||
modtime = datetime.fromtimestamp(os.path.getmtime('ItemInventory\ItemInventory_FromQB.xlsx'))
|
||||
print(f"modified Time:{modtime}")
|
||||
# print(ini.status_ok(itu))
|
||||
else:
|
||||
messages.warning(request, f"Saving {subject} NOT success: {msg}")
|
||||
|
||||
elif subject.upper() == "CUSTOMER LIST":
|
||||
# try:
|
||||
print("try customerlist import")
|
||||
from SO_to_Inv.CustomerQuery import CustomerQuery
|
||||
|
||||
ini=CustomerQuery()
|
||||
itu = ini.create_customerquery_QBXML()
|
||||
# print(f'itu:{itu}')
|
||||
print(f'get customer pricelevel list:{ini.get_customer_pricelevel_list(itu)}')
|
||||
ret=True
|
||||
elif subject.upper() == "PRICE LEVEL LIST":
|
||||
# try:
|
||||
print("try pricelevelquery import")
|
||||
from SO_to_Inv.PriceLevelQuery import PriceLevelQuery
|
||||
|
||||
FullName = ['t 202202', 'M 202202', 'b 202202', 'sp 202202']
|
||||
FullName = request.POST.getlist("selected_items", FullName)
|
||||
# print(f'fullname:{FullName}')
|
||||
ini = PriceLevelQuery(FullName = FullName, )
|
||||
itu = ini.connect_to_quickbooks(ini.create_QBXML())
|
||||
ret, msg = ini.get_pricelevel()
|
||||
ini= None
|
||||
itu = None
|
||||
if ret:
|
||||
print(f'Success Save Price Level : {FullName}')
|
||||
|
||||
else:
|
||||
messages.warning(request, f"Saving Not Success. status: {msg}")
|
||||
print(f"Saving Not Success. status: {msg}")
|
||||
if ret:
|
||||
messages.info(request, f"{subject} has been updated Successfully in {round(timeit.default_timer() - starttime, 4)} seconds. {FullName}")
|
||||
|
||||
else:
|
||||
messages.error(request, "not valid choice. Please choose again")
|
||||
# else:
|
||||
from SO_to_Inv.PriceLevelQuery import PriceLevelQuery
|
||||
ini = PriceLevelQuery(IncludeRetElement = ['Name'])
|
||||
|
||||
price_level_list = ini.name_list()
|
||||
print(price_level_list)
|
||||
context['objects']=price_level_list
|
||||
|
||||
print("The time difference is :", timeit.default_timer() - starttime)
|
||||
return render(request, "Invoice/prepare_data.html", context=context)
|
||||
|
||||
|
||||
def index(request):
|
||||
print("index Inv")
|
||||
context = {}
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
<li><a class="dropdown-item" href="{% url 'Invoice:index' %}">Invoice List</a></li>
|
||||
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="#">Something else here</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'Invoice:prepare_data' %}">Prepare Data</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user