def test_make_new_lead_if_required(self): new_lead_email_id = "new{}@example.com".format(random_string(5)) args = { "doctype": "Opportunity", "contact_email": new_lead_email_id, "opportunity_type": "Sales", "with_items": 0, "transaction_date": today() } # new lead should be created against the [email protected] opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Lead") self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), new_lead_email_id) # create new customer and create new contact against '*****@*****.**' customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True) contact = frappe.get_doc({ "doctype": "Contact", "first_name": "_Test Opportunity Customer", "links": [{ "link_doctype": "Customer", "link_name": customer.name }] }) contact.add_email(new_lead_email_id, is_primary=True) contact.insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Customer") self.assertEqual(opp_doc.party_name, customer.name)
def test_make_new_lead_if_required(self): args = { "doctype": "Opportunity", "contact_email":"*****@*****.**", "enquiry_type": "Sales", "with_items": 0, "transaction_date": today() } # new lead should be created against the [email protected] opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.lead) self.assertEquals(opp_doc.enquiry_from, "Lead") self.assertEquals(frappe.db.get_value("Lead", opp_doc.lead, "email_id"), '*****@*****.**') # create new customer and create new contact against '*****@*****.**' customer = make_customer(opp_doc.lead).insert(ignore_permissions=True) frappe.get_doc({ "doctype": "Contact", "email_id": "*****@*****.**", "first_name": "_Test Opportunity Customer", "links": [{ "link_doctype": "Customer", "link_name": customer.name }] }).insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.customer) self.assertEquals(opp_doc.enquiry_from, "Customer") self.assertEquals(opp_doc.customer, customer.name)
def test_make_new_lead_if_required(self): args = { "doctype": "Opportunity", "contact_email": "*****@*****.**", "opportunity_type": "Sales", "with_items": 0, "transaction_date": today() } # new lead should be created against the [email protected] opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.lead) self.assertEqual(opp_doc.enquiry_from, "Lead") self.assertEqual(frappe.db.get_value("Lead", opp_doc.lead, "email_id"), '*****@*****.**') # create new customer and create new contact against '*****@*****.**' customer = make_customer(opp_doc.lead).insert(ignore_permissions=True) frappe.get_doc({ "doctype": "Contact", "email_id": "*****@*****.**", "first_name": "_Test Opportunity Customer", "links": [{ "link_doctype": "Customer", "link_name": customer.name }] }).insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.customer) self.assertEqual(opp_doc.enquiry_from, "Customer") self.assertEqual(opp_doc.customer, customer.name)
def test_make_customer(self): from erpnext.crm.doctype.lead.lead import make_customer frappe.delete_doc_if_exists("Customer", "_Test Lead") customer = make_customer("_T-Lead-00001") self.assertEqual(customer.doctype, "Customer") self.assertEqual(customer.lead_name, "_T-Lead-00001") customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" customer.insert() # check whether lead contact is carried forward to the customer. contact = frappe.db.get_value( "Dynamic Link", { "parenttype": "Contact", "link_doctype": "Lead", "link_name": customer.lead_name, }, "parent", ) if contact: contact_doc = frappe.get_doc("Contact", contact) self.assertEqual( contact_doc.has_link(customer.doctype, customer.name), True)
def test_make_customer_from_organization(self): from erpnext.crm.doctype.lead.lead import make_customer customer = make_customer("_T-Lead-00002") self.assertEqual(customer.doctype, "Customer") self.assertEqual(customer.lead_name, "_T-Lead-00002") customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" customer.insert()
def test_make_customer(self): from erpnext.crm.doctype.lead.lead import make_customer frappe.delete_doc_if_exists("Customer", "_Test Lead") customer = make_customer("_T-Lead-00001") self.assertEqual(customer.doctype, "Customer") self.assertEqual(customer.lead_name, "_T-Lead-00001") customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" customer.insert()
def test_make_customer(self): from erpnext.crm.doctype.lead.lead import make_customer frappe.delete_doc_if_exists("Customer", "_Test Lead") customer = make_customer("_T-Lead-00001") self.assertEquals(customer.doctype, "Customer") self.assertEquals(customer.lead_name, "_T-Lead-00001") customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" customer.insert()
def test_make_new_lead_if_required(self): opp_doc = make_opportunity_from_lead() self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Lead") self.assertEqual( frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), opp_doc.contact_email) # create new customer and create new contact against '*****@*****.**' customer = make_customer( opp_doc.party_name).insert(ignore_permissions=True) contact = frappe.get_doc({ "doctype": "Contact", "first_name": "_Test Opportunity Customer", "links": [{ "link_doctype": "Customer", "link_name": customer.name }], }) contact.add_email(opp_doc.contact_email, is_primary=True) contact.insert(ignore_permissions=True)
def create_customer(sodoc): from erpnext.crm.doctype.lead.lead import make_customer cust = make_customer(sodoc) cust.save()