diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index f48f8a88712..bf2c166069f 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -347,8 +347,8 @@ def make_sales_order(source_name: str, target_doc=None):
return _make_sales_order(source_name, target_doc)
-def _make_sales_order(source_name, target_doc=None, customer_group=None, ignore_permissions=False):
- customer = _make_customer(source_name, ignore_permissions, customer_group)
+def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
+ customer = _make_customer(source_name, ignore_permissions)
ordered_items = frappe._dict(
frappe.db.get_all(
"Sales Order Item",
@@ -502,41 +502,17 @@ def _make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
return doclist
-def _make_customer(source_name, ignore_permissions=False, customer_group=None):
+def _make_customer(source_name, ignore_permissions=False):
quotation = frappe.db.get_value(
- "Quotation", source_name, ["order_type", "party_name", "customer_name"], as_dict=1
+ "Quotation",
+ source_name,
+ ["order_type", "quotation_to", "party_name", "customer_name"],
+ as_dict=1,
)
- if quotation and quotation.get("party_name"):
- if not frappe.db.exists("Customer", quotation.get("party_name")):
- lead_name = quotation.get("party_name")
- customer_name = frappe.db.get_value(
- "Customer", {"lead_name": lead_name}, ["name", "customer_name"], as_dict=True
- )
- if not customer_name:
- from erpnext.crm.doctype.lead.lead import _make_customer
+ if quotation.quotation_to == "Customer":
+ return frappe.get_doc("Customer", quotation.party_name)
-<<<<<<< HEAD
- customer_doclist = _make_customer(lead_name, ignore_permissions=ignore_permissions)
- customer = frappe.get_doc(customer_doclist)
- customer.flags.ignore_permissions = ignore_permissions
- customer.customer_group = customer_group
-
- try:
- customer.insert()
- return customer
- except frappe.NameError:
- if frappe.defaults.get_global_default("cust_master_name") == "Customer Name":
- customer.run_method("autoname")
- customer.name += "-" + lead_name
- customer.insert()
- return customer
- else:
- raise
- except frappe.MandatoryError as e:
- mandatory_fields = e.args[0].split(":")[1].split(",")
- mandatory_fields = [customer.meta.get_label(field.strip()) for field in mandatory_fields]
-=======
# Check if a Customer already exists for the Lead or Prospect.
existing_customer = None
if quotation.quotation_to == "Lead":
@@ -554,24 +530,8 @@ def _make_customer(source_name, ignore_permissions=False, customer_group=None):
return create_customer_from_prospect(quotation.party_name, ignore_permissions=ignore_permissions)
return None
->>>>>>> 2f63fae31d (fix: Create Sales Order from Quotation for Prospect)
- frappe.local.message_log = []
- lead_link = frappe.utils.get_link_to_form("Lead", lead_name)
- message = (
- _("Could not auto create Customer due to the following missing mandatory field(s):")
- + "
"
- )
- message += "