Auto create new document


I have a custom doctype “offers” which links to “Quotation Item”. I want to auto create the “offers” everytime the user inputs an item.

I think this can be done on the server side by adding a create function at on_submit function in ? How can I ensure the relation always stays 1:1.

ie for every item in quotation one unique offers is created.

Yeah you can do that, but also add it for all sales transactions (you can skip quotation)

I would like to know how I can link the newly created doctype to the link field? In my case

offers = frappe.get_doc({"doctype":"offers", "description": "test"})

I need to link the newly created doctype to quotation item. I already have a link field in Quotation Item table. Do I simply assign the following?

self.offers_field = offers

Can’t understand unless you share your full code.

Hi ,

“Quotation Item” table contains link to “Offers” a custom Doctype

offer is the fieldname given in Quotation Item to link with Offers doctype

def on_update(self):
                 for d in self.get('quotation_details'):
                        if not d.offer: 
                                n_offers = frappe.get_doc({"doctype":"Offers"})
                                frappe.db.set_value(d.doctype, d.offer, "offer", n_offers)

The above code creates my custom doc Offers. I need to link it to Quotation Item. The last line works?

Should just be

d.offer = n_offers


Hi ty,

I tried print(n_offers) so I can see the object returned in console and assign correctly. But it doesnt work. I am in developer mode too.

Please check screenshot.

I still havent figured this basic code. Would appreciate some help. I tried so as to understand the returned object


Which returns in the shell the follow

<erpnext.selling.doctype.offers.offers.Offers object at 0x7f10e7751e50>

I still am not able to assign the newly created document to the Quotation Item.

Use the following

d.offer =
1 Like

Ty! that did it