Hello everyone,
So I would like to link submissions obtained from KoboCollect ( an extension of ODK) to ERPNext. I have successfully implemented the following field types;
I. Integer
II. Text
III. Date
IV. Time
V. Select one
VI. File
I achieved that using the following code: Is there a better way to do this?
def iccm():
try:
response = requests.get(
'https://kobo.humanitarianresponse.info/api/v2/assets/anU4kNVU2NKfVukrNPsWe3/data/?format=json')
jsonObject = response.json()
for val in jsonObject['results']:
geo = val['Geolocation'].split(' ')
geo_link = 'https://www.openstreetmap.org/#map=18/' + \
geo[0] + '/' + geo[1]
geo = geo[0] + ' '+geo[1]
sel_o = re.sub('_', ' ', val['Select_One'])
sel_m = re.sub('_', ' ', val['Select_Many'])
file_base_url = 'https://kc.humanitarianresponse.info/media/small?media_file='
row = {
'doctype': 'iccmassessment',
'f_id': val['_id'],
'f_name': val['Name'],
'f_number': val['Number'],
'f_select_one': sel_o,
'f_select_many': sel_m,
'f_geolocation': geo_link,
'f_date': val['Date'],
'f_time': frappe.format_value(val['Time'], {'fieldtype': 'Time'}),
'f_file': val['File'],
'f_file_url': file_base_url + val['_attachments'][0]['filename'],
}
doc = frappe.get_doc(row)
doc.insert()
frappe.db.commit()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}')
But now I have two challenges:
I. How can I link the select_many to the ERPNext Table-multiselect field (given that the actual data is stored in a child table)? The select many field from KoboCollect comes in as … string 1 string 2 string 3 …
II. I cannot create dashboard charts on custom-created child tables (the parent doctype does not show up). I can do so on stand ones like Expense Claim Detail etc. but not on ones I create myself. Thank you in advance for your help.