Frappe Client - Insert with childs - for example BOM

Hi,

i am writing an Import Script for BOMs with FrappeClient. I read out the following data from a csv File:

  • BOM
  • BOM Items
  • BOM Operations

client = FrappeClient(“xyz”, “Administrator”, “pass_for_admin”)

//read out csv and sort the data
//so now I have the following docs

bom = {“doctype”: “BOM”, “item”: artNr, “item_name”: desc, “is_active”:0, “is_default”:0, “with_operations”:0}
client.insert(bom)
// I cannot insert the BOM here, because the BOM has no BOM Items - I get the ValidationError “Raw Materials cannot be blank”

bom_operation = {“doctype”: “BOM Operation”, “parent”:bom_name, “workstation”:workstation, “description”: desc, “time_in_mins”: zeit}
client.insert(bom_operation)
bom_item = {“doctype”: “BOM Item”, “parent”:bom_name, “item_code”:matNr, “item_name”: desc, “bom_no”: artNr, “qty”:menge}
client.insert(bom_item)

// I cannot insert the operations and items first, because I have no parent BOM ID

How can this be done ?
Can I insert the BOM without server side validation, to get an valid ID ?
I can only find the insert command in the FrappeClient.

Thank you very much
Tobias

Could u share code used for csv reading? Thx

of course, its quite simple:

import csv   
from frappeclient import FrappeClient

f = open('testfile.csv', 'rb') # opens the csv file
reader = csv.reader(f, delimiter=';', quotechar='"')
client = FrappeClient("www.xyz.de", "Administrator", "pass_for_admin")
try:
rownum = 0
for row in reader:
	if rownum == 0:
		print "doing  nothing"
	else:
		artNr = row[0]
		desc = row[1]
		ind = row[2]
		zNr = row[3]
		indK = row[4]
		gult = row[5]
                    matPos = row[6]
		matNr = row[7]
		menge = row[8]
		intM = row[9]
		folge = row[10]
		katNr = row[11]
		zeit = row[12]
		typ = row[13]
		bom = {"doctype": "BOM",  "item": artNr, "item_name": desc, "is_active":0, "is_default":0, "with_operations":0}
		client.insert(bom)
		if typ == "A":
			# Operation
			bom_operation = {"doctype": "BOM Operation",  "parent":bom_name, "workstation":katNr,  "description": desc, "time_in_mins": zeit}
			client.insert(bom_operation)
		if typ == "P":
			# Material
			bom_item = {"doctype": "BOM Item", "parent":bom_name, "item_code":matNr,  "item_name": desc, "bom_no": artNr, "qty":menge}
			client.insert(bom_item)
	rownum += 1   
finally:
	f.close()

Thx for posting :+1: