fix: using frm instead of cur_frm

This commit is contained in:
Anupam 2021-08-27 13:09:52 +05:30
parent de488f68c0
commit d701ad5313
3 changed files with 33 additions and 30 deletions

View File

@ -51,7 +51,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
} }
} }
add_lead_to_prospect () { add_lead_to_prospect (frm) {
frappe.prompt([ frappe.prompt([
{ {
fieldname: 'prospect', fieldname: 'prospect',
@ -65,12 +65,12 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
frappe.call({ frappe.call({
method: 'erpnext.crm.doctype.lead.lead.add_lead_to_prospect', method: 'erpnext.crm.doctype.lead.lead.add_lead_to_prospect',
args: { args: {
'lead': cur_frm.doc.name, 'lead': frm.doc.name,
'prospect': data.prospect 'prospect': data.prospect
}, },
callback: function(r) { callback: function(r) {
if (!r.exc) { if (!r.exc) {
cur_frm.reload_doc(); frm.reload_doc();
} }
}, },
freeze: true, freeze: true,
@ -79,41 +79,41 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
}, __('Add Lead to Prospect'), __('Add')); }, __('Add Lead to Prospect'), __('Add'));
} }
make_customer () { make_customer (frm) {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_customer", method: "erpnext.crm.doctype.lead.lead.make_customer",
frm: cur_frm frm: frm
}) })
} }
make_opportunity () { make_opportunity (frm) {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity", method: "erpnext.crm.doctype.lead.lead.make_opportunity",
frm: cur_frm frm: frm
}) })
} }
make_quotation () { make_quotation (frm) {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_quotation", method: "erpnext.crm.doctype.lead.lead.make_quotation",
frm: cur_frm frm: frm
}) })
} }
make_prospect () { make_prospect (frm) {
frappe.model.with_doctype("Prospect", function() { frappe.model.with_doctype("Prospect", function() {
let prospect = frappe.model.get_new_doc("Prospect"); let prospect = frappe.model.get_new_doc("Prospect");
prospect.company_name = cur_frm.doc.company_name; prospect.company_name = frm.doc.company_name;
prospect.no_of_employees = cur_frm.doc.no_of_employees; prospect.no_of_employees = frm.doc.no_of_employees;
prospect.industry = cur_frm.doc.industry; prospect.industry = frm.doc.industry;
prospect.market_segment = cur_frm.doc.market_segment; prospect.market_segment = frm.doc.market_segment;
prospect.territory = cur_frm.doc.territory; prospect.territory = frm.doc.territory;
prospect.fax = cur_frm.doc.fax; prospect.fax = frm.doc.fax;
prospect.website = cur_frm.doc.website; prospect.website = frm.doc.website;
prospect.prospect_owner = cur_frm.doc.lead_owner; prospect.prospect_owner = frm.doc.lead_owner;
let lead_prospect_row = frappe.model.add_child(prospect, 'prospect_lead'); let lead_prospect_row = frappe.model.add_child(prospect, 'prospect_lead');
lead_prospect_row.lead = cur_frm.doc.name; lead_prospect_row.lead = frm.doc.name;
frappe.set_route("Form", "Prospect", prospect.name); frappe.set_route("Form", "Prospect", prospect.name);
}); });

View File

@ -2,29 +2,28 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('Prospect', { frappe.ui.form.on('Prospect', {
refresh () { refresh (frm) {
if (!cur_frm.is_new() && frappe.boot.user.can_create.includes("Customer")) { if (!frm.is_new() && frappe.boot.user.can_create.includes("Customer")) {
cur_frm.add_custom_button(__("Customer"), function() { frm.add_custom_button(__("Customer"), function() {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.prospect.prospect.make_customer", method: "erpnext.crm.doctype.prospect.prospect.make_customer",
frm: cur_frm frm: frm
}); });
}, __("Create")); }, __("Create"));
} }
if (!cur_frm.is_new() && frappe.boot.user.can_create.includes("Opportunity")) { if (!frm.is_new() && frappe.boot.user.can_create.includes("Opportunity")) {
cur_frm.add_custom_button(__("Opportunity"), function() { frm.add_custom_button(__("Opportunity"), function() {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.prospect.prospect.make_opportunity", method: "erpnext.crm.doctype.prospect.prospect.make_opportunity",
frm: cur_frm frm: frm
}); });
}, __("Create")); }, __("Create"));
} }
if (!cur_frm.is_new()) { if (!frm.is_new()) {
frappe.contacts.render_address_and_contact(cur_frm); frappe.contacts.render_address_and_contact(frm);
cur_frm.trigger('render_contact_day_html');
} else { } else {
frappe.contacts.clear_address_and_contact(cur_frm); frappe.contacts.clear_address_and_contact(frm);
} }
} }
}); });

View File

@ -4,8 +4,12 @@
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc from frappe.model.mapper import get_mapped_doc
from frappe.contacts.address_and_contact import load_address_and_contact
class Prospect(Document): class Prospect(Document):
def onload(self):
load_address_and_contact(self)
def validate(self): def validate(self):
self.update_lead_details() self.update_lead_details()