ERPnext have lot of linked doctypes for eg, we can create supplier quotation from RFQ, quotation from supplier quotation and etc, in which there is a button on top of it to create the document.
When we do that, the fields having the same name gets automatically filled. So I want to know how can I do this for my custom doctypes, in which I also can add a button for example at the top to create a new doctype from some doctype with same fields getting automatically populated.
@bahaou
I have one doctype - RFQ and other doctype - JOB
Basically RFQ gets converted to JOB after all data is fed.
Now I want a button on top of RFQ which says, Create JOB which will open the JOB docform with data from RFQ doctype prepopulated. There are some child tables in RFQ which are also present in JOB so that also needs to be populated.
So I need to copy child table fields as well as normal table fields.
import frappe
@frappe.whitelist()
def function(source_name,target_doc=None):
rfq=frappe.get_doc("RFQ",source_name)
job=frappe.new_doc("JOB")
#to populate a normal field just use job.field=rfq.field_from_rfq
#for a table do this
for i in rfq.table_examle:
new_row=job.append("child_table_name_in_job",{})
new_row.field=i.example_field
# what I did is just eterate the first child table of rfq and accordingly add a new row in the job table and for each row you gonna populate it's own fields .
#if child tables are the same you can just populate the entire table .
return job
I don’t know about documentations . open_mapped_doc wil just redirect to a new doctype you built using python code above . which exactly what you need . and this is exactly how standard create buttons work in erpnext .
Now I want to know one more thing
Can I pass any custom arguments as well?
I actually have a child table through which I want to create a new document. I have a button in my child document so whenever I click on that button, that particular row I want to create a new document out of it of other doctype.
That custom argument will help me know which particular row was clicked so that is required.