i am trying update doctype but cannot update in database. when i log by (print() func). it work but nothing saved in database
func create new record in doctype history
async def createHistoryRecord(history, device):
his_record = frappe.new_doc("Histories")
his_record.device_id = device
his_record.longitude = history['longitude']
his_record.latitude = history['latitude']
his_record.save()
print("his:", his_record) // i print here and see doc update
func get data from other app
def getHistories(location):
try:
global histories
if location:
histories.append(location)
precessWebhookData()
except Exception as e:
return error_response(500, e)
func process data
def precessWebhookData():
return asyncio.run(processHistoriesData())
async def processHistoriesData():
try:
global histories
for history in histories:
print("imei:")
print(type(history['imei']))
res_device_id = await getDeviceIdFromImei(history['imei'])
print("device_id:")
print(res_device_id)
if True:
print("hieu")
print("ieu4")
last_point = history
print(last_point)
device_id = res_device_id[0]['id']
await updateDeviceLastPoint(device_id, last_point)
print("OK!")
dv = frappe.get_doc("Devices", {"imei": history["imei"]})
await createHistoryRecord(history, dv.name)
else:
return "Device not found!"
return success_response("ok")
except Exception as e:
return error_response(500, e)