before touching UOM into account to calculate rate discount

This commit is contained in:
bcomsugi 2023-12-29 06:59:31 +07:00
parent 9e65890d0f
commit 56594e963a
2 changed files with 63 additions and 35 deletions

View File

@ -204,38 +204,46 @@ class SalesOrderQuery:
# Memo = self.create_sub_element(ET, InvoiceAdd, "Memo", self.DN['Memo'], 10 ) # Memo = self.create_sub_element(ET, InvoiceAdd, "Memo", self.DN['Memo'], 10 )
disc_amount = 0 disc_amount = 0
for soidx, salesorder in enumerate(self.SalesOrderList): for soidx, salesorder in enumerate(self.SalesOrderList):
SOTxnId = salesorder['TxnID'] if 'TxnID' in salesorder:
# disc_amount+=int(salesorder['Disc_Amount']) SOTxnId = salesorder['TxnID']
print(f'create_invoiceadd_QBXML->SOTxnId: {SOTxnId}') # disc_amount+=int(salesorder['Disc_Amount'])
for itemline in salesorder['SalesOrderLineRet']: print(f'create_invoiceadd_QBXML->SOTxnId: {SOTxnId}')
backOrdered = str(itemline['BackOrdered']) for itemline in salesorder['SalesOrderLineRet']:
# backOrdered = '1' #testing purpose backOrdered = str(itemline['BackOrdered'])
if float(backOrdered) > 0: # backOrdered = '1' #testing purpose
discPerPcs = float(itemline['discPerPcs']) if float(backOrdered) > 0:
discPerItem = float(backOrdered) * discPerPcs discPerPcs = float(itemline['discPerPcs'])
disc_amount += discPerItem discPerItem = float(backOrdered) * discPerPcs
InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 ) disc_amount += discPerItem
# Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", str(itemline['DNQuantity'] ), 12 ) InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 )
Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", backOrdered, 12 ) # Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", str(itemline['DNQuantity'] ), 12 )
# UnitOfMeasure = self.create_sub_element(ET, InvoiceLineAdd, "UnitOfMeasure", str(itemline['UOM']), 12 ) Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", backOrdered, 12 )
LinkToTxn = self.create_sub_element(ET, InvoiceLineAdd, "LinkToTxn", "\n ", 10 ) # UnitOfMeasure = self.create_sub_element(ET, InvoiceLineAdd, "UnitOfMeasure", str(itemline['UOM']), 12 )
TxnID = self.create_sub_element(ET, LinkToTxn, "TxnID", SOTxnId,14 ) LinkToTxn = self.create_sub_element(ET, InvoiceLineAdd, "LinkToTxn", "\n ", 10 )
TxnLineID = self.create_sub_element(ET, LinkToTxn, "TxnLineID", itemline['TxnLineID'], 12 ) TxnID = self.create_sub_element(ET, LinkToTxn, "TxnID", SOTxnId,14 )
# if soidx == len(self.SalesOrderList)-1: #last list then set the'400_Sales_discount' TxnLineID = self.create_sub_element(ET, LinkToTxn, "TxnLineID", itemline['TxnLineID'], 12 )
# print(f'disc_amount:{format(disc_amount, ".2f")}') # if soidx == len(self.SalesOrderList)-1: #last list then set the'400_Sales_discount'
# if disc_amount != 0: # print(f'disc_amount:{format(disc_amount, ".2f")}')
# # disc_amount=format(disc_amount, ".2f") # if disc_amount != 0:
# InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 ) # # disc_amount=format(disc_amount, ".2f")
# ItemRef = self.create_sub_element(ET, InvoiceLineAdd, "ItemRef", "\n ", 12) # InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 )
# ItemFullName = self.create_sub_element(ET, ItemRef, "FullName", "400_Sales Discount", 12) # ItemRef = self.create_sub_element(ET, InvoiceLineAdd, "ItemRef", "\n ", 12)
# ItemRate = self.create_sub_element(ET, InvoiceLineAdd, "Rate", str(disc_amount), 10) # ItemFullName = self.create_sub_element(ET, ItemRef, "FullName", "400_Sales Discount", 12)
# ItemRate = self.create_sub_element(ET, InvoiceLineAdd, "Rate", str(disc_amount), 10)
if salesorder['Disc_Amount']!=0: # disc_amount != 0: if salesorder['Disc_Amount']!=0: # disc_amount != 0:
# disc_amount=format(disc_amount, ".2f") # disc_amount=format(disc_amount, ".2f")
InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 )
ItemRef = self.create_sub_element(ET, InvoiceLineAdd, "ItemRef", "\n ", 12)
ItemFullName = self.create_sub_element(ET, ItemRef, "FullName", "400_Sales Discount", 12)
ItemRate = self.create_sub_element(ET, InvoiceLineAdd, "Rate", str(disc_amount), 10)
elif 'other_itemFullName' in salesorder and 'other_qty' in salesorder and 'other_rate' in salesorder:
pass
InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 ) InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 )
ItemRef = self.create_sub_element(ET, InvoiceLineAdd, "ItemRef", "\n ", 12) ItemRef = self.create_sub_element(ET, InvoiceLineAdd, "ItemRef", "\n ", 12)
ItemFullName = self.create_sub_element(ET, ItemRef, "FullName", "400_Sales Discount", 12) ItemFullName = self.create_sub_element(ET, ItemRef, "FullName", salesorder['other_itemFullName'], 12)
ItemRate = self.create_sub_element(ET, InvoiceLineAdd, "Rate", str(disc_amount), 10) Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", str(salesorder['other_qty']), 12 )
ItemRate = self.create_sub_element(ET, InvoiceLineAdd, "Rate", str(salesorder['other_rate']), 10)
mydata = ET.tostring(root, encoding = "unicode") mydata = ET.tostring(root, encoding = "unicode")
@ -270,7 +278,7 @@ class SalesOrderQuery:
sessionManager.EndSession(ticket) # Close the company file sessionManager.EndSession(ticket) # Close the company file
sessionManager.CloseConnection() # Close the connection sessionManager.CloseConnection() # Close the connection
# print (f'response_string:{response_string}') # print (f'response_string:{response_string}')
return response_string return self.pprintXml(response_string)
def __str__(self, *args) -> str: def __str__(self, *args) -> str:
# return str(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML()))) # return str(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML())))

