mirror of
https://github.com/bcomsugi/dasaproject.git
synced 2026-01-09 15:32:38 +07:00
add change to notes and minor change in server.py
This commit is contained in:
parent
db5a2b9105
commit
8b5f87619c
@ -95,8 +95,10 @@ class baseQBQuery:
|
|||||||
ticket = sessionManager.BeginSession("", 2)
|
ticket = sessionManager.BeginSession("", 2)
|
||||||
|
|
||||||
# Send query and receive response
|
# Send query and receive response
|
||||||
self.response_string = sessionManager.ProcessRequest(ticket, self.QBXML)
|
if not qbxml_query:
|
||||||
|
self.response_string = sessionManager.ProcessRequest(ticket, self.QBXML)
|
||||||
|
else:
|
||||||
|
self.response_string = sessionManager.ProcessRequest(ticket, qbxml_query)
|
||||||
# Disconnect from Quickbooks
|
# Disconnect from Quickbooks
|
||||||
sessionManager.EndSession(ticket) # Close the company file
|
sessionManager.EndSession(ticket) # Close the company file
|
||||||
sessionManager.CloseConnection() # Close the connection
|
sessionManager.CloseConnection() # Close the connection
|
||||||
@ -107,7 +109,9 @@ class baseQBQuery:
|
|||||||
self.response_string = xml.toprettyxml()
|
self.response_string = xml.toprettyxml()
|
||||||
# print(f'{self.response_string = }')
|
# print(f'{self.response_string = }')
|
||||||
|
|
||||||
self.statusOk = self.isDataOK()
|
if not qbxml_query:
|
||||||
|
self.statusOk = self.isDataOK()
|
||||||
|
|
||||||
return self.statusOk
|
return self.statusOk
|
||||||
return self.response_string
|
return self.response_string
|
||||||
|
|
||||||
|
|||||||
137
change_to_notes.py
Normal file
137
change_to_notes.py
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
from QBClass.QBClasses import CustomerQuery
|
||||||
|
import pprint
|
||||||
|
import json
|
||||||
|
import xmltodict
|
||||||
|
|
||||||
|
# cust = CustomerQuery(MaxReturned = 90, OwnerID = 0, IncludeRetElement = ['ListID', 'Name', 'FullName', 'EditSequence', 'CompanyName', 'ShipAddress','ShipToAddress', 'CreditLimit', 'PriceLevelRef', 'AdditionalNotesRet', 'Notes', 'DataExtRet'])
|
||||||
|
cust = CustomerQuery(OwnerID = 0, IncludeRetElement = ['ListID', 'Name', 'FullName', 'EditSequence', 'CompanyName', 'ShipAddress','ShipToAddress', 'CreditLimit', 'PriceLevelRef', 'AdditionalNotesRet', 'Notes', 'DataExtRet'])
|
||||||
|
# pprint.pprint(cust.all(), sort_dicts=False)
|
||||||
|
# print(cust.response_string)
|
||||||
|
print(cust.all())
|
||||||
|
print(type(cust.all()))
|
||||||
|
# pprint.pprint(cust.filter('DataExtRet').all(), sort_dicts=False)
|
||||||
|
beeer = json.loads(json.dumps(cust.all()))
|
||||||
|
pprint.pprint( beeer , sort_dicts=False)
|
||||||
|
|
||||||
|
if not isinstance(cust.all(), list):
|
||||||
|
customers = [cust.all()]
|
||||||
|
else:
|
||||||
|
customers = cust.all()
|
||||||
|
|
||||||
|
notes_create = []
|
||||||
|
notes_update = []
|
||||||
|
for customer in customers:
|
||||||
|
DER_note = {}
|
||||||
|
if 'DataExtRet' in customer:
|
||||||
|
# notes = {customer['ListID']:[]}
|
||||||
|
|
||||||
|
if not isinstance(customer['DataExtRet'], list):
|
||||||
|
customer['DataExtRet'] = [customer['DataExtRet']]
|
||||||
|
for DER in customer['DataExtRet']:
|
||||||
|
Der_name = DER['DataExtName']
|
||||||
|
Der_value = DER['DataExtValue']
|
||||||
|
DER_note[Der_name] = Der_value
|
||||||
|
print(f'{DER_note = }')
|
||||||
|
note_json = json.dumps(DER_note, ensure_ascii=False)
|
||||||
|
print(note_json)
|
||||||
|
is_new = True
|
||||||
|
noteid_counter = 0
|
||||||
|
if DER_note and 'AdditionalNotesRet' in customer:
|
||||||
|
print(f"{customer['AdditionalNotesRet'] = }")
|
||||||
|
# print(f"dernote and additional note ret {customer['FullName']}")
|
||||||
|
if not isinstance(customer['AdditionalNotesRet'], list):
|
||||||
|
customer['AdditionalNotesRet'] = [customer['AdditionalNotesRet']]
|
||||||
|
print(f"{customer['FullName'] = } {customer['AdditionalNotesRet'] = }")
|
||||||
|
for cur_note in customer['AdditionalNotesRet']:
|
||||||
|
cur_noteid = cur_note['NoteID']
|
||||||
|
if float(noteid_counter)<=float(cur_noteid):
|
||||||
|
noteid_counter = str(int(float(cur_noteid)+1))
|
||||||
|
cur_date = cur_note['Date']
|
||||||
|
cur_note_json = cur_note['Note']
|
||||||
|
|
||||||
|
try:
|
||||||
|
cur_note = json.loads(cur_note_json)
|
||||||
|
except Exception as e:
|
||||||
|
continue
|
||||||
|
print(f'{cur_noteid = } {cur_note_json = } {len(cur_note) = } {len(DER_note) = }')
|
||||||
|
if len(cur_note)!=len(DER_note): #then update notes
|
||||||
|
# note_update = note_json
|
||||||
|
print('len(cur_note)!=len(DER_note)')
|
||||||
|
notes_create.append({customer['ListID']:{'ListID':customer['ListID'], 'EditSequence':customer['EditSequence'], 'AdditionalNotesMod':{'NoteID':int(float(cur_noteid)), 'Note':note_json}}})
|
||||||
|
is_new=False
|
||||||
|
break
|
||||||
|
if json.dumps(cur_note)!=note_json:
|
||||||
|
print('cur_note!=note_json')
|
||||||
|
# print(cur_note)
|
||||||
|
# print(json.dumps(cur_note))
|
||||||
|
# print(note_json)
|
||||||
|
notes_create.append({customer['ListID']:{'ListID':customer['ListID'], 'EditSequence':customer['EditSequence'], 'AdditionalNotesMod':{'NoteID':int(float(cur_noteid)), 'Note':note_json}}})
|
||||||
|
is_new = False
|
||||||
|
break
|
||||||
|
is_new=False
|
||||||
|
if is_new:
|
||||||
|
print('is_new')
|
||||||
|
notes_create.append({customer['ListID']:{'ListID':customer['ListID'], 'EditSequence':customer['EditSequence'], 'AdditionalNotesMod':{'NoteID':int(float(noteid_counter)), 'Note':note_json}}})
|
||||||
|
elif DER_note and 'AdditionalNotesRet' not in customer:
|
||||||
|
print("DER_note and 'AdditionalNotesRet' not in customer")
|
||||||
|
notes_create.append({customer['ListID']:{'ListID':customer['ListID'], 'EditSequence':customer['EditSequence'], 'Notes':note_json}})
|
||||||
|
# if is_new:
|
||||||
|
|
||||||
|
|
||||||
|
print(f'{notes_create=} {len(notes_create) = }')
|
||||||
|
if notes_create:
|
||||||
|
customer_mods = []
|
||||||
|
total_notes_create = len(notes_create)
|
||||||
|
max_transaction_len = len(notes_create)
|
||||||
|
repeat = int(total_notes_create/max_transaction_len)
|
||||||
|
leftover = total_notes_create%max_transaction_len
|
||||||
|
cannot_update = []
|
||||||
|
for x in range(repeat):
|
||||||
|
xml_body=""
|
||||||
|
customer_mods = []
|
||||||
|
print(f'repeat ke : {x=} {x*max_transaction_len=} {x*max_transaction_len+max_transaction_len=}')
|
||||||
|
for idx, notecreate in enumerate(notes_create[x*max_transaction_len:x*max_transaction_len+max_transaction_len]):
|
||||||
|
# print(list(notecreate.keys())[0])
|
||||||
|
print(f'{idx = }')
|
||||||
|
xml = xmltodict.unparse(notecreate, pretty=True)
|
||||||
|
# print(xml)
|
||||||
|
# print(xml.split('\n')[2:-1])
|
||||||
|
joined_xml = "".join(xml.split('\n')[2:-1])
|
||||||
|
# print(f'{joined_xml = }')
|
||||||
|
# pprint.pprint(joined_xml, sort_dicts=False)
|
||||||
|
# print(f'{joined_xml = }')
|
||||||
|
single_customermod = f'<CustomerModRq><CustomerMod>\n {joined_xml}\n</CustomerMod></CustomerModRq>'
|
||||||
|
customer_mods.append(single_customermod)
|
||||||
|
# print(f'<CustomerMod>\n {joined_xml}\n<\CustomerMod>')
|
||||||
|
|
||||||
|
# for cur_item in cur_note:
|
||||||
|
# print(f'{customer_mods = }')
|
||||||
|
xml_body = '\n'.join(customer_mods)
|
||||||
|
xml_body = "" + xml_body + ""
|
||||||
|
# print(f'{xml_body = }')
|
||||||
|
xml_header = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<?qbxml version="13.0"?>
|
||||||
|
<QBXML>
|
||||||
|
<QBXMLMsgsRq onError="stopOnError">
|
||||||
|
|
||||||
|
"""
|
||||||
|
xml_footer = """
|
||||||
|
|
||||||
|
</QBXMLMsgsRq>
|
||||||
|
</QBXML>"""
|
||||||
|
qbxml = xml_header+xml_body+xml_footer
|
||||||
|
# print(f'{qbxml = }')
|
||||||
|
print(qbxml)
|
||||||
|
try:
|
||||||
|
cust.connect_to_quickbooks(qbxml)
|
||||||
|
except Exception as e:
|
||||||
|
cannot_update.append(xml_body)
|
||||||
|
|
||||||
|
# print(cust.response_string)
|
||||||
|
print(f'{cannot_update = }, {len(cannot_update) = }')
|
||||||
|
no_notes=[]
|
||||||
|
for x in cust.all():
|
||||||
|
if 'Notes' not in x:
|
||||||
|
no_notes.append(x['FullName'])
|
||||||
|
|
||||||
|
print(f'{no_notes = }, {len(no_notes) = }')
|
||||||
5
exim.py
5
exim.py
@ -570,7 +570,8 @@ if __name__=='__main__':
|
|||||||
|
|
||||||
print(fromtxndate)
|
print(fromtxndate)
|
||||||
readydata = main(fromtxndate, totxndate, 2)
|
readydata = main(fromtxndate, totxndate, 2)
|
||||||
# print(readydata)
|
# pprint(readydata, sort_dicts=False)
|
||||||
|
|
||||||
IA = InvoiceAdd(*readydata, debug=False)
|
IA = InvoiceAdd(*readydata, debug=True)
|
||||||
|
print(IA.create_QBXML())
|
||||||
# IA.all()
|
# IA.all()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user