fix: adding test cases
diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js
index 10e3f7d..3363d8c 100644
--- a/erpnext/crm/doctype/lead/lead.js
+++ b/erpnext/crm/doctype/lead/lead.js
@@ -43,7 +43,7 @@
if (!this.frm.is_new()) {
frappe.contacts.render_address_and_contact(this.frm);
- cur_frm.trigger('render_basic_info_html');
+ cur_frm.trigger('render_contact_day_html');
} else {
frappe.contacts.clear_address_and_contact(this.frm);
}
@@ -84,14 +84,14 @@
}
}
- render_basic_info_html() {
+ render_contact_day_html() {
if (cur_frm.doc.contact_date) {
let contact_date = frappe.datetime.obj_to_str(cur_frm.doc.contact_date)
let diff_days = frappe.datetime.get_day_diff(contact_date, frappe.datetime.get_today());
let color = diff_days > 0 ? "orange" : "green";
let message = diff_days > 0 ? __("Next Contact Date") : __("Last Contact Date");
let html = `<div class="col-xs-12">
- <span class="indicator whitespace-nowrap ${color}"><span> ${message} : ${contact_date}</span></span>
+ <span class="indicator whitespace-nowrap ${color}"><span> ${message} : ${frappe.datetime.global_date_format(contact_date)}</span></span>
</div>` ;
cur_frm.dashboard.set_headline_alert(html);
}
diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py
index 33fda89..49b682c 100644
--- a/erpnext/crm/doctype/lead/lead.py
+++ b/erpnext/crm/doctype/lead/lead.py
@@ -21,9 +21,6 @@
self.get("__onload").is_customer = customer
load_address_and_contact(self)
- def set_full_name(self):
- self.lead_name = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name]))
-
def validate(self):
self.set_full_name()
self.set_lead_name()
@@ -38,6 +35,9 @@
"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if (not cint(self.is_new())) else None,
})
+ def set_full_name(self):
+ self.lead_name = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name]))
+
def validate_email_id(self):
if self.email_id:
if not self.flags.ignore_email_validation:
diff --git a/erpnext/crm/doctype/lead/test_lead.py b/erpnext/crm/doctype/lead/test_lead.py
index d428a45..174b1c9 100644
--- a/erpnext/crm/doctype/lead/test_lead.py
+++ b/erpnext/crm/doctype/lead/test_lead.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
+from frappe.utils import random_string
import unittest
test_records = frappe.get_test_records('Lead')
@@ -32,3 +33,51 @@
customer.company = "_Test Company"
customer.customer_group = "_Test Customer Group"
customer.insert()
+
+ def test_create_lead_and_unlinking_dynamic_links(self):
+ lead_doc = make_lead(first_name = "Lorem", last_name="Ipsum")
+ lead_doc_1 = make_lead()
+ address = frappe.get_doc({
+ "doctype": "Address",
+ "address_type": "Billing",
+ "city": "Mumbai",
+ "address_line1": "Vidya Vihar West",
+ "country": "India",
+ "links": [{
+ "link_doctype": "Lead",
+ "link_name": lead_doc.name
+ }]
+ }).insert()
+
+ address_1 = frappe.get_doc({
+ "doctype": "Address",
+ "address_type": "Billing",
+ "address_line1": "Baner",
+ "city": "Pune",
+ "country": "India",
+ "links": [{
+ "link_doctype": "Lead",
+ "link_name": lead_doc.name
+ },
+ {
+ "link_doctype": "Lead",
+ "link_name": lead_doc_1.name
+ }]
+ }).insert()
+
+ lead_doc.delete()
+ address_1.reload()
+ self.assertEqual(frappe.db.exists("Lead",lead_doc.name), None)
+ self.assertEqual(len(address_1.get('links')), 1)
+
+def make_lead(**args):
+ args = frappe._dict(args)
+
+ lead_doc = frappe.get_doc({
+ "doctype": "Lead",
+ "first_name": args.first_name or "Test",
+ "last_name": args.last_name or "Lead",
+ "email_id": args.email_id or "new_lead{}@example.com".format(random_string(5)),
+ }).insert()
+
+ return lead_doc
\ No newline at end of file