mirror of
https://github.com/bcomsugi/dasaproject.git
synced 2026-01-10 06:52:36 +07:00
before touching UOM into account to calculate rate discount
This commit is contained in:
parent
9e65890d0f
commit
56594e963a
@ -204,38 +204,46 @@ class SalesOrderQuery:
|
||||
# Memo = self.create_sub_element(ET, InvoiceAdd, "Memo", self.DN['Memo'], 10 )
|
||||
disc_amount = 0
|
||||
for soidx, salesorder in enumerate(self.SalesOrderList):
|
||||
SOTxnId = salesorder['TxnID']
|
||||
# disc_amount+=int(salesorder['Disc_Amount'])
|
||||
print(f'create_invoiceadd_QBXML->SOTxnId: {SOTxnId}')
|
||||
for itemline in salesorder['SalesOrderLineRet']:
|
||||
backOrdered = str(itemline['BackOrdered'])
|
||||
# backOrdered = '1' #testing purpose
|
||||
if float(backOrdered) > 0:
|
||||
discPerPcs = float(itemline['discPerPcs'])
|
||||
discPerItem = float(backOrdered) * discPerPcs
|
||||
disc_amount += discPerItem
|
||||
InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 )
|
||||
# Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", str(itemline['DNQuantity'] ), 12 )
|
||||
Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", backOrdered, 12 )
|
||||
# UnitOfMeasure = self.create_sub_element(ET, InvoiceLineAdd, "UnitOfMeasure", str(itemline['UOM']), 12 )
|
||||
LinkToTxn = self.create_sub_element(ET, InvoiceLineAdd, "LinkToTxn", "\n ", 10 )
|
||||
TxnID = self.create_sub_element(ET, LinkToTxn, "TxnID", SOTxnId,14 )
|
||||
TxnLineID = self.create_sub_element(ET, LinkToTxn, "TxnLineID", itemline['TxnLineID'], 12 )
|
||||
# if soidx == len(self.SalesOrderList)-1: #last list then set the'400_Sales_discount'
|
||||
# print(f'disc_amount:{format(disc_amount, ".2f")}')
|
||||
# if disc_amount != 0:
|
||||
# # 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)
|
||||
if 'TxnID' in salesorder:
|
||||
SOTxnId = salesorder['TxnID']
|
||||
# disc_amount+=int(salesorder['Disc_Amount'])
|
||||
print(f'create_invoiceadd_QBXML->SOTxnId: {SOTxnId}')
|
||||
for itemline in salesorder['SalesOrderLineRet']:
|
||||
backOrdered = str(itemline['BackOrdered'])
|
||||
# backOrdered = '1' #testing purpose
|
||||
if float(backOrdered) > 0:
|
||||
discPerPcs = float(itemline['discPerPcs'])
|
||||
discPerItem = float(backOrdered) * discPerPcs
|
||||
disc_amount += discPerItem
|
||||
InvoiceLineAdd = self.create_sub_element(ET, InvoiceAdd, "InvoiceLineAdd", "\n ", 10 )
|
||||
# Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", str(itemline['DNQuantity'] ), 12 )
|
||||
Quantity = self.create_sub_element(ET, InvoiceLineAdd, "Quantity", backOrdered, 12 )
|
||||
# UnitOfMeasure = self.create_sub_element(ET, InvoiceLineAdd, "UnitOfMeasure", str(itemline['UOM']), 12 )
|
||||
LinkToTxn = self.create_sub_element(ET, InvoiceLineAdd, "LinkToTxn", "\n ", 10 )
|
||||
TxnID = self.create_sub_element(ET, LinkToTxn, "TxnID", SOTxnId,14 )
|
||||
TxnLineID = self.create_sub_element(ET, LinkToTxn, "TxnLineID", itemline['TxnLineID'], 12 )
|
||||
# if soidx == len(self.SalesOrderList)-1: #last list then set the'400_Sales_discount'
|
||||
# print(f'disc_amount:{format(disc_amount, ".2f")}')
|
||||
# if disc_amount != 0:
|
||||
# # 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)
|
||||
|
||||
if salesorder['Disc_Amount']!=0: # disc_amount != 0:
|
||||
# disc_amount=format(disc_amount, ".2f")
|
||||
if salesorder['Disc_Amount']!=0: # disc_amount != 0:
|
||||
# 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 )
|
||||
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)
|
||||
ItemFullName = self.create_sub_element(ET, ItemRef, "FullName", salesorder['other_itemFullName'], 12)
|
||||
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")
|
||||
|
||||
@ -270,7 +278,7 @@ class SalesOrderQuery:
|
||||
sessionManager.EndSession(ticket) # Close the company file
|
||||
sessionManager.CloseConnection() # Close the connection
|
||||
# print (f'response_string:{response_string}')
|
||||
return response_string
|
||||
return self.pprintXml(response_string)
|
||||
|
||||
def __str__(self, *args) -> str:
|
||||
# return str(self._get_datarow(self.connect_to_quickbooks(self.create_QBXML())))
|
||||
|
||||
@ -172,12 +172,30 @@ def save_inv(request):
|
||||
data = dict(request.POST)
|
||||
del data['csrfmiddlewaretoken']
|
||||
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:
|
||||
del data['other_items']
|
||||
if 'other_qty' in data:
|
||||
del data['other_qty']
|
||||
if 'other_rate' in data:
|
||||
del data['other_rate']
|
||||
if 'selected_items' in data:
|
||||
del data['selected_items']
|
||||
print(f'others:{others}')
|
||||
|
||||
# print(f"datadict:{data}")
|
||||
try:
|
||||
@ -259,24 +277,26 @@ def save_inv(request):
|
||||
break
|
||||
break
|
||||
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
|
||||
data_to_save.append(dict_)
|
||||
print('save the last dict')
|
||||
else:
|
||||
print('last data to save == dict')
|
||||
for _ in others:
|
||||
data_to_save.append(_)
|
||||
print(f'Final List:{data_to_save}')
|
||||
print("")
|
||||
# print(itu)
|
||||
context['objects'] = itu
|
||||
context['customer_fullname'] = customer_fullname
|
||||
print(context['objects'])
|
||||
# print(context['objects'])
|
||||
print("Invoiceaddqbxml:")
|
||||
invoiceaddQBXML=ini.create_invoiceadd_QBXML(data_to_save)
|
||||
|
||||
print(invoiceaddQBXML)
|
||||
result=None
|
||||
# result = ini.connect_to_quickbooks(ini.create_invoiceadd_QBXML())
|
||||
result = ini.connect_to_quickbooks(ini.create_invoiceadd_QBXML())
|
||||
print("RESULT:")
|
||||
print(result)
|
||||
return render(request, "Invoice/so_details_form.html", context)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user