fix: adding test cases
This commit is contained in:
parent
2732490cbe
commit
c35a526dd8
@ -43,7 +43,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
|
|
||||||
if (!this.frm.is_new()) {
|
if (!this.frm.is_new()) {
|
||||||
frappe.contacts.render_address_and_contact(this.frm);
|
frappe.contacts.render_address_and_contact(this.frm);
|
||||||
cur_frm.trigger('render_basic_info_html');
|
cur_frm.trigger('render_contact_day_html');
|
||||||
} else {
|
} else {
|
||||||
frappe.contacts.clear_address_and_contact(this.frm);
|
frappe.contacts.clear_address_and_contact(this.frm);
|
||||||
}
|
}
|
||||||
@ -84,14 +84,14 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_basic_info_html() {
|
render_contact_day_html() {
|
||||||
if (cur_frm.doc.contact_date) {
|
if (cur_frm.doc.contact_date) {
|
||||||
let contact_date = frappe.datetime.obj_to_str(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 diff_days = frappe.datetime.get_day_diff(contact_date, frappe.datetime.get_today());
|
||||||
let color = diff_days > 0 ? "orange" : "green";
|
let color = diff_days > 0 ? "orange" : "green";
|
||||||
let message = diff_days > 0 ? __("Next Contact Date") : __("Last Contact Date");
|
let message = diff_days > 0 ? __("Next Contact Date") : __("Last Contact Date");
|
||||||
let html = `<div class="col-xs-12">
|
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>` ;
|
</div>` ;
|
||||||
cur_frm.dashboard.set_headline_alert(html);
|
cur_frm.dashboard.set_headline_alert(html);
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,6 @@ class Lead(SellingController):
|
|||||||
self.get("__onload").is_customer = customer
|
self.get("__onload").is_customer = customer
|
||||||
load_address_and_contact(self)
|
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):
|
def validate(self):
|
||||||
self.set_full_name()
|
self.set_full_name()
|
||||||
self.set_lead_name()
|
self.set_lead_name()
|
||||||
@ -38,6 +35,9 @@ class Lead(SellingController):
|
|||||||
"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if (not cint(self.is_new())) else None,
|
"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):
|
def validate_email_id(self):
|
||||||
if self.email_id:
|
if self.email_id:
|
||||||
if not self.flags.ignore_email_validation:
|
if not self.flags.ignore_email_validation:
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.utils import random_string
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
test_records = frappe.get_test_records('Lead')
|
test_records = frappe.get_test_records('Lead')
|
||||||
@ -32,3 +33,51 @@ class TestLead(unittest.TestCase):
|
|||||||
customer.company = "_Test Company"
|
customer.company = "_Test Company"
|
||||||
customer.customer_group = "_Test Customer Group"
|
customer.customer_group = "_Test Customer Group"
|
||||||
customer.insert()
|
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
|
Loading…
x
Reference in New Issue
Block a user