I have to restrict creation of customer against opportunity as one customer for one opportunity. By default multiple customers can be created against an opportunity/lead, want to avoid it.
if not frappe.db.exists(“Customer”, {“customer_name”: doc.customer_name}):
customer = frappe.new_doc(“Customer”)
customer.customer_name = doc.customer_name
customer.territory = doc.territory
customer.lead_name = doc.party_name
customer.opportunity_name = doc.opportunity
customer.customer_primary_address = doc.customer_address
customer.insert()
frappe.msgprint(“Customer Created!”)
else:
pass
frappe.msgprint(f"Customer {doc.customer_name} with Opportunity "{doc.opportunity}" Already Exists")
i have used this code, but didnt get any solution.