feat(crm): Allow leads to be imported without person name

This commit is contained in:
Rohan Bansal 2019-05-10 15:48:14 +05:30
parent b10392134d
commit 9778ff8ab3
3 changed files with 36 additions and 31 deletions

View File

@ -5,29 +5,32 @@ frappe.provide("erpnext");
cur_frm.email_field = "email_id"; cur_frm.email_field = "email_id";
erpnext.LeadController = frappe.ui.form.Controller.extend({ erpnext.LeadController = frappe.ui.form.Controller.extend({
setup: function() { setup: function () {
this.frm.fields_dict.customer.get_query = function(doc, cdt, cdn) { this.frm.fields_dict.customer.get_query = function (doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.customer_query" } } return { query: "erpnext.controllers.queries.customer_query" }
}
this.frm.toggle_reqd("lead_name", !this.frm.doc.organization_lead);
}, },
onload: function() { onload: function () {
if (cur_frm.fields_dict.lead_owner.df.options.match(/^User/)) {
if(cur_frm.fields_dict.lead_owner.df.options.match(/^User/)) { cur_frm.fields_dict.lead_owner.get_query = function (doc, cdt, cdn) {
cur_frm.fields_dict.lead_owner.get_query = function(doc, cdt, cdn) {
return { query: "frappe.core.doctype.user.user.user_query" } return { query: "frappe.core.doctype.user.user.user_query" }
} }
} }
if(cur_frm.fields_dict.contact_by.df.options.match(/^User/)) { if (cur_frm.fields_dict.contact_by.df.options.match(/^User/)) {
cur_frm.fields_dict.contact_by.get_query = function(doc, cdt, cdn) { cur_frm.fields_dict.contact_by.get_query = function (doc, cdt, cdn) {
return { query: "frappe.core.doctype.user.user.user_query" } } return { query: "frappe.core.doctype.user.user.user_query" }
}
} }
}, },
refresh: function() { refresh: function () {
var doc = this.frm.doc; var doc = this.frm.doc;
erpnext.toggle_naming_series(); erpnext.toggle_naming_series();
frappe.dynamic_link = {doc: doc, fieldname: 'name', doctype: 'Lead'} frappe.dynamic_link = { doc: doc, fieldname: 'name', doctype: 'Lead' }
if(!doc.__islocal && doc.__onload && !doc.__onload.is_customer) { if(!doc.__islocal && doc.__onload && !doc.__onload.is_customer) {
this.frm.add_custom_button(__("Customer"), this.create_customer, __('Create')); this.frm.add_custom_button(__("Customer"), this.create_customer, __('Create'));
@ -35,49 +38,46 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
this.frm.add_custom_button(__("Quotation"), this.make_quotation, __('Create')); this.frm.add_custom_button(__("Quotation"), this.make_quotation, __('Create'));
} }
if(!this.frm.doc.__islocal) { if (!this.frm.doc.__islocal) {
frappe.contacts.render_address_and_contact(cur_frm); frappe.contacts.render_address_and_contact(cur_frm);
} else { } else {
frappe.contacts.clear_address_and_contact(cur_frm); frappe.contacts.clear_address_and_contact(cur_frm);
} }
}, },
create_customer: function() { create_customer: function () {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_customer", method: "erpnext.crm.doctype.lead.lead.make_customer",
frm: cur_frm frm: cur_frm
}) })
}, },
create_opportunity: function() { create_opportunity: function () {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity", method: "erpnext.crm.doctype.lead.lead.make_opportunity",
frm: cur_frm frm: cur_frm
}) })
}, },
make_quotation: function() { make_quotation: function () {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_quotation", method: "erpnext.crm.doctype.lead.lead.make_quotation",
frm: cur_frm frm: cur_frm
}) })
}, },
organization_lead: function() { organization_lead: function () {
if (this.frm.doc.organization_lead == 1) { this.frm.toggle_reqd("lead_name", !this.frm.doc.organization_lead);
this.frm.set_df_property('company_name', 'reqd', 1); this.frm.toggle_reqd("company_name", this.frm.doc.organization_lead);
} else {
this.frm.set_df_property('company_name', 'reqd', 0);
}
}, },
company_name: function() { company_name: function () {
if (this.frm.doc.organization_lead == 1) { if (this.frm.doc.organization_lead == 1) {
this.frm.set_value("lead_name", this.frm.doc.company_name); this.frm.set_value("lead_name", this.frm.doc.company_name);
} }
}, },
contact_date: function() { contact_date: function () {
if (this.frm.doc.contact_date) { if (this.frm.doc.contact_date) {
let d = moment(this.frm.doc.contact_date); let d = moment(this.frm.doc.contact_date);
d.add(1, "hours"); d.add(1, "hours");
@ -86,4 +86,4 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
} }
}); });
$.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.LeadController({ frm: cur_frm }));

View File

@ -145,7 +145,7 @@
"read_only": 0, "read_only": 0,
"remember_last_selected_value": 0, "remember_last_selected_value": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 0,
"search_index": 1, "search_index": 1,
"set_only_once": 0, "set_only_once": 0,
"translatable": 0, "translatable": 0,
@ -268,7 +268,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_global_search": 0, "in_global_search": 0,
"in_list_view": 0, "in_list_view": 1,
"in_standard_filter": 0, "in_standard_filter": 0,
"label": "Lead Owner", "label": "Lead Owner",
"length": 0, "length": 0,
@ -1419,17 +1419,18 @@
} }
], ],
"has_web_view": 0, "has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0, "hide_toolbar": 0,
"icon": "fa fa-user", "icon": "fa fa-user",
"idx": 5, "idx": 5,
"image_field": "image", "image_field": "image",
"image_view": 0,
"in_create": 0, "in_create": 0,
"is_submittable": 0, "is_submittable": 0,
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"menu_index": 0, "modified": "2019-05-10 03:22:57.283628",
"modified": "2019-04-11 22:12:50.029368",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "CRM", "module": "CRM",
"name": "Lead", "name": "Lead",

View File

@ -109,7 +109,11 @@ class Lead(SellingController):
def set_lead_name(self): def set_lead_name(self):
if not self.lead_name: if not self.lead_name:
frappe.db.set_value("Lead", self.name, "lead_name", self.company_name) # Check for leads being created through data import
if not self.company_name:
frappe.throw(_("A Lead requires either a person's name or an organization's name"))
self.lead_name = self.company_name
@frappe.whitelist() @frappe.whitelist()
def make_customer(source_name, target_doc=None): def make_customer(source_name, target_doc=None):
@ -225,4 +229,4 @@ def make_lead_from_communication(communication, ignore_communication_links=False
lead_name = lead.name lead_name = lead.name
link_communication_to_document(doc, "Lead", lead_name, ignore_communication_links) link_communication_to_document(doc, "Lead", lead_name, ignore_communication_links)
return lead_name return lead_name