View File

@ -172,12 +172,30 @@ def save_inv(request):
data = dict(request.POST) data = dict(request.POST)
del data['csrfmiddlewaretoken'] del data['csrfmiddlewaretoken']
del data['customer_fullname'] del data['customer_fullname']
### get others items into list of dict ###
others=[]
otherFullName = {'peti': 'PETI', 'expedition':'Sales_Ekspedisi'}
if 'selected_items' in data:
for _ in data['selected_items']:
if _ in data['other_items']:
data_idx = data['other_items'].index(_)
print(f'selected item:{_} is in index:{data_idx}')
other_qty = int(data['other_qty'][data_idx])
other_rate = float(data['other_rate'][data_idx])
if other_qty<=0:
other_qty = 1
if other_rate <= 0:
continue
temp_ = {'other_item':data['other_items'][data_idx], 'other_itemFullName': otherFullName[data['other_items'][data_idx]], 'other_qty':other_qty, 'other_rate': other_rate}
others.append(temp_)
del data['selected_items']
if 'other_items' in data: if 'other_items' in data:
del data['other_items'] del data['other_items']
if 'other_qty' in data:
del data['other_qty'] del data['other_qty']
if 'other_rate' in data:
del data['other_rate'] del data['other_rate']
if 'selected_items' in data: print(f'others:{others}')
del data['selected_items']
# print(f"datadict:{data}") # print(f"datadict:{data}")
try: try:
@ -259,24 +277,26 @@ def save_inv(request):
break break
break break
print(f'last:{dict_}') print(f'last:{dict_}')
if dict_ != data_to_save[-1]: if dict_ != data_to_save[-1]: #append the last dict_
dict_['Disc_Amount']=disc_amount dict_['Disc_Amount']=disc_amount
data_to_save.append(dict_) data_to_save.append(dict_)
print('save the last dict') print('save the last dict')
else: else:
print('last data to save == dict') print('last data to save == dict')
for _ in others:
data_to_save.append(_)
print(f'Final List:{data_to_save}') print(f'Final List:{data_to_save}')
print("") print("")
# print(itu) # print(itu)
context['objects'] = itu context['objects'] = itu
context['customer_fullname'] = customer_fullname context['customer_fullname'] = customer_fullname
print(context['objects']) # print(context['objects'])
print("Invoiceaddqbxml:") print("Invoiceaddqbxml:")
invoiceaddQBXML=ini.create_invoiceadd_QBXML(data_to_save) invoiceaddQBXML=ini.create_invoiceadd_QBXML(data_to_save)
print(invoiceaddQBXML) print(invoiceaddQBXML)
result=None result=None
# result = ini.connect_to_quickbooks(ini.create_invoiceadd_QBXML()) result = ini.connect_to_quickbooks(ini.create_invoiceadd_QBXML())
print("RESULT:") print("RESULT:")
print(result) print(result)
return render(request, "Invoice/so_details_form.html", context) return render(request, "Invoice/so_details_form.html", context)