mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-18 09:47:14 +00:00
fix: Make customer and lead dynamic_link in opportunity
This commit is contained in:
@@ -89,7 +89,7 @@ class Lead(SellingController):
|
||||
return frappe.db.get_value("Customer", {"lead_name": self.name})
|
||||
|
||||
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):
|
||||
return frappe.db.get_value("Quotation", {
|
||||
|
||||
@@ -9,16 +9,24 @@ frappe.ui.form.on("Opportunity", {
|
||||
frm.custom_make_buttons = {
|
||||
'Quotation': 'Quotation',
|
||||
'Supplier Quotation': 'Supplier Quotation'
|
||||
}
|
||||
},
|
||||
customer: function(frm) {
|
||||
frm.trigger('set_contact_link');
|
||||
erpnext.utils.get_party_details(frm);
|
||||
},
|
||||
},
|
||||
|
||||
lead: function(frm) {
|
||||
frm.trigger('set_contact_link');
|
||||
frm.set_query("opportunity_from", function() {
|
||||
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) {
|
||||
frm.trigger('toggle_mandatory');
|
||||
@@ -30,16 +38,17 @@ frappe.ui.form.on("Opportunity", {
|
||||
|
||||
contact_person: erpnext.utils.get_contact_details,
|
||||
|
||||
enquiry_from: function(frm) {
|
||||
frm.toggle_reqd("lead", frm.doc.enquiry_from==="Lead");
|
||||
frm.toggle_reqd("customer", frm.doc.enquiry_from==="Customer");
|
||||
opportunity_from: function(frm) {
|
||||
frm.toggle_reqd("customer_lead", frm.doc.opportunity_from);
|
||||
frm.trigger("set_dynamic_field_label");
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
var doc = frm.doc;
|
||||
frm.events.enquiry_from(frm);
|
||||
frm.trigger('set_contact_link');
|
||||
// frm.events.enquiry_from(frm);
|
||||
// frm.trigger('set_contact_link');
|
||||
frm.trigger('toggle_mandatory');
|
||||
frm.trigger("set_dynamic_field_label");
|
||||
erpnext.toggle_naming_series();
|
||||
|
||||
if(!doc.__islocal && doc.status!=="Lost") {
|
||||
@@ -74,11 +83,22 @@ frappe.ui.form.on("Opportunity", {
|
||||
}
|
||||
},
|
||||
|
||||
set_contact_link: function(frm) {
|
||||
if(frm.doc.customer) {
|
||||
frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||
} else if(frm.doc.lead) {
|
||||
frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'}
|
||||
// set_contact_link: function(frm) {
|
||||
// if(frm.doc.customer) {
|
||||
// frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||
// } else if(frm.doc.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
|
||||
erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
|
||||
onload: function() {
|
||||
if(!this.frm.doc.enquiry_from && this.frm.doc.customer)
|
||||
this.frm.doc.enquiry_from = "Customer";
|
||||
if(!this.frm.doc.enquiry_from && this.frm.doc.lead)
|
||||
this.frm.doc.enquiry_from = "Lead";
|
||||
// if(!this.frm.doc.enquiry_from && this.frm.doc.customer)
|
||||
// this.frm.doc.enquiry_from = "Customer";
|
||||
// if(!this.frm.doc.enquiry_from && this.frm.doc.lead)
|
||||
// this.frm.doc.enquiry_from = "Lead";
|
||||
|
||||
if(!this.frm.doc.status)
|
||||
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}));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -171,10 +191,10 @@ cur_frm.cscript.item_code = 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({
|
||||
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
|
||||
source_name: cur_frm.doc.lead,
|
||||
source_name: cur_frm.doc.customer_lead,
|
||||
frm: cur_frm
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "from_section",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@@ -54,6 +55,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "naming_series",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
@@ -88,8 +90,9 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "enquiry_from",
|
||||
"fieldtype": "Select",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "opportunity_from",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
@@ -102,7 +105,7 @@
|
||||
"no_copy": 0,
|
||||
"oldfieldname": "enquiry_from",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "\nLead\nCustomer",
|
||||
"options": "DocType",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
@@ -122,9 +125,10 @@
|
||||
"bold": 1,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.enquiry_from===\"Customer\"",
|
||||
"fieldname": "customer",
|
||||
"fieldtype": "Link",
|
||||
"depends_on": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "customer_lead",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
@@ -132,47 +136,12 @@
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Customer",
|
||||
"label": "Customer/Lead",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"oldfieldname": "customer",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Customer",
|
||||
"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",
|
||||
"options": "opportunity_from",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
@@ -193,6 +162,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "customer_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
@@ -224,6 +194,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "column_break0",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
@@ -256,6 +227,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
@@ -289,6 +261,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Sales",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "opportunity_type",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -324,6 +297,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Open",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
@@ -359,6 +333,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.status===\"Lost\"",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "order_lost_reason",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 0,
|
||||
@@ -390,6 +365,7 @@
|
||||
"bold": 1,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "mins_to_first_response",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
@@ -423,6 +399,7 @@
|
||||
"collapsible": 1,
|
||||
"collapsible_depends_on": "contact_by",
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "next_contact",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@@ -456,6 +433,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"description": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_by",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -492,6 +470,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"description": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_date",
|
||||
"fieldtype": "Datetime",
|
||||
"hidden": 0,
|
||||
@@ -525,6 +504,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "column_break2",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
@@ -557,6 +537,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "to_discuss",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 0,
|
||||
@@ -590,6 +571,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "section_break_14",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@@ -622,6 +604,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -655,6 +638,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "opportunity_amount",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 0,
|
||||
@@ -687,6 +671,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "with_items",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
@@ -719,6 +704,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "column_break_17",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
@@ -751,6 +737,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Prospecting",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "sales_stage",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -785,6 +772,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "100",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "probability",
|
||||
"fieldtype": "Percent",
|
||||
"hidden": 0,
|
||||
@@ -818,6 +806,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "with_items",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "items_section",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@@ -852,6 +841,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"description": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "items",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
@@ -888,6 +878,7 @@
|
||||
"collapsible_depends_on": "next_contact_by",
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.lead || doc.customer",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_info",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@@ -921,6 +912,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.customer || doc.lead",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "customer_address",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -953,6 +945,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "address_display",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 1,
|
||||
@@ -988,6 +981,7 @@
|
||||
"columns": 0,
|
||||
"depends_on": "customer",
|
||||
"description": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1022,6 +1016,7 @@
|
||||
"columns": 0,
|
||||
"depends_on": "customer",
|
||||
"description": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1056,6 +1051,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "column_break3",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
@@ -1087,6 +1083,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.lead || doc.customer",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_person",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1120,6 +1117,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "customer",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_display",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 0,
|
||||
@@ -1152,6 +1150,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.lead || doc.customer",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_email",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
@@ -1184,6 +1183,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.lead || doc.customer",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "contact_mobile",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 0,
|
||||
@@ -1216,6 +1216,7 @@
|
||||
"collapsible": 1,
|
||||
"collapsible_depends_on": "",
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "more_info",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@@ -1249,6 +1250,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "source",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1285,6 +1287,7 @@
|
||||
"columns": 0,
|
||||
"depends_on": "eval: doc.source==\"Campaign\"",
|
||||
"description": "Enter name of campaign if source of enquiry is campaign",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "campaign",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1319,6 +1322,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "column_break1",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
@@ -1351,6 +1355,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1386,6 +1391,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Today",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "transaction_date",
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
@@ -1420,6 +1426,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -1460,7 +1467,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2018-10-01 09:28:43.990999",
|
||||
"modified": "2019-04-14 21:00:16.007097",
|
||||
"modified_by": "Administrator",
|
||||
"module": "CRM",
|
||||
"name": "Opportunity",
|
||||
@@ -1508,11 +1515,11 @@
|
||||
"quick_entry": 0,
|
||||
"read_only": 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,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"timeline_field": "customer",
|
||||
"timeline_field": "customer_lead",
|
||||
"title_field": "title",
|
||||
"track_changes": 0,
|
||||
"track_seen": 1,
|
||||
|
||||
@@ -15,8 +15,8 @@ sender_field = "contact_email"
|
||||
|
||||
class Opportunity(TransactionBase):
|
||||
def after_insert(self):
|
||||
if self.lead:
|
||||
frappe.get_doc("Lead", self.lead).set_status(update=True)
|
||||
if self.opportunity_from == "Lead":
|
||||
frappe.get_doc("Lead", self.customer_lead).set_status(update=True)
|
||||
|
||||
def validate(self):
|
||||
self._prev = frappe._dict({
|
||||
@@ -28,7 +28,7 @@ class Opportunity(TransactionBase):
|
||||
|
||||
self.make_new_lead_if_required()
|
||||
|
||||
if not self.enquiry_from:
|
||||
if not self.opportunity_from:
|
||||
frappe.throw(_("Opportunity From field is mandatory"))
|
||||
|
||||
self.validate_item_details()
|
||||
@@ -44,7 +44,7 @@ class Opportunity(TransactionBase):
|
||||
|
||||
def make_new_lead_if_required(self):
|
||||
"""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
|
||||
customer = frappe.db.sql("""select
|
||||
distinct `tabDynamic Link`.link_name as customer
|
||||
@@ -60,8 +60,8 @@ class Opportunity(TransactionBase):
|
||||
`tabDynamic Link`.link_doctype='Customer'
|
||||
""".format(self.contact_email), as_dict=True)
|
||||
if customer and customer[0].customer:
|
||||
self.customer = customer[0].customer
|
||||
self.enquiry_from = "Customer"
|
||||
self.customer_lead = customer[0].customer
|
||||
self.opportunity_from = "Customer"
|
||||
return
|
||||
|
||||
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_name = lead.name
|
||||
|
||||
self.enquiry_from = "Lead"
|
||||
self.lead = lead_name
|
||||
self.opportunity_from = "Lead"
|
||||
self.customer_lead = lead_name
|
||||
|
||||
def declare_enquiry_lost(self,arg):
|
||||
if not self.has_active_quotation():
|
||||
@@ -136,10 +136,10 @@ class Opportunity(TransactionBase):
|
||||
return True
|
||||
|
||||
def validate_cust_name(self):
|
||||
if self.customer:
|
||||
self.customer_name = frappe.db.get_value("Customer", self.customer, "customer_name")
|
||||
elif self.lead:
|
||||
lead_name, company_name = frappe.db.get_value("Lead", self.lead, ["lead_name", "company_name"])
|
||||
if self.customer_lead and self.opportunity_from == 'Customer':
|
||||
self.customer_name = frappe.db.get_value("Customer", self.customer_lead, "customer_name")
|
||||
elif self.customer_lead and self.opportunity_from == 'Lead':
|
||||
lead_name, company_name = frappe.db.get_value("Lead", self.customer_lead, ["lead_name", "company_name"])
|
||||
self.customer_name = company_name or lead_name
|
||||
|
||||
def on_update(self):
|
||||
@@ -152,16 +152,16 @@ class Opportunity(TransactionBase):
|
||||
opts.description = ""
|
||||
opts.contact_date = self.contact_date
|
||||
|
||||
if self.customer:
|
||||
if self.customer_lead and self.opportunity_from == 'Customer':
|
||||
if self.contact_person:
|
||||
opts.description = 'Contact '+cstr(self.contact_person)
|
||||
else:
|
||||
opts.description = 'Contact customer '+cstr(self.customer)
|
||||
elif self.lead:
|
||||
opts.description = 'Contact customer '+cstr(self.customer_lead)
|
||||
elif self.customer_lead and self.opportunity_from == 'Lead':
|
||||
if self.contact_display:
|
||||
opts.description = 'Contact '+cstr(self.contact_display)
|
||||
else:
|
||||
opts.description = 'Contact lead '+cstr(self.lead)
|
||||
opts.description = 'Contact lead '+cstr(self.customer_lead)
|
||||
|
||||
opts.subject = opts.description
|
||||
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))
|
||||
|
||||
def validate_lead_cust(self):
|
||||
if self.enquiry_from == 'Lead':
|
||||
if not self.lead:
|
||||
if self.opportunity_from == 'Lead':
|
||||
if not self.customer_lead:
|
||||
frappe.throw(_("Lead must be set if Opportunity is made from Lead"))
|
||||
else:
|
||||
self.customer = None
|
||||
elif self.enquiry_from == 'Customer':
|
||||
if not self.customer:
|
||||
elif self.opportunity_from == 'Customer':
|
||||
if not self.customer_lead:
|
||||
msgprint(_("Customer is mandatory if 'Opportunity From' is selected as Customer"), raise_exception=1)
|
||||
else:
|
||||
self.lead = None
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_item_details(item_code):
|
||||
|
||||
@@ -37,13 +37,13 @@ class TestOpportunity(unittest.TestCase):
|
||||
# new lead should be created against the new.opportunity@example.com
|
||||
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"),
|
||||
self.assertTrue(opp_doc.customer_lead)
|
||||
self.assertEqual(opp_doc.opportunity_from, "Lead")
|
||||
self.assertEqual(frappe.db.get_value("Lead", opp_doc.customer_lead, "email_id"),
|
||||
'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({
|
||||
"doctype": "Contact",
|
||||
"email_id": "new.opportunity@example.com",
|
||||
@@ -55,9 +55,9 @@ class TestOpportunity(unittest.TestCase):
|
||||
}).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)
|
||||
self.assertTrue(opp_doc.customer_lead)
|
||||
self.assertEqual(opp_doc.opportunity_from, "Customer")
|
||||
self.assertEqual(opp_doc.customer_lead, customer.name)
|
||||
|
||||
def make_opportunity(**args):
|
||||
args = frappe._dict(args)
|
||||
@@ -65,17 +65,17 @@ def make_opportunity(**args):
|
||||
opp_doc = frappe.get_doc({
|
||||
"doctype": "Opportunity",
|
||||
"company": args.company or "_Test Company",
|
||||
"enquiry_from": args.enquiry_from or "Customer",
|
||||
"opportunity_from": args.opportunity_from or "Customer",
|
||||
"opportunity_type": "Sales",
|
||||
"with_items": args.with_items or 0,
|
||||
"transaction_date": today()
|
||||
})
|
||||
|
||||
if opp_doc.enquiry_from == 'Customer':
|
||||
opp_doc.customer = args.customer or "_Test Customer"
|
||||
if opp_doc.opportunity_from == 'Customer':
|
||||
opp_doc.customer_lead= args.customer or "_Test Customer"
|
||||
|
||||
if opp_doc.enquiry_from == 'Lead':
|
||||
opp_doc.customer = args.lead or "_T-Lead-00001"
|
||||
if opp_doc.opportunity_from == 'Lead':
|
||||
opp_doc.customer_lead = args.lead or "_T-Lead-00001"
|
||||
|
||||
if args.with_items:
|
||||
opp_doc.append('items', {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
{
|
||||
"doctype": "Opportunity",
|
||||
"name": "_Test Opportunity 1",
|
||||
"enquiry_from": "Lead",
|
||||
"opportunity_from": "Lead",
|
||||
"enquiry_type": "Sales",
|
||||
"lead": "_T-Lead-00001",
|
||||
"customer_lead": "_T-Lead-00001",
|
||||
"transaction_date": "2013-12-12",
|
||||
"items": [{
|
||||
"item_name": "Test Item",
|
||||
|
||||
@@ -7,4 +7,8 @@ import frappe
|
||||
def execute():
|
||||
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 = 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' """)
|
||||
@@ -104,8 +104,8 @@ class Customer(TransactionBase):
|
||||
if self.lead_name:
|
||||
frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False)
|
||||
|
||||
for d in frappe.get_all('Opportunity', {'lead': self.lead_name}):
|
||||
frappe.db.set_value('Opportunity', d.name, 'customer', self.name, update_modified=False)
|
||||
for d in frappe.get_all('Opportunity', {'customer_lead': self.lead_name}):
|
||||
frappe.db.set_value('Opportunity', d.name, 'customer_lead', self.name, update_modified=False)
|
||||
|
||||
def create_lead_address_contact(self):
|
||||
if self.lead_name:
|
||||
|
||||
@@ -7,7 +7,8 @@ def get_data():
|
||||
'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'),
|
||||
'fieldname': 'customer',
|
||||
'non_standard_fieldnames': {
|
||||
'Quotation': 'customer_lead'
|
||||
'Quotation': 'customer_lead',
|
||||
'Opportunity': 'customer_lead'
|
||||
},
|
||||
'transactions': [
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@ frappe.ui.form.on('Quotation', {
|
||||
quotation_to: function(frm) {
|
||||
frm.trigger("set_label");
|
||||
frm.trigger("toggle_reqd_lead_customer");
|
||||
frm.trigger("set_dynamic_field_label");
|
||||
},
|
||||
|
||||
set_label: function(frm) {
|
||||
|
||||
Reference in New Issue
Block a user