Create quotation through script

I want to create quotation through script. In general, How can we insert data into a doctype through script along with the child table data.

Check following code to create record

https://github.com/frappe/erpnext/blob/develop/erpnext/accounts/doctype/asset/asset.py#L198-L211

Thanks for your reply. It was helpful.

In the above part,
pi.append() is used to add data in the child table. But it is adding only one entry. How can we add multiple rows in the child table?

I wrote this code but it’s not working.

for i in item_code:   # item_code is an array having multiple item_codes
       pi.append("items", {
		"item_code": i,
		"is_fixed_asset": 1,
		"asset": asset,
		"expense_account": get_fixed_asset_account(asset),
		"qty": 1,
		"price_list_rate": gross_purchase_amount,
		"rate": gross_purchase_amount
	})

I guess it is done in some other way.

what is the result of item_code?

on printing item_code , the output was:
["IT001","IT002"]

seems like okay. Any error or traceback

I got it.

Actually the problem was that the variable item_code was having the value as an array i.e the value of it was the array “[“IT001”,“IT002”]” .

The solution was to encode the array as json at frontend before sending to the backend and decode it in the python script and then use it.

Facing a new problem. I am unable to create Quotation through script for a Customer say “Robert Lewandowski”.

But for the same Customer I can create a quotation via desk.

Here is the script:

@frappe.whitelist(allow_guest=True)
def quotation_add(qty, itm_code):
	cstmr_name = frappe.db.get_value("User",frappe.session.user,"full_name")
	qa = frappe.new_doc("Quotation")
	qa.quotation_to = "Customer"
	qa.customer = cstmr_name
	res = json.loads(qty)
	i_codes = json.loads(itm_code)
	print "RES: ",res," TYPE: ",type(res)
	j = 0
	for i in i_codes:
		qa.append("items",{
			"item_code": i,
			"description": "This is some description",
			"qty": res[j],
			"uom": "Nos",
			"conversion_factor": 12
			})
		j = j+1
	qa.set_missing_values()
	qa.insert()
	qa.submit()
	return qty

It’s validation from party.py file.

use ignore_permissions flag

qa.flags.ignore_permissions = True
qa.submit()