Skip to content

Commit

Permalink
fix: create SO from Quot for Prospect --conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihantra-Patel authored Aug 20, 2024
1 parent 33542cb commit 5d7fb1d
Showing 1 changed file with 13 additions and 52 deletions.
65 changes: 13 additions & 52 deletions erpnext/selling/doctype/quotation/quotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -502,41 +502,17 @@ def update_item(obj, target, source_parent):
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

<<<<<<< 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]
=======
if quotation.quotation_to == "Customer":
return frappe.get_doc("Customer", quotation.party_name)

# Check if a Customer already exists for the Lead or Prospect.
existing_customer = None
if quotation.quotation_to == "Lead":
Expand All @@ -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):")
+ "<br>"
)
message += "<br><ul><li>" + "</li><li>".join(mandatory_fields) + "</li></ul>"
message += _("Please create Customer from Lead {0}.").format(lead_link)

<<<<<<< HEAD
frappe.throw(message, title=_("Mandatory Missing"))
else:
return customer_name
else:
return frappe.get_doc("Customer", quotation.get("party_name"))
=======
def create_customer_from_lead(lead_name, ignore_permissions=False):
from erpnext.crm.doctype.lead.lead import _make_customer

Expand Down Expand Up @@ -605,9 +565,10 @@ def handle_mandatory_error(e, customer, lead_name):
mandatory_fields = [customer.meta.get_label(field.strip()) for field in mandatory_fields]

frappe.local.message_log = []
message = _("Could not auto create Customer due to the following missing mandatory field(s):") + "<br>"
message = (
_("Could not auto create Customer due to the following missing mandatory field(s):") + "<br>"
)
message += "<br><ul><li>" + "</li><li>".join(mandatory_fields) + "</li></ul>"
message += _("Please create Customer from Lead {0}.").format(get_link_to_form("Lead", lead_name))

frappe.throw(message, title=_("Mandatory Missing"))
>>>>>>> 2f63fae31d (fix: Create Sales Order from Quotation for Prospect)

0 comments on commit 5d7fb1d

Please sign in to comment.