Values not updating from server script

Hi,

I am working on server script Api and updating the sales invoice. The main problem was i have to update alot of sales invoices for a new custom field. to update all draft invoices i am getting all the invoices the items inside those invoices then calculating their value and updating a column in sales invoice items table.
I am facing 2 problems.2

1: values are not updating
2: if it’s saved somehow still that field is not populated inside sales invoice, i have to manually add one entry then the custom field is populated there.

Here is the code i am using.

invoices = frappe.get_all('Sales Invoice',filters={'status': 'draft','name':'SINV-4749'},fields=['name',"customer"])
uom_details = ''
#uom_str = ''

for x in invoices:
  invoiceItems = frappe.db.get_all('Sales Invoice Item',filters={'parent': x['name']},fields=['name','item_code','qty','conversion_factor','uom_details'])
  
  for z in invoiceItems:
      uom_str = ''
      doc = ''
      conversionDetails = frappe.db.get_all('UOM Conversion Detail',filters={'parent': z['item_code']},fields=['uom','conversion_factor'])
      doc = frappe.get_doc("Sales Invoice Item",z['name'])
      for y in conversionDetails:
        qty_in_nos = z['qty'] * z['conversion_factor']
        frappe.response['qty_in_nos'] = qty_in_nos
        converted_qty = qty_in_nos / y['conversion_factor'];
        uom_str = uom_str + y['uom'] + " " + str(converted_qty) + " | ";
      doc.uom_details = uom_str
      doc.save()
 
frappe.response['invoices'] = invoices
frappe.response['doc'] = doc.name
frappe.response['invoiceItems'] = invoiceItems
frappe.response['conversionDetails'] = conversionDetails
frappe.response['converted_qty'] = uom_str

Looking forward for some help

Looking forward for some help too.

@sohailamar For your first problem, are you making a GET request? You should make a POST request instead.

1 Like

@adityahase

Can i give you a hug :grinning::grinning:
That POST request actually solved all the problems,
Thanks a lot, i had just tried each possible way to this but nothing worked
Thanks again and a lot of love