Skip to content

Commit ecad553

Browse files
Abdeali099mergify[bot]
authored andcommitted
fix: Add translation for showing mandatory fields in error msg
(cherry picked from commit f42ec6a) # Conflicts: # erpnext/selling/doctype/quotation/quotation.py
1 parent 627a50e commit ecad553

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

erpnext/selling/doctype/quotation/quotation.py

+44
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,52 @@ def _make_customer(source_name, ignore_permissions=False):
466466
message += "<br><ul><li>" + "</li><li>".join(mandatory_fields) + "</li></ul>"
467467
message += _("Please create Customer from Lead {0}.").format(lead_link)
468468

469+
<<<<<<< HEAD
469470
frappe.throw(message, title=_("Mandatory Missing"))
470471
else:
471472
return customer_name
472473
else:
473474
return frappe.get_doc("Customer", quotation.get("party_name"))
475+
=======
476+
return None
477+
478+
479+
def create_customer_from_lead(lead_name, ignore_permissions=False):
480+
from erpnext.crm.doctype.lead.lead import _make_customer
481+
482+
customer = _make_customer(lead_name, ignore_permissions=ignore_permissions)
483+
customer.flags.ignore_permissions = ignore_permissions
484+
485+
try:
486+
customer.insert()
487+
return customer
488+
except frappe.MandatoryError as e:
489+
handle_mandatory_error(e, customer, lead_name)
490+
491+
492+
def create_customer_from_prospect(prospect_name, ignore_permissions=False):
493+
from erpnext.crm.doctype.prospect.prospect import make_customer as make_customer_from_prospect
494+
495+
customer = make_customer_from_prospect(prospect_name)
496+
customer.flags.ignore_permissions = ignore_permissions
497+
498+
try:
499+
customer.insert()
500+
return customer
501+
except frappe.MandatoryError as e:
502+
handle_mandatory_error(e, customer, prospect_name)
503+
504+
505+
def handle_mandatory_error(e, customer, lead_name):
506+
from frappe.utils import get_link_to_form
507+
508+
mandatory_fields = e.args[0].split(":")[1].split(",")
509+
mandatory_fields = [_(customer.meta.get_label(field.strip())) for field in mandatory_fields]
510+
511+
frappe.local.message_log = []
512+
message = _("Could not auto create Customer due to the following missing mandatory field(s):") + "<br>"
513+
message += "<br><ul><li>" + "</li><li>".join(mandatory_fields) + "</li></ul>"
514+
message += _("Please create Customer from Lead {0}.").format(get_link_to_form("Lead", lead_name))
515+
516+
frappe.throw(message, title=_("Mandatory Missing"))
517+
>>>>>>> f42ec6a124 (fix: Add translation for showing mandatory fields in error msg)

0 commit comments

Comments
 (0)