fix: Make customer and lead dynamic_link in opportunity

This commit is contained in:
deepeshgarg007
2019-04-14 22:30:49 +05:30
parent 4f0a4a1a2d
commit af4d588f64
10 changed files with 144 additions and 114 deletions

View File

@@ -89,7 +89,7 @@ class Lead(SellingController):
return frappe.db.get_value("Customer", {"lead_name": self.name}) return frappe.db.get_value("Customer", {"lead_name": self.name})
def has_opportunity(self): def has_opportunity(self):
return frappe.db.get_value("Opportunity", {"lead": self.name, "status": ["!=", "Lost"]}) return frappe.db.get_value("Opportunity", {"customer_lead": self.name, "status": ["!=", "Lost"]})
def has_quotation(self): def has_quotation(self):
return frappe.db.get_value("Quotation", { return frappe.db.get_value("Quotation", {

View File

@@ -9,16 +9,24 @@ frappe.ui.form.on("Opportunity", {
frm.custom_make_buttons = { frm.custom_make_buttons = {
'Quotation': 'Quotation', 'Quotation': 'Quotation',
'Supplier Quotation': 'Supplier Quotation' 'Supplier Quotation': 'Supplier Quotation'
} },
},
customer: function(frm) {
frm.trigger('set_contact_link');
erpnext.utils.get_party_details(frm);
},
lead: function(frm) { frm.set_query("opportunity_from", function() {
frm.trigger('set_contact_link'); return{
"filters": {
"name": ["in", ["Customer", "Lead"]],
}
}
});
}, },
// customer: function(frm) {
// frm.trigger('set_contact_link');
// erpnext.utils.get_party_details(frm);
// },
// lead: function(frm) {
// frm.trigger('set_contact_link');
// },
with_items: function(frm) { with_items: function(frm) {
frm.trigger('toggle_mandatory'); frm.trigger('toggle_mandatory');
@@ -30,16 +38,17 @@ frappe.ui.form.on("Opportunity", {
contact_person: erpnext.utils.get_contact_details, contact_person: erpnext.utils.get_contact_details,
enquiry_from: function(frm) { opportunity_from: function(frm) {
frm.toggle_reqd("lead", frm.doc.enquiry_from==="Lead"); frm.toggle_reqd("customer_lead", frm.doc.opportunity_from);
frm.toggle_reqd("customer", frm.doc.enquiry_from==="Customer"); frm.trigger("set_dynamic_field_label");
}, },
refresh: function(frm) { refresh: function(frm) {
var doc = frm.doc; var doc = frm.doc;
frm.events.enquiry_from(frm); // frm.events.enquiry_from(frm);
frm.trigger('set_contact_link'); // frm.trigger('set_contact_link');
frm.trigger('toggle_mandatory'); frm.trigger('toggle_mandatory');
frm.trigger("set_dynamic_field_label");
erpnext.toggle_naming_series(); erpnext.toggle_naming_series();
if(!doc.__islocal && doc.status!=="Lost") { if(!doc.__islocal && doc.status!=="Lost") {
@@ -74,11 +83,22 @@ frappe.ui.form.on("Opportunity", {
} }
}, },
set_contact_link: function(frm) { // set_contact_link: function(frm) {
if(frm.doc.customer) { // if(frm.doc.customer) {
frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'} // frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
} else if(frm.doc.lead) { // } else if(frm.doc.lead) {
frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'} // frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'}
// }
// },
set_dynamic_field_label: function(frm){
if (frm.doc.opportunity_from == "Customer")
{
frm.set_df_property("customer_lead", "label", "Customer");
}
if (frm.doc.opportunity_from == "Lead")
{
frm.set_df_property("customer_lead", "label", "Lead");
} }
}, },
@@ -97,10 +117,10 @@ frappe.ui.form.on("Opportunity", {
// TODO commonify this code // TODO commonify this code
erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
onload: function() { onload: function() {
if(!this.frm.doc.enquiry_from && this.frm.doc.customer) // if(!this.frm.doc.enquiry_from && this.frm.doc.customer)
this.frm.doc.enquiry_from = "Customer"; // this.frm.doc.enquiry_from = "Customer";
if(!this.frm.doc.enquiry_from && this.frm.doc.lead) // if(!this.frm.doc.enquiry_from && this.frm.doc.lead)
this.frm.doc.enquiry_from = "Lead"; // this.frm.doc.enquiry_from = "Lead";
if(!this.frm.doc.status) if(!this.frm.doc.status)
set_multiple(this.frm.doc.doctype, this.frm.doc.name, { status:'Open' }); set_multiple(this.frm.doc.doctype, this.frm.doc.name, { status:'Open' });
@@ -148,7 +168,7 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
$.extend(cur_frm.cscript, new erpnext.crm.Opportunity({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.crm.Opportunity({frm: cur_frm}));
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
if(doc.enquiry_from == 'Lead' && doc.lead) if(doc.opportunity_from == 'Lead' && doc.lead)
cur_frm.cscript.lead(doc, cdt, cdn); cur_frm.cscript.lead(doc, cdt, cdn);
} }
@@ -171,10 +191,10 @@ cur_frm.cscript.item_code = function(doc, cdt, cdn) {
} }
cur_frm.cscript.lead = function(doc, cdt, cdn) { cur_frm.cscript.lead = function(doc, cdt, cdn) {
cur_frm.toggle_display("contact_info", doc.customer || doc.lead); cur_frm.toggle_display("contact_info", doc.customer_lead);
erpnext.utils.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity", method: "erpnext.crm.doctype.lead.lead.make_opportunity",
source_name: cur_frm.doc.lead, source_name: cur_frm.doc.customer_lead,
frm: cur_frm frm: cur_frm
}); });
} }

View File

@@ -21,6 +21,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "from_section", "fieldname": "from_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@@ -54,6 +55,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "", "default": "",
"fetch_if_empty": 0,
"fieldname": "naming_series", "fieldname": "naming_series",
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 0, "hidden": 0,
@@ -88,8 +90,9 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fieldname": "enquiry_from", "fetch_if_empty": 0,
"fieldtype": "Select", "fieldname": "opportunity_from",
"fieldtype": "Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
@@ -102,7 +105,7 @@
"no_copy": 0, "no_copy": 0,
"oldfieldname": "enquiry_from", "oldfieldname": "enquiry_from",
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "\nLead\nCustomer", "options": "DocType",
"permlevel": 0, "permlevel": 0,
"print_hide": 1, "print_hide": 1,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
@@ -122,9 +125,10 @@
"bold": 1, "bold": 1,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.enquiry_from===\"Customer\"", "depends_on": "",
"fieldname": "customer", "fetch_if_empty": 0,
"fieldtype": "Link", "fieldname": "customer_lead",
"fieldtype": "Dynamic Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
@@ -132,47 +136,12 @@
"in_global_search": 0, "in_global_search": 0,
"in_list_view": 0, "in_list_view": 0,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Customer", "label": "Customer/Lead",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"oldfieldname": "customer", "oldfieldname": "customer",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Customer", "options": "opportunity_from",
"permlevel": 0,
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:doc.enquiry_from===\"Lead\"",
"fieldname": "lead",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 1,
"label": "Lead",
"length": 0,
"no_copy": 0,
"oldfieldname": "lead",
"oldfieldtype": "Link",
"options": "Lead",
"permlevel": 0, "permlevel": 0,
"print_hide": 1, "print_hide": 1,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
@@ -193,6 +162,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "", "depends_on": "",
"fetch_if_empty": 0,
"fieldname": "customer_name", "fieldname": "customer_name",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0, "hidden": 0,
@@ -224,6 +194,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break0", "fieldname": "column_break0",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@@ -256,6 +227,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "title", "fieldname": "title",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 1, "hidden": 1,
@@ -289,6 +261,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "Sales", "default": "Sales",
"fetch_if_empty": 0,
"fieldname": "opportunity_type", "fieldname": "opportunity_type",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -324,6 +297,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "Open", "default": "Open",
"fetch_if_empty": 0,
"fieldname": "status", "fieldname": "status",
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 0, "hidden": 0,
@@ -359,6 +333,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.status===\"Lost\"", "depends_on": "eval:doc.status===\"Lost\"",
"fetch_if_empty": 0,
"fieldname": "order_lost_reason", "fieldname": "order_lost_reason",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 0, "hidden": 0,
@@ -390,6 +365,7 @@
"bold": 1, "bold": 1,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "mins_to_first_response", "fieldname": "mins_to_first_response",
"fieldtype": "Float", "fieldtype": "Float",
"hidden": 0, "hidden": 0,
@@ -423,6 +399,7 @@
"collapsible": 1, "collapsible": 1,
"collapsible_depends_on": "contact_by", "collapsible_depends_on": "contact_by",
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "next_contact", "fieldname": "next_contact",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@@ -456,6 +433,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"description": "", "description": "",
"fetch_if_empty": 0,
"fieldname": "contact_by", "fieldname": "contact_by",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -492,6 +470,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"description": "", "description": "",
"fetch_if_empty": 0,
"fieldname": "contact_date", "fieldname": "contact_date",
"fieldtype": "Datetime", "fieldtype": "Datetime",
"hidden": 0, "hidden": 0,
@@ -525,6 +504,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break2", "fieldname": "column_break2",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@@ -557,6 +537,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "to_discuss", "fieldname": "to_discuss",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 0, "hidden": 0,
@@ -590,6 +571,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "section_break_14", "fieldname": "section_break_14",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@@ -622,6 +604,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "currency", "fieldname": "currency",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -655,6 +638,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "opportunity_amount", "fieldname": "opportunity_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@@ -687,6 +671,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "with_items", "fieldname": "with_items",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 0, "hidden": 0,
@@ -719,6 +704,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break_17", "fieldname": "column_break_17",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@@ -751,6 +737,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "Prospecting", "default": "Prospecting",
"fetch_if_empty": 0,
"fieldname": "sales_stage", "fieldname": "sales_stage",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -785,6 +772,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "100", "default": "100",
"fetch_if_empty": 0,
"fieldname": "probability", "fieldname": "probability",
"fieldtype": "Percent", "fieldtype": "Percent",
"hidden": 0, "hidden": 0,
@@ -818,6 +806,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "with_items", "depends_on": "with_items",
"fetch_if_empty": 0,
"fieldname": "items_section", "fieldname": "items_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@@ -852,6 +841,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"description": "", "description": "",
"fetch_if_empty": 0,
"fieldname": "items", "fieldname": "items",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0, "hidden": 0,
@@ -888,6 +878,7 @@
"collapsible_depends_on": "next_contact_by", "collapsible_depends_on": "next_contact_by",
"columns": 0, "columns": 0,
"depends_on": "eval:doc.lead || doc.customer", "depends_on": "eval:doc.lead || doc.customer",
"fetch_if_empty": 0,
"fieldname": "contact_info", "fieldname": "contact_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@@ -921,6 +912,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.customer || doc.lead", "depends_on": "eval:doc.customer || doc.lead",
"fetch_if_empty": 0,
"fieldname": "customer_address", "fieldname": "customer_address",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -953,6 +945,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "address_display", "fieldname": "address_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 1, "hidden": 1,
@@ -988,6 +981,7 @@
"columns": 0, "columns": 0,
"depends_on": "customer", "depends_on": "customer",
"description": "", "description": "",
"fetch_if_empty": 0,
"fieldname": "territory", "fieldname": "territory",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1022,6 +1016,7 @@
"columns": 0, "columns": 0,
"depends_on": "customer", "depends_on": "customer",
"description": "", "description": "",
"fetch_if_empty": 0,
"fieldname": "customer_group", "fieldname": "customer_group",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1056,6 +1051,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break3", "fieldname": "column_break3",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@@ -1087,6 +1083,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.lead || doc.customer", "depends_on": "eval:doc.lead || doc.customer",
"fetch_if_empty": 0,
"fieldname": "contact_person", "fieldname": "contact_person",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1120,6 +1117,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "customer", "depends_on": "customer",
"fetch_if_empty": 0,
"fieldname": "contact_display", "fieldname": "contact_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 0, "hidden": 0,
@@ -1152,6 +1150,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.lead || doc.customer", "depends_on": "eval:doc.lead || doc.customer",
"fetch_if_empty": 0,
"fieldname": "contact_email", "fieldname": "contact_email",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0, "hidden": 0,
@@ -1184,6 +1183,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.lead || doc.customer", "depends_on": "eval:doc.lead || doc.customer",
"fetch_if_empty": 0,
"fieldname": "contact_mobile", "fieldname": "contact_mobile",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 0, "hidden": 0,
@@ -1216,6 +1216,7 @@
"collapsible": 1, "collapsible": 1,
"collapsible_depends_on": "", "collapsible_depends_on": "",
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "more_info", "fieldname": "more_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@@ -1249,6 +1250,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "source", "fieldname": "source",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1285,6 +1287,7 @@
"columns": 0, "columns": 0,
"depends_on": "eval: doc.source==\"Campaign\"", "depends_on": "eval: doc.source==\"Campaign\"",
"description": "Enter name of campaign if source of enquiry is campaign", "description": "Enter name of campaign if source of enquiry is campaign",
"fetch_if_empty": 0,
"fieldname": "campaign", "fieldname": "campaign",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1319,6 +1322,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break1", "fieldname": "column_break1",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@@ -1351,6 +1355,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1386,6 +1391,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "Today", "default": "Today",
"fetch_if_empty": 0,
"fieldname": "transaction_date", "fieldname": "transaction_date",
"fieldtype": "Date", "fieldtype": "Date",
"hidden": 0, "hidden": 0,
@@ -1420,6 +1426,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_if_empty": 0,
"fieldname": "amended_from", "fieldname": "amended_from",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@@ -1460,7 +1467,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-10-01 09:28:43.990999", "modified": "2019-04-14 21:00:16.007097",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "CRM", "module": "CRM",
"name": "Opportunity", "name": "Opportunity",
@@ -1508,11 +1515,11 @@
"quick_entry": 0, "quick_entry": 0,
"read_only": 0, "read_only": 0,
"read_only_onload": 0, "read_only_onload": 0,
"search_fields": "status,transaction_date,customer,lead,opportunity_type,territory,company", "search_fields": "status,transaction_date,customer_lead,opportunity_type,territory,company",
"show_name_in_global_search": 1, "show_name_in_global_search": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"timeline_field": "customer", "timeline_field": "customer_lead",
"title_field": "title", "title_field": "title",
"track_changes": 0, "track_changes": 0,
"track_seen": 1, "track_seen": 1,

View File

@@ -15,8 +15,8 @@ sender_field = "contact_email"
class Opportunity(TransactionBase): class Opportunity(TransactionBase):
def after_insert(self): def after_insert(self):
if self.lead: if self.opportunity_from == "Lead":
frappe.get_doc("Lead", self.lead).set_status(update=True) frappe.get_doc("Lead", self.customer_lead).set_status(update=True)
def validate(self): def validate(self):
self._prev = frappe._dict({ self._prev = frappe._dict({
@@ -28,7 +28,7 @@ class Opportunity(TransactionBase):
self.make_new_lead_if_required() self.make_new_lead_if_required()
if not self.enquiry_from: if not self.opportunity_from:
frappe.throw(_("Opportunity From field is mandatory")) frappe.throw(_("Opportunity From field is mandatory"))
self.validate_item_details() self.validate_item_details()
@@ -44,7 +44,7 @@ class Opportunity(TransactionBase):
def make_new_lead_if_required(self): def make_new_lead_if_required(self):
"""Set lead against new opportunity""" """Set lead against new opportunity"""
if not (self.lead or self.customer) and self.contact_email: if not self.customer_lead and self.contact_email:
# check if customer is already created agains the self.contact_email # check if customer is already created agains the self.contact_email
customer = frappe.db.sql("""select customer = frappe.db.sql("""select
distinct `tabDynamic Link`.link_name as customer distinct `tabDynamic Link`.link_name as customer
@@ -60,8 +60,8 @@ class Opportunity(TransactionBase):
`tabDynamic Link`.link_doctype='Customer' `tabDynamic Link`.link_doctype='Customer'
""".format(self.contact_email), as_dict=True) """.format(self.contact_email), as_dict=True)
if customer and customer[0].customer: if customer and customer[0].customer:
self.customer = customer[0].customer self.customer_lead = customer[0].customer
self.enquiry_from = "Customer" self.opportunity_from = "Customer"
return return
lead_name = frappe.db.get_value("Lead", {"email_id": self.contact_email}) lead_name = frappe.db.get_value("Lead", {"email_id": self.contact_email})
@@ -88,8 +88,8 @@ class Opportunity(TransactionBase):
lead.insert(ignore_permissions=True) lead.insert(ignore_permissions=True)
lead_name = lead.name lead_name = lead.name
self.enquiry_from = "Lead" self.opportunity_from = "Lead"
self.lead = lead_name self.customer_lead = lead_name
def declare_enquiry_lost(self,arg): def declare_enquiry_lost(self,arg):
if not self.has_active_quotation(): if not self.has_active_quotation():
@@ -136,10 +136,10 @@ class Opportunity(TransactionBase):
return True return True
def validate_cust_name(self): def validate_cust_name(self):
if self.customer: if self.customer_lead and self.opportunity_from == 'Customer':
self.customer_name = frappe.db.get_value("Customer", self.customer, "customer_name") self.customer_name = frappe.db.get_value("Customer", self.customer_lead, "customer_name")
elif self.lead: elif self.customer_lead and self.opportunity_from == 'Lead':
lead_name, company_name = frappe.db.get_value("Lead", self.lead, ["lead_name", "company_name"]) lead_name, company_name = frappe.db.get_value("Lead", self.customer_lead, ["lead_name", "company_name"])
self.customer_name = company_name or lead_name self.customer_name = company_name or lead_name
def on_update(self): def on_update(self):
@@ -152,16 +152,16 @@ class Opportunity(TransactionBase):
opts.description = "" opts.description = ""
opts.contact_date = self.contact_date opts.contact_date = self.contact_date
if self.customer: if self.customer_lead and self.opportunity_from == 'Customer':
if self.contact_person: if self.contact_person:
opts.description = 'Contact '+cstr(self.contact_person) opts.description = 'Contact '+cstr(self.contact_person)
else: else:
opts.description = 'Contact customer '+cstr(self.customer) opts.description = 'Contact customer '+cstr(self.customer_lead)
elif self.lead: elif self.customer_lead and self.opportunity_from == 'Lead':
if self.contact_display: if self.contact_display:
opts.description = 'Contact '+cstr(self.contact_display) opts.description = 'Contact '+cstr(self.contact_display)
else: else:
opts.description = 'Contact lead '+cstr(self.lead) opts.description = 'Contact lead '+cstr(self.customer_lead)
opts.subject = opts.description opts.subject = opts.description
opts.description += '. By : ' + cstr(self.contact_by) opts.description += '. By : ' + cstr(self.contact_by)
@@ -187,16 +187,13 @@ class Opportunity(TransactionBase):
if not d.get(key): d.set(key, item.get(key)) if not d.get(key): d.set(key, item.get(key))
def validate_lead_cust(self): def validate_lead_cust(self):
if self.enquiry_from == 'Lead': if self.opportunity_from == 'Lead':
if not self.lead: if not self.customer_lead:
frappe.throw(_("Lead must be set if Opportunity is made from Lead")) frappe.throw(_("Lead must be set if Opportunity is made from Lead"))
else: elif self.opportunity_from == 'Customer':
self.customer = None if not self.customer_lead:
elif self.enquiry_from == 'Customer':
if not self.customer:
msgprint(_("Customer is mandatory if 'Opportunity From' is selected as Customer"), raise_exception=1) msgprint(_("Customer is mandatory if 'Opportunity From' is selected as Customer"), raise_exception=1)
else:
self.lead = None
@frappe.whitelist() @frappe.whitelist()
def get_item_details(item_code): def get_item_details(item_code):

View File

@@ -37,13 +37,13 @@ class TestOpportunity(unittest.TestCase):
# new lead should be created against the new.opportunity@example.com # new lead should be created against the new.opportunity@example.com
opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True)
self.assertTrue(opp_doc.lead) self.assertTrue(opp_doc.customer_lead)
self.assertEqual(opp_doc.enquiry_from, "Lead") self.assertEqual(opp_doc.opportunity_from, "Lead")
self.assertEqual(frappe.db.get_value("Lead", opp_doc.lead, "email_id"), self.assertEqual(frappe.db.get_value("Lead", opp_doc.customer_lead, "email_id"),
'new.opportunity@example.com') 'new.opportunity@example.com')
# create new customer and create new contact against 'new.opportunity@example.com' # create new customer and create new contact against 'new.opportunity@example.com'
customer = make_customer(opp_doc.lead).insert(ignore_permissions=True) customer = make_customer(opp_doc.customer_lead).insert(ignore_permissions=True)
frappe.get_doc({ frappe.get_doc({
"doctype": "Contact", "doctype": "Contact",
"email_id": "new.opportunity@example.com", "email_id": "new.opportunity@example.com",
@@ -55,9 +55,9 @@ class TestOpportunity(unittest.TestCase):
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)
opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True)
self.assertTrue(opp_doc.customer) self.assertTrue(opp_doc.customer_lead)
self.assertEqual(opp_doc.enquiry_from, "Customer") self.assertEqual(opp_doc.opportunity_from, "Customer")
self.assertEqual(opp_doc.customer, customer.name) self.assertEqual(opp_doc.customer_lead, customer.name)
def make_opportunity(**args): def make_opportunity(**args):
args = frappe._dict(args) args = frappe._dict(args)
@@ -65,17 +65,17 @@ def make_opportunity(**args):
opp_doc = frappe.get_doc({ opp_doc = frappe.get_doc({
"doctype": "Opportunity", "doctype": "Opportunity",
"company": args.company or "_Test Company", "company": args.company or "_Test Company",
"enquiry_from": args.enquiry_from or "Customer", "opportunity_from": args.opportunity_from or "Customer",
"opportunity_type": "Sales", "opportunity_type": "Sales",
"with_items": args.with_items or 0, "with_items": args.with_items or 0,
"transaction_date": today() "transaction_date": today()
}) })
if opp_doc.enquiry_from == 'Customer': if opp_doc.opportunity_from == 'Customer':
opp_doc.customer = args.customer or "_Test Customer" opp_doc.customer_lead= args.customer or "_Test Customer"
if opp_doc.enquiry_from == 'Lead': if opp_doc.opportunity_from == 'Lead':
opp_doc.customer = args.lead or "_T-Lead-00001" opp_doc.customer_lead = args.lead or "_T-Lead-00001"
if args.with_items: if args.with_items:
opp_doc.append('items', { opp_doc.append('items', {

View File

@@ -2,9 +2,9 @@
{ {
"doctype": "Opportunity", "doctype": "Opportunity",
"name": "_Test Opportunity 1", "name": "_Test Opportunity 1",
"enquiry_from": "Lead", "opportunity_from": "Lead",
"enquiry_type": "Sales", "enquiry_type": "Sales",
"lead": "_T-Lead-00001", "customer_lead": "_T-Lead-00001",
"transaction_date": "2013-12-12", "transaction_date": "2013-12-12",
"items": [{ "items": [{
"item_name": "Test Item", "item_name": "Test Item",

View File

@@ -7,4 +7,8 @@ import frappe
def execute(): def execute():
frappe.reload_doctype("Quotation") frappe.reload_doctype("Quotation")
frappe.db.sql(""" UPDATE `tabQuotation` set customer_lead = lead WHERE quotation_to = 'Lead' """) frappe.db.sql(""" UPDATE `tabQuotation` set customer_lead = lead WHERE quotation_to = 'Lead' """)
frappe.db.sql(""" UPDATE `tabQuotation` set customer_lead = customer WHERE quotation_to = 'Customer' """) frappe.db.sql(""" UPDATE `tabQuotation` set customer_lead = customer WHERE quotation_to = 'Customer' """)
frappe.reload_doctype("Opportunity")
frappe.db.sql(""" UPDATE `tabOpportunity` set customer_lead = lead WHERE opportunity_from = 'Lead' """)
frappe.db.sql(""" UPDATE `tabOpportunity` set customer_lead = customer WHERE opportunity_from = 'Customer' """)

View File

@@ -104,8 +104,8 @@ class Customer(TransactionBase):
if self.lead_name: if self.lead_name:
frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False) frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False)
for d in frappe.get_all('Opportunity', {'lead': self.lead_name}): for d in frappe.get_all('Opportunity', {'customer_lead': self.lead_name}):
frappe.db.set_value('Opportunity', d.name, 'customer', self.name, update_modified=False) frappe.db.set_value('Opportunity', d.name, 'customer_lead', self.name, update_modified=False)
def create_lead_address_contact(self): def create_lead_address_contact(self):
if self.lead_name: if self.lead_name:

View File

@@ -7,7 +7,8 @@ def get_data():
'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'), 'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'),
'fieldname': 'customer', 'fieldname': 'customer',
'non_standard_fieldnames': { 'non_standard_fieldnames': {
'Quotation': 'customer_lead' 'Quotation': 'customer_lead',
'Opportunity': 'customer_lead'
}, },
'transactions': [ 'transactions': [
{ {

View File

@@ -28,6 +28,7 @@ frappe.ui.form.on('Quotation', {
quotation_to: function(frm) { quotation_to: function(frm) {
frm.trigger("set_label"); frm.trigger("set_label");
frm.trigger("toggle_reqd_lead_customer"); frm.trigger("toggle_reqd_lead_customer");
frm.trigger("set_dynamic_field_label");
}, },
set_label: function(frm) { set_label: function(frm) {