2017-03-13 11:02:46 +00:00
|
|
|
frappe.ui.form.on("Communication", {
|
2017-10-05 08:49:45 +00:00
|
|
|
refresh: (frm) => {
|
|
|
|
// setup custom Make button only if Communication is Email
|
|
|
|
if(frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") {
|
|
|
|
frm.events.setup_custom_buttons(frm);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setup_custom_buttons: (frm) => {
|
2020-08-20 13:42:12 +00:00
|
|
|
let confirm_msg = "Are you sure you want to create {0} from this email?";
|
2017-03-13 11:02:46 +00:00
|
|
|
if(frm.doc.reference_doctype !== "Issue") {
|
2017-10-05 08:49:45 +00:00
|
|
|
frm.add_custom_button(__("Issue"), () => {
|
|
|
|
frappe.confirm(__(confirm_msg, [__("Issue")]), () => {
|
2017-03-13 11:02:46 +00:00
|
|
|
frm.trigger('make_issue_from_communication');
|
|
|
|
})
|
2020-08-10 07:09:42 +00:00
|
|
|
}, "Create");
|
2017-03-13 11:02:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 07:24:42 +00:00
|
|
|
if(!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) {
|
2017-10-05 08:49:45 +00:00
|
|
|
frm.add_custom_button(__("Lead"), () => {
|
|
|
|
frappe.confirm(__(confirm_msg, [__("Lead")]), () => {
|
2018-01-23 10:38:52 +00:00
|
|
|
frm.trigger('make_lead_from_communication');
|
2017-03-13 11:02:46 +00:00
|
|
|
})
|
2018-12-23 07:55:58 +00:00
|
|
|
}, __('Create'));
|
2017-03-13 11:02:46 +00:00
|
|
|
|
2017-10-05 08:49:45 +00:00
|
|
|
frm.add_custom_button(__("Opportunity"), () => {
|
|
|
|
frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => {
|
2017-03-13 11:02:46 +00:00
|
|
|
frm.trigger('make_opportunity_from_communication');
|
|
|
|
})
|
2018-12-23 07:55:58 +00:00
|
|
|
}, __('Create'));
|
2017-03-13 11:02:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-05 08:49:45 +00:00
|
|
|
make_lead_from_communication: (frm) => {
|
2017-03-13 11:02:46 +00:00
|
|
|
return frappe.call({
|
2019-04-19 05:50:41 +00:00
|
|
|
method: "erpnext.crm.doctype.lead.lead.make_lead_from_communication",
|
2017-03-13 11:02:46 +00:00
|
|
|
args: {
|
|
|
|
communication: frm.doc.name
|
|
|
|
},
|
|
|
|
freeze: true,
|
2017-10-05 08:49:45 +00:00
|
|
|
callback: (r) => {
|
2017-03-13 11:02:46 +00:00
|
|
|
if(r.message) {
|
|
|
|
frm.reload_doc()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2017-10-05 08:49:45 +00:00
|
|
|
make_issue_from_communication: (frm) => {
|
2017-03-13 11:02:46 +00:00
|
|
|
return frappe.call({
|
2019-04-19 05:50:41 +00:00
|
|
|
method: "erpnext.support.doctype.issue.issue.make_issue_from_communication",
|
2017-03-13 11:02:46 +00:00
|
|
|
args: {
|
|
|
|
communication: frm.doc.name
|
|
|
|
},
|
|
|
|
freeze: true,
|
2017-10-05 08:49:45 +00:00
|
|
|
callback: (r) => {
|
2017-03-13 11:02:46 +00:00
|
|
|
if(r.message) {
|
|
|
|
frm.reload_doc()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2017-10-05 08:49:45 +00:00
|
|
|
make_opportunity_from_communication: (frm) => {
|
2020-08-20 13:42:12 +00:00
|
|
|
const fields = [{
|
|
|
|
fieldtype: 'Link',
|
|
|
|
label: __('Select a Company'),
|
|
|
|
fieldname: 'company',
|
|
|
|
options: 'Company',
|
|
|
|
reqd: 1,
|
|
|
|
default: frappe.defaults.get_user_default("Company")
|
|
|
|
}];
|
|
|
|
|
|
|
|
frappe.prompt(fields, data => {
|
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.crm.doctype.opportunity.opportunity.make_opportunity_from_communication",
|
|
|
|
args: {
|
|
|
|
communication: frm.doc.name,
|
|
|
|
company: data.company
|
|
|
|
},
|
|
|
|
freeze: true,
|
|
|
|
callback: (r) => {
|
|
|
|
if(r.message) {
|
|
|
|
frm.reload_doc();
|
|
|
|
frappe.show_alert({
|
|
|
|
message: __("Opportunity {0} created",
|
|
|
|
['<a href="#Form/Opportunity/'+r.message+'">' + r.message + '</a>']),
|
|
|
|
indicator: 'green'
|
|
|
|
});
|
|
|
|
}
|
2017-03-13 11:02:46 +00:00
|
|
|
}
|
2020-08-20 13:42:12 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
'Create an Opportunity',
|
|
|
|
'Create');
|
2017-03-13 11:02:46 +00:00
|
|
|
}
|
2020-08-20 13:42:12 +00:00
|
|
|
});
|