mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 21:19:19 +00:00
fix: Change dynamic_field name and minor fixes
This commit is contained in:
@@ -90,11 +90,11 @@ class Lead(SellingController):
|
||||
return frappe.db.get_value("Customer", {"lead_name": self.name})
|
||||
|
||||
def has_opportunity(self):
|
||||
return frappe.db.get_value("Opportunity", {"customer_lead": self.name, "status": ["!=", "Lost"]})
|
||||
return frappe.db.get_value("Opportunity", {"party_name": self.name, "status": ["!=", "Lost"]})
|
||||
|
||||
def has_quotation(self):
|
||||
return frappe.db.get_value("Quotation", {
|
||||
"customer_lead": self.name,
|
||||
"party_name": self.name,
|
||||
"docstatus": 1,
|
||||
"status": ["!=", "Lost"]
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ frappe.ui.form.on("Opportunity", {
|
||||
});
|
||||
},
|
||||
|
||||
customer_lead: function(frm) {
|
||||
party_name: function(frm) {
|
||||
if (frm.doc.opportunity_from == "Customer") {
|
||||
frm.trigger('set_contact_link');
|
||||
erpnext.utils.get_party_details(frm);
|
||||
@@ -38,7 +38,7 @@ frappe.ui.form.on("Opportunity", {
|
||||
contact_person: erpnext.utils.get_contact_details,
|
||||
|
||||
opportunity_from: function(frm) {
|
||||
frm.toggle_reqd("customer_lead", frm.doc.opportunity_from);
|
||||
frm.toggle_reqd("party_name", frm.doc.opportunity_from);
|
||||
frm.trigger("set_dynamic_field_label");
|
||||
},
|
||||
|
||||
@@ -81,22 +81,17 @@ frappe.ui.form.on("Opportunity", {
|
||||
},
|
||||
|
||||
set_contact_link: function(frm) {
|
||||
if(frm.doc.opportunity_from == "Customer" && frm.doc.customer_lead) {
|
||||
if(frm.doc.opportunity_from == "Customer" && frm.doc.party_name) {
|
||||
frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||
} else if(frm.doc.opportunity_from == "Lead" && frm.doc.customer_lead) {
|
||||
} else if(frm.doc.opportunity_from == "Lead" && frm.doc.party_name) {
|
||||
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");
|
||||
if (frm.doc.opportunity_from) {
|
||||
frm.set_df_property("party_name", "label", frm.doc.opportunity_from);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -162,7 +157,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.opportunity_from == 'Lead' && doc.customer_lead)
|
||||
if(doc.opportunity_from == 'Lead' && doc.party_name)
|
||||
cur_frm.cscript.lead(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
@@ -185,10 +180,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_lead);
|
||||
cur_frm.toggle_display("contact_info", doc.party_name);
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
|
||||
source_name: cur_frm.doc.customer_lead,
|
||||
source_name: cur_frm.doc.party_name,
|
||||
frm: cur_frm
|
||||
});
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
"columns": 0,
|
||||
"depends_on": "",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "customer_lead",
|
||||
"fieldname": "party_name",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
@@ -148,7 +148,7 @@
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
@@ -162,6 +162,7 @@
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "",
|
||||
"fetch_from": "party_name.customer_name",
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "customer_name",
|
||||
"fieldtype": "Data",
|
||||
@@ -1467,7 +1468,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2019-04-14 21:00:16.007097",
|
||||
"modified": "2019-04-25 17:10:09.399721",
|
||||
"modified_by": "Administrator",
|
||||
"module": "CRM",
|
||||
"name": "Opportunity",
|
||||
@@ -1515,11 +1516,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,party_name,opportunity_type,territory,company",
|
||||
"show_name_in_global_search": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"timeline_field": "customer_lead",
|
||||
"timeline_field": "party_name",
|
||||
"title_field": "title",
|
||||
"track_changes": 0,
|
||||
"track_seen": 1,
|
||||
|
||||
@@ -17,7 +17,7 @@ sender_field = "contact_email"
|
||||
class Opportunity(TransactionBase):
|
||||
def after_insert(self):
|
||||
if self.opportunity_from == "Lead":
|
||||
frappe.get_doc("Lead", self.customer_lead).set_status(update=True)
|
||||
frappe.get_doc("Lead", self.party_name).set_status(update=True)
|
||||
|
||||
def validate(self):
|
||||
self._prev = frappe._dict({
|
||||
@@ -29,9 +29,6 @@ class Opportunity(TransactionBase):
|
||||
|
||||
self.make_new_lead_if_required()
|
||||
|
||||
if not self.opportunity_from:
|
||||
frappe.throw(_("Opportunity From field is mandatory"))
|
||||
|
||||
self.validate_item_details()
|
||||
self.validate_uom_is_integer("uom", "qty")
|
||||
self.validate_lead_cust()
|
||||
@@ -45,7 +42,7 @@ class Opportunity(TransactionBase):
|
||||
|
||||
def make_new_lead_if_required(self):
|
||||
"""Set lead against new opportunity"""
|
||||
if (not self.get("customer_lead")) and self.contact_email:
|
||||
if (not self.get("party_name")) 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
|
||||
@@ -61,7 +58,7 @@ class Opportunity(TransactionBase):
|
||||
`tabDynamic Link`.link_doctype='Customer'
|
||||
""".format(self.contact_email), as_dict=True)
|
||||
if customer and customer[0].customer:
|
||||
self.customer_lead = customer[0].customer
|
||||
self.party_name = customer[0].customer
|
||||
self.opportunity_from = "Customer"
|
||||
return
|
||||
|
||||
@@ -90,7 +87,7 @@ class Opportunity(TransactionBase):
|
||||
lead_name = lead.name
|
||||
|
||||
self.opportunity_from = "Lead"
|
||||
self.customer_lead = lead_name
|
||||
self.party_name = lead_name
|
||||
|
||||
def declare_enquiry_lost(self,arg):
|
||||
if not self.has_active_quotation():
|
||||
@@ -137,10 +134,10 @@ class Opportunity(TransactionBase):
|
||||
return True
|
||||
|
||||
def validate_cust_name(self):
|
||||
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"])
|
||||
if self.party_name and self.opportunity_from == 'Customer':
|
||||
self.customer_name = frappe.db.get_value("Customer", self.party_name, "customer_name")
|
||||
elif self.party_name and self.opportunity_from == 'Lead':
|
||||
lead_name, company_name = frappe.db.get_value("Lead", self.party_name, ["lead_name", "company_name"])
|
||||
self.customer_name = company_name or lead_name
|
||||
|
||||
def on_update(self):
|
||||
@@ -153,16 +150,16 @@ class Opportunity(TransactionBase):
|
||||
opts.description = ""
|
||||
opts.contact_date = self.contact_date
|
||||
|
||||
if self.customer_lead and self.opportunity_from == 'Customer':
|
||||
if self.party_name and self.opportunity_from == 'Customer':
|
||||
if self.contact_person:
|
||||
opts.description = 'Contact '+cstr(self.contact_person)
|
||||
else:
|
||||
opts.description = 'Contact customer '+cstr(self.customer_lead)
|
||||
elif self.customer_lead and self.opportunity_from == 'Lead':
|
||||
opts.description = 'Contact customer '+cstr(self.party_name)
|
||||
elif self.party_name and self.opportunity_from == 'Lead':
|
||||
if self.contact_display:
|
||||
opts.description = 'Contact '+cstr(self.contact_display)
|
||||
else:
|
||||
opts.description = 'Contact lead '+cstr(self.customer_lead)
|
||||
opts.description = 'Contact lead '+cstr(self.party_name)
|
||||
|
||||
opts.subject = opts.description
|
||||
opts.description += '. By : ' + cstr(self.contact_by)
|
||||
@@ -187,14 +184,6 @@ class Opportunity(TransactionBase):
|
||||
for key in item_fields:
|
||||
if not d.get(key): d.set(key, item.get(key))
|
||||
|
||||
def validate_lead_cust(self):
|
||||
if self.opportunity_from == 'Lead':
|
||||
if not self.customer_lead:
|
||||
frappe.throw(_("Lead must be set if Opportunity is made from Lead"))
|
||||
elif self.opportunity_from == 'Customer':
|
||||
if not self.customer_lead:
|
||||
msgprint(_("Customer is mandatory if 'Opportunity From' is selected as Customer"), raise_exception=1)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_item_details(item_code):
|
||||
@@ -216,8 +205,11 @@ def make_quotation(source_name, target_doc=None):
|
||||
quotation = frappe.get_doc(target)
|
||||
|
||||
company_currency = frappe.get_cached_value('Company', quotation.company, "default_currency")
|
||||
party_account_currency = get_party_account_currency("Customer", quotation.customer_lead,
|
||||
quotation.company) if quotation.customer_lead else company_currency
|
||||
|
||||
if quotation.quotation_to == 'Customer' and quotation.party_name:
|
||||
party_account_currency = get_party_account_currency("Customer", quotation.party_name, quotation.company)
|
||||
else:
|
||||
party_account_currency = company_currency
|
||||
|
||||
quotation.currency = party_account_currency or company_currency
|
||||
|
||||
|
||||
@@ -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.customer_lead)
|
||||
self.assertTrue(opp_doc.party_name)
|
||||
self.assertEqual(opp_doc.opportunity_from, "Lead")
|
||||
self.assertEqual(frappe.db.get_value("Lead", opp_doc.customer_lead, "email_id"),
|
||||
self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"),
|
||||
'new.opportunity@example.com')
|
||||
|
||||
# create new customer and create new contact against 'new.opportunity@example.com'
|
||||
customer = make_customer(opp_doc.customer_lead).insert(ignore_permissions=True)
|
||||
customer = make_customer(opp_doc.party_name).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_lead)
|
||||
self.assertTrue(opp_doc.party_name)
|
||||
self.assertEqual(opp_doc.opportunity_from, "Customer")
|
||||
self.assertEqual(opp_doc.customer_lead, customer.name)
|
||||
self.assertEqual(opp_doc.party_name, customer.name)
|
||||
|
||||
def make_opportunity(**args):
|
||||
args = frappe._dict(args)
|
||||
@@ -72,10 +72,10 @@ def make_opportunity(**args):
|
||||
})
|
||||
|
||||
if opp_doc.opportunity_from == 'Customer':
|
||||
opp_doc.customer_lead= args.customer or "_Test Customer"
|
||||
opp_doc.party_name= args.customer or "_Test Customer"
|
||||
|
||||
if opp_doc.opportunity_from == 'Lead':
|
||||
opp_doc.customer_lead = args.lead or "_T-Lead-00001"
|
||||
opp_doc.party_name = args.lead or "_T-Lead-00001"
|
||||
|
||||
if args.with_items:
|
||||
opp_doc.append('items', {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"name": "_Test Opportunity 1",
|
||||
"opportunity_from": "Lead",
|
||||
"enquiry_type": "Sales",
|
||||
"customer_lead": "_T-Lead-00001",
|
||||
"party_name": "_T-Lead-00001",
|
||||
"transaction_date": "2013-12-12",
|
||||
"items": [{
|
||||
"item_name": "Test Item",
|
||||
|
||||
Reference in New Issue
Block a user