Convert to Customer Button from Enquiry

Hi. I have two doctype Enquiry and Customer.
In Enquiry I have a button “Convert to Customer” and status selection with option “Not Customer” and “Customer”. If I click “Convert to Customer” button I want to open Customer doctype with all the value of enquiry. Then If click save button after adding details in Customer form I need to change to status of enquiry form “Not Customer” to “Customer”. Plz help. If any other options to do this let me know.


You can refer implementation of Invoice/orders.

Creating a Payment Entry from that documents.


I received above error



plz check

path is wrong!

add one more fire1app in path.

fire1app.fire1app.doctype. ...

then reload and check it.

That worked. But received another error
error2

@Atheetha check this Understanding differences between frm.call() and frappe.call() you can use frm.call


now received this error
function

plz chk

@Atheetha

frappe.ui.form.on('F Enquiry',{
refresh:function(frm){
	if(frm.doc.status==='Not Customer'){

	frm.add_custom_button(_("Conver to Customer"),function(){

	frm.call("convert_to_customer").then((r)=>{
	if(r.message){
		frappe.set_value("form",'F Customer',r.message)
		})

		})

}
}
}
});
Class FEnquiry(Document):
   
   @frappe.whitelist()
   def convert_to_customer(self):
      customer=frappe.new_doc("F Customer")
      customer.customer_name=self.customer_name
      customer.phone=self.phone
      customer.email_id=self.email_id
      customer.insert()
      self.status='Customer'
      self.save()
      return customer.name


js
py
plz check this erro

Please add it.

Class FEnquiry(Document):
    pass
   
@frappe.whitelist()
def convert_to_customer(self):
  customer=frappe.new_doc("F Customer")
  customer.customer_name=self.customer_name
  customer.phone=self.phone
  customer.email_id=self.email_id
  customer.insert()
  self.status='Customer'
  self.save()
  return customer.name

its not working

Hi, I think, you need to understand the concept of frappe.call and frm.call so please check the video.

I checked that…still not woking

Documents and videos are already provided in the above post so now you have to try it yourself.

Both frappe.call and frm.call is not working.

frappe.ui.form.on('F Enquiry', {
   refresh: function (frm) {
       // Check if the form has been saved
       if (!frm.doc.__islocal) {
           // Add the custom button only if the form is not new (i.e., saved)
           frm.add_custom_button(__('Convert to Customer'), function () {
               let e_name1 = frm.doc.name1
               let new_doc = frappe.new_doc('F Customer', {
               customer_name: e_name1
           });
          
           });

above code is woking.