mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 1 | frappe.ui.form.on("Communication", { |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 2 | refresh: (frm) => { |
| 3 | // setup custom Make button only if Communication is Email |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 4 | if (frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") { |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 5 | frm.events.setup_custom_buttons(frm); |
| 6 | } |
| 7 | }, |
| 8 | |
| 9 | setup_custom_buttons: (frm) => { |
Marica | c23797e | 2020-08-20 19:12:12 +0530 | [diff] [blame] | 10 | let confirm_msg = "Are you sure you want to create {0} from this email?"; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 11 | if (frm.doc.reference_doctype !== "Issue") { |
| 12 | frm.add_custom_button( |
| 13 | __("Issue"), |
| 14 | () => { |
| 15 | frappe.confirm(__(confirm_msg, [__("Issue")]), () => { |
| 16 | frm.trigger("make_issue_from_communication"); |
| 17 | }); |
| 18 | }, |
| 19 | __("Create") |
| 20 | ); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 21 | } |
| 22 | |
barredterra | d238751 | 2024-03-19 12:03:36 +0100 | [diff] [blame] | 23 | if (!["Lead", "Opportunity"].includes(frm.doc.reference_doctype)) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 24 | frm.add_custom_button( |
| 25 | __("Lead"), |
| 26 | () => { |
| 27 | frappe.confirm(__(confirm_msg, [__("Lead")]), () => { |
| 28 | frm.trigger("make_lead_from_communication"); |
| 29 | }); |
| 30 | }, |
| 31 | __("Create") |
| 32 | ); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 33 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 34 | frm.add_custom_button( |
| 35 | __("Opportunity"), |
| 36 | () => { |
| 37 | frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => { |
| 38 | frm.trigger("make_opportunity_from_communication"); |
| 39 | }); |
| 40 | }, |
| 41 | __("Create") |
| 42 | ); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 43 | } |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 44 | }, |
| 45 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 46 | make_lead_from_communication: (frm) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 47 | return frappe.call({ |
Rohit Waghchaure | 270d4e9 | 2019-04-19 11:20:41 +0530 | [diff] [blame] | 48 | method: "erpnext.crm.doctype.lead.lead.make_lead_from_communication", |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 49 | args: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 50 | communication: frm.doc.name, |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 51 | }, |
| 52 | freeze: true, |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 53 | callback: (r) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 54 | if (r.message) { |
| 55 | frm.reload_doc(); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 56 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 57 | }, |
| 58 | }); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 59 | }, |
| 60 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 61 | make_issue_from_communication: (frm) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 62 | return frappe.call({ |
Rohit Waghchaure | 270d4e9 | 2019-04-19 11:20:41 +0530 | [diff] [blame] | 63 | method: "erpnext.support.doctype.issue.issue.make_issue_from_communication", |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 64 | args: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 65 | communication: frm.doc.name, |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 66 | }, |
| 67 | freeze: true, |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 68 | callback: (r) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 69 | if (r.message) { |
| 70 | frm.reload_doc(); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 71 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 72 | }, |
| 73 | }); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 74 | }, |
| 75 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 76 | make_opportunity_from_communication: (frm) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 77 | const fields = [ |
| 78 | { |
| 79 | fieldtype: "Link", |
| 80 | label: __("Select a Company"), |
| 81 | fieldname: "company", |
| 82 | options: "Company", |
| 83 | reqd: 1, |
| 84 | default: frappe.defaults.get_user_default("Company"), |
| 85 | }, |
| 86 | ]; |
Marica | c23797e | 2020-08-20 19:12:12 +0530 | [diff] [blame] | 87 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 88 | frappe.prompt( |
| 89 | fields, |
| 90 | (data) => { |
| 91 | frappe.call({ |
| 92 | method: "erpnext.crm.doctype.opportunity.opportunity.make_opportunity_from_communication", |
| 93 | args: { |
| 94 | communication: frm.doc.name, |
| 95 | company: data.company, |
| 96 | }, |
| 97 | freeze: true, |
| 98 | callback: (r) => { |
| 99 | if (r.message) { |
| 100 | frm.reload_doc(); |
| 101 | frappe.show_alert({ |
| 102 | message: __("Opportunity {0} created", [ |
| 103 | '<a href="/app/opportunity/' + r.message + '">' + r.message + "</a>", |
| 104 | ]), |
| 105 | indicator: "green", |
| 106 | }); |
| 107 | } |
| 108 | }, |
| 109 | }); |
| 110 | }, |
| 111 | "Create an Opportunity", |
| 112 | "Create" |
| 113 | ); |
| 114 | }, |
Marica | c23797e | 2020-08-20 19:12:12 +0530 | [diff] [blame] | 115 | }); |