fix: Create Opportunity without Default Company from Email (#23097)
* fix: Create Opoortunity without Default Company from Email
* fix: Add Prompt to Select Company
* Update communication.js
Co-authored-by: Nabin Hait <nabinhait@gmail.com>
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index e152850..6096053 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -325,7 +325,7 @@
doc.save()
@frappe.whitelist()
-def make_opportunity_from_communication(communication, ignore_communication_links=False):
+def make_opportunity_from_communication(communication, company, ignore_communication_links=False):
from erpnext.crm.doctype.lead.lead import make_lead_from_communication
doc = frappe.get_doc("Communication", communication)
@@ -337,6 +337,7 @@
opportunity = frappe.get_doc({
"doctype": "Opportunity",
+ "company": company,
"opportunity_from": opportunity_from,
"party_name": lead
}).insert(ignore_permissions=True)
diff --git a/erpnext/public/js/communication.js b/erpnext/public/js/communication.js
index 9432d42..26e5ab8 100644
--- a/erpnext/public/js/communication.js
+++ b/erpnext/public/js/communication.js
@@ -7,7 +7,7 @@
},
setup_custom_buttons: (frm) => {
- let confirm_msg = "Are you sure you want to create {0} from this email";
+ let confirm_msg = "Are you sure you want to create {0} from this email?";
if(frm.doc.reference_doctype !== "Issue") {
frm.add_custom_button(__("Issue"), () => {
frappe.confirm(__(confirm_msg, [__("Issue")]), () => {
@@ -62,17 +62,36 @@
},
make_opportunity_from_communication: (frm) => {
- return frappe.call({
- method: "erpnext.crm.doctype.opportunity.opportunity.make_opportunity_from_communication",
- args: {
- communication: frm.doc.name
- },
- freeze: true,
- callback: (r) => {
- if(r.message) {
- frm.reload_doc()
+ 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'
+ });
+ }
}
- }
- })
+ });
+ },
+ 'Create an Opportunity',
+ 'Create');
}
-});
\ No newline at end of file
+});