diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 687caaaad83..d3d31b8e702 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -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", {"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", { - "lead": self.name, + "party_name": self.name, "docstatus": 1, "status": ["!=", "Lost"] diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index abe560ba5ee..88ce10c9561 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -9,15 +9,22 @@ frappe.ui.form.on("Opportunity", { frm.custom_make_buttons = { 'Quotation': 'Quotation', 'Supplier Quotation': 'Supplier Quotation' - } - }, - customer: function(frm) { - frm.trigger('set_contact_link'); - erpnext.utils.get_party_details(frm); + }, + + frm.set_query("opportunity_from", function() { + return{ + "filters": { + "name": ["in", ["Customer", "Lead"]], + } + } + }); }, - lead: function(frm) { - frm.trigger('set_contact_link'); + party_name: function(frm) { + if (frm.doc.opportunity_from == "Customer") { + frm.trigger('set_contact_link'); + erpnext.utils.get_party_details(frm); + } }, with_items: function(frm) { @@ -30,15 +37,14 @@ frappe.ui.form.on("Opportunity", { contact_person: erpnext.utils.get_contact_details, - enquiry_from: function(frm) { - frm.toggle_reqd("lead", frm.doc.enquiry_from==="Lead"); - frm.toggle_reqd("customer", frm.doc.enquiry_from==="Customer"); + opportunity_from: function(frm) { + frm.toggle_reqd("party_name", frm.doc.opportunity_from); + frm.trigger("set_dynamic_field_label"); }, refresh: function(frm) { var doc = frm.doc; - frm.events.enquiry_from(frm); - frm.trigger('set_contact_link'); + frm.events.opportunity_from(frm); frm.trigger('toggle_mandatory'); erpnext.toggle_naming_series(); @@ -75,13 +81,20 @@ frappe.ui.form.on("Opportunity", { }, set_contact_link: function(frm) { - if(frm.doc.customer) { + if(frm.doc.opportunity_from == "Customer" && frm.doc.party_name) { frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'} - } else if(frm.doc.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) { + frm.set_df_property("party_name", "label", frm.doc.opportunity_from); + } + }, + make_supplier_quotation: function(frm) { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.opportunity.opportunity.make_supplier_quotation", @@ -97,10 +110,6 @@ frappe.ui.form.on("Opportunity", { // TODO commonify this code erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({ onload: function() { - if(!this.frm.doc.enquiry_from && this.frm.doc.customer) - this.frm.doc.enquiry_from = "Customer"; - if(!this.frm.doc.enquiry_from && this.frm.doc.lead) - this.frm.doc.enquiry_from = "Lead"; if(!this.frm.doc.status) set_multiple(this.frm.doc.doctype, this.frm.doc.name, { status:'Open' }); @@ -148,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.enquiry_from == 'Lead' && doc.lead) + if(doc.opportunity_from == 'Lead' && doc.party_name) cur_frm.cscript.lead(doc, cdt, cdn); } @@ -171,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 || doc.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.lead, + source_name: cur_frm.doc.party_name, frm: cur_frm }); } diff --git a/erpnext/crm/doctype/opportunity/opportunity.json b/erpnext/crm/doctype/opportunity/opportunity.json index fc86842e01f..e3f43f40fd3 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.json +++ b/erpnext/crm/doctype/opportunity/opportunity.json @@ -21,6 +21,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "from_section", "fieldtype": "Section Break", "hidden": 0, @@ -54,6 +55,7 @@ "collapsible": 0, "columns": 0, "default": "", + "fetch_if_empty": 0, "fieldname": "naming_series", "fieldtype": "Select", "hidden": 0, @@ -88,8 +90,9 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "enquiry_from", - "fieldtype": "Select", + "fetch_if_empty": 0, + "fieldname": "opportunity_from", + "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -102,7 +105,7 @@ "no_copy": 0, "oldfieldname": "enquiry_from", "oldfieldtype": "Select", - "options": "\nLead\nCustomer", + "options": "DocType", "permlevel": 0, "print_hide": 1, "print_hide_if_no_value": 0, @@ -122,9 +125,10 @@ "bold": 1, "collapsible": 0, "columns": 0, - "depends_on": "eval:doc.enquiry_from===\"Customer\"", - "fieldname": "customer", - "fieldtype": "Link", + "depends_on": "", + "fetch_if_empty": 0, + "fieldname": "party_name", + "fieldtype": "Dynamic Link", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -132,54 +136,19 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 1, - "label": "Customer", + "label": "Customer/Lead", "length": 0, "no_copy": 0, "oldfieldname": "customer", "oldfieldtype": "Link", - "options": "Customer", + "options": "opportunity_from", "permlevel": 0, "print_hide": 1, "print_hide_if_no_value": 0, "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:doc.enquiry_from===\"Lead\"", - "fieldname": "lead", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 1, - "label": "Lead", - "length": 0, - "no_copy": 0, - "oldfieldname": "lead", - "oldfieldtype": "Link", - "options": "Lead", - "permlevel": 0, - "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, + "reqd": 1, "search_index": 0, "set_only_once": 0, "translatable": 0, @@ -193,6 +162,8 @@ "collapsible": 0, "columns": 0, "depends_on": "", + "fetch_from": "", + "fetch_if_empty": 0, "fieldname": "customer_name", "fieldtype": "Data", "hidden": 0, @@ -224,6 +195,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break0", "fieldtype": "Column Break", "hidden": 0, @@ -256,6 +228,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "title", "fieldtype": "Data", "hidden": 1, @@ -289,6 +262,7 @@ "collapsible": 0, "columns": 0, "default": "Sales", + "fetch_if_empty": 0, "fieldname": "opportunity_type", "fieldtype": "Link", "hidden": 0, @@ -324,6 +298,7 @@ "collapsible": 0, "columns": 0, "default": "Open", + "fetch_if_empty": 0, "fieldname": "status", "fieldtype": "Select", "hidden": 0, @@ -359,6 +334,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.status===\"Lost\"", + "fetch_if_empty": 0, "fieldname": "order_lost_reason", "fieldtype": "Small Text", "hidden": 0, @@ -390,6 +366,7 @@ "bold": 1, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "mins_to_first_response", "fieldtype": "Float", "hidden": 0, @@ -423,6 +400,7 @@ "collapsible": 1, "collapsible_depends_on": "contact_by", "columns": 0, + "fetch_if_empty": 0, "fieldname": "next_contact", "fieldtype": "Section Break", "hidden": 0, @@ -456,6 +434,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "contact_by", "fieldtype": "Link", "hidden": 0, @@ -492,6 +471,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "contact_date", "fieldtype": "Datetime", "hidden": 0, @@ -525,6 +505,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break2", "fieldtype": "Column Break", "hidden": 0, @@ -557,6 +538,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "to_discuss", "fieldtype": "Small Text", "hidden": 0, @@ -590,6 +572,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "section_break_14", "fieldtype": "Section Break", "hidden": 0, @@ -622,6 +605,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "currency", "fieldtype": "Link", "hidden": 0, @@ -655,6 +639,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "opportunity_amount", "fieldtype": "Currency", "hidden": 0, @@ -687,6 +672,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "with_items", "fieldtype": "Check", "hidden": 0, @@ -719,6 +705,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_17", "fieldtype": "Column Break", "hidden": 0, @@ -751,6 +738,7 @@ "collapsible": 0, "columns": 0, "default": "Prospecting", + "fetch_if_empty": 0, "fieldname": "sales_stage", "fieldtype": "Link", "hidden": 0, @@ -785,6 +773,7 @@ "collapsible": 0, "columns": 0, "default": "100", + "fetch_if_empty": 0, "fieldname": "probability", "fieldtype": "Percent", "hidden": 0, @@ -818,6 +807,7 @@ "collapsible": 0, "columns": 0, "depends_on": "with_items", + "fetch_if_empty": 0, "fieldname": "items_section", "fieldtype": "Section Break", "hidden": 0, @@ -852,6 +842,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "items", "fieldtype": "Table", "hidden": 0, @@ -888,6 +879,7 @@ "collapsible_depends_on": "next_contact_by", "columns": 0, "depends_on": "eval:doc.lead || doc.customer", + "fetch_if_empty": 0, "fieldname": "contact_info", "fieldtype": "Section Break", "hidden": 0, @@ -921,6 +913,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.customer || doc.lead", + "fetch_if_empty": 0, "fieldname": "customer_address", "fieldtype": "Link", "hidden": 0, @@ -953,6 +946,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "address_display", "fieldtype": "Small Text", "hidden": 1, @@ -988,6 +982,7 @@ "columns": 0, "depends_on": "customer", "description": "", + "fetch_if_empty": 0, "fieldname": "territory", "fieldtype": "Link", "hidden": 0, @@ -1022,6 +1017,7 @@ "columns": 0, "depends_on": "customer", "description": "", + "fetch_if_empty": 0, "fieldname": "customer_group", "fieldtype": "Link", "hidden": 0, @@ -1056,6 +1052,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break3", "fieldtype": "Column Break", "hidden": 0, @@ -1087,6 +1084,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.lead || doc.customer", + "fetch_if_empty": 0, "fieldname": "contact_person", "fieldtype": "Link", "hidden": 0, @@ -1120,6 +1118,7 @@ "collapsible": 0, "columns": 0, "depends_on": "customer", + "fetch_if_empty": 0, "fieldname": "contact_display", "fieldtype": "Small Text", "hidden": 0, @@ -1152,6 +1151,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.lead || doc.customer", + "fetch_if_empty": 0, "fieldname": "contact_email", "fieldtype": "Data", "hidden": 0, @@ -1184,6 +1184,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.lead || doc.customer", + "fetch_if_empty": 0, "fieldname": "contact_mobile", "fieldtype": "Small Text", "hidden": 0, @@ -1216,6 +1217,7 @@ "collapsible": 1, "collapsible_depends_on": "", "columns": 0, + "fetch_if_empty": 0, "fieldname": "more_info", "fieldtype": "Section Break", "hidden": 0, @@ -1249,6 +1251,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "source", "fieldtype": "Link", "hidden": 0, @@ -1285,6 +1288,7 @@ "columns": 0, "depends_on": "eval: doc.source==\"Campaign\"", "description": "Enter name of campaign if source of enquiry is campaign", + "fetch_if_empty": 0, "fieldname": "campaign", "fieldtype": "Link", "hidden": 0, @@ -1319,6 +1323,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break1", "fieldtype": "Column Break", "hidden": 0, @@ -1351,6 +1356,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "company", "fieldtype": "Link", "hidden": 0, @@ -1386,6 +1392,7 @@ "collapsible": 0, "columns": 0, "default": "Today", + "fetch_if_empty": 0, "fieldname": "transaction_date", "fieldtype": "Date", "hidden": 0, @@ -1420,6 +1427,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "amended_from", "fieldtype": "Link", "hidden": 0, @@ -1460,7 +1468,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-10-01 09:28:43.990999", + "modified": "2019-04-25 18:55:43.874656", "modified_by": "Administrator", "module": "CRM", "name": "Opportunity", @@ -1508,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", + "timeline_field": "party_name", "title_field": "title", "track_changes": 0, "track_seen": 1, diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index c5aae9cd5f3..dad249213c7 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -16,8 +16,8 @@ sender_field = "contact_email" class Opportunity(TransactionBase): def after_insert(self): - if self.lead: - frappe.get_doc("Lead", self.lead).set_status(update=True) + if self.opportunity_from == "Lead": + frappe.get_doc("Lead", self.party_name).set_status(update=True) def validate(self): self._prev = frappe._dict({ @@ -29,12 +29,8 @@ class Opportunity(TransactionBase): self.make_new_lead_if_required() - if not self.enquiry_from: - frappe.throw(_("Opportunity From field is mandatory")) - self.validate_item_details() self.validate_uom_is_integer("uom", "qty") - self.validate_lead_cust() self.validate_cust_name() if not self.title: @@ -45,7 +41,7 @@ class Opportunity(TransactionBase): def make_new_lead_if_required(self): """Set lead against new opportunity""" - if not (self.lead or self.customer) 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,8 +57,8 @@ class Opportunity(TransactionBase): `tabDynamic Link`.link_doctype='Customer' """.format(self.contact_email), as_dict=True) if customer and customer[0].customer: - self.customer = customer[0].customer - self.enquiry_from = "Customer" + self.party_name = customer[0].customer + self.opportunity_from = "Customer" return lead_name = frappe.db.get_value("Lead", {"email_id": self.contact_email}) @@ -89,8 +85,8 @@ class Opportunity(TransactionBase): lead.insert(ignore_permissions=True) lead_name = lead.name - self.enquiry_from = "Lead" - self.lead = lead_name + self.opportunity_from = "Lead" + self.party_name = lead_name def declare_enquiry_lost(self,arg): if not self.has_active_quotation(): @@ -137,10 +133,10 @@ class Opportunity(TransactionBase): return True def validate_cust_name(self): - if self.customer: - self.customer_name = frappe.db.get_value("Customer", self.customer, "customer_name") - elif self.lead: - lead_name, company_name = frappe.db.get_value("Lead", self.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 +149,16 @@ class Opportunity(TransactionBase): opts.description = "" opts.contact_date = self.contact_date - if self.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) - elif self.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.lead) + opts.description = 'Contact lead '+cstr(self.party_name) opts.subject = opts.description opts.description += '. By : ' + cstr(self.contact_by) @@ -187,17 +183,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.enquiry_from == 'Lead': - if not self.lead: - frappe.throw(_("Lead must be set if Opportunity is made from Lead")) - else: - self.customer = None - elif self.enquiry_from == 'Customer': - if not self.customer: - msgprint(_("Customer is mandatory if 'Opportunity From' is selected as Customer"), raise_exception=1) - else: - self.lead = None @frappe.whitelist() def get_item_details(item_code): @@ -219,8 +204,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, - quotation.company) if quotation.customer 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 @@ -246,7 +234,7 @@ def make_quotation(source_name, target_doc=None): "Opportunity": { "doctype": "Quotation", "field_map": { - "enquiry_from": "quotation_to", + "opportunity_from": "quotation_to", "opportunity_type": "order_type", "name": "enq_no", } diff --git a/erpnext/crm/doctype/opportunity/opportunity_list.js b/erpnext/crm/doctype/opportunity/opportunity_list.js index 0dbbf8add1c..9712fb04c56 100644 --- a/erpnext/crm/doctype/opportunity/opportunity_list.js +++ b/erpnext/crm/doctype/opportunity/opportunity_list.js @@ -1,5 +1,5 @@ frappe.listview_settings['Opportunity'] = { - add_fields: ["customer_name", "opportunity_type", "enquiry_from", "status"], + add_fields: ["customer_name", "opportunity_type", "opportunity_from", "status"], get_indicator: function(doc) { var indicator = [__(doc.status), frappe.utils.guess_colour(doc.status), "status,=," + doc.status]; if(doc.status=="Quotation") { diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.js b/erpnext/crm/doctype/opportunity/test_opportunity.js index f2b04f86474..45b97ddc4d1 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.js +++ b/erpnext/crm/doctype/opportunity/test_opportunity.js @@ -6,7 +6,7 @@ QUnit.test("test: opportunity", function (assert) { () => frappe.timeout(1), () => frappe.click_button('New'), () => frappe.timeout(1), - () => cur_frm.set_value('enquiry_from', 'Customer'), + () => cur_frm.set_value('opportunity_from', 'Customer'), () => cur_frm.set_value('customer', 'Test Customer 1'), // check items diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index ef2945b41f9..61dac90cd9f 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -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.lead) - self.assertEqual(opp_doc.enquiry_from, "Lead") - self.assertEqual(frappe.db.get_value("Lead", opp_doc.lead, "email_id"), + self.assertTrue(opp_doc.party_name) + self.assertEqual(opp_doc.opportunity_from, "Lead") + 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.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) - self.assertEqual(opp_doc.enquiry_from, "Customer") - self.assertEqual(opp_doc.customer, customer.name) + self.assertTrue(opp_doc.party_name) + self.assertEqual(opp_doc.opportunity_from, "Customer") + self.assertEqual(opp_doc.party_name, customer.name) def make_opportunity(**args): args = frappe._dict(args) @@ -65,17 +65,17 @@ def make_opportunity(**args): opp_doc = frappe.get_doc({ "doctype": "Opportunity", "company": args.company or "_Test Company", - "enquiry_from": args.enquiry_from or "Customer", + "opportunity_from": args.opportunity_from or "Customer", "opportunity_type": "Sales", "with_items": args.with_items or 0, "transaction_date": today() }) - if opp_doc.enquiry_from == 'Customer': - opp_doc.customer = args.customer or "_Test Customer" + if opp_doc.opportunity_from == 'Customer': + opp_doc.party_name= args.customer or "_Test Customer" - if opp_doc.enquiry_from == 'Lead': - opp_doc.customer = args.lead or "_T-Lead-00001" + if opp_doc.opportunity_from == 'Lead': + opp_doc.party_name = args.lead or "_T-Lead-00001" if args.with_items: opp_doc.append('items', { diff --git a/erpnext/crm/doctype/opportunity/test_records.json b/erpnext/crm/doctype/opportunity/test_records.json index 84dfea515a0..a1e0ad921b4 100644 --- a/erpnext/crm/doctype/opportunity/test_records.json +++ b/erpnext/crm/doctype/opportunity/test_records.json @@ -2,9 +2,9 @@ { "doctype": "Opportunity", "name": "_Test Opportunity 1", - "enquiry_from": "Lead", + "opportunity_from": "Lead", "enquiry_type": "Sales", - "lead": "_T-Lead-00001", + "party_name": "_T-Lead-00001", "transaction_date": "2013-12-12", "items": [{ "item_name": "Test Item", diff --git a/erpnext/crm/report/lead_conversion_time/lead_conversion_time.py b/erpnext/crm/report/lead_conversion_time/lead_conversion_time.py index d9ee30ec1ae..d91b9c5607d 100644 --- a/erpnext/crm/report/lead_conversion_time/lead_conversion_time.py +++ b/erpnext/crm/report/lead_conversion_time/lead_conversion_time.py @@ -66,7 +66,7 @@ def get_columns(): def get_communication_details(filters): communication_count = None communication_list = [] - opportunities = frappe.db.get_values('Opportunity', {'enquiry_from': 'Lead'},\ + opportunities = frappe.db.get_values('Opportunity', {'opportunity_from': 'Lead'},\ ['name', 'customer_name', 'lead', 'contact_email'], as_dict=1) for d in opportunities: diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py index 69ba9007a61..3809c1f0924 100644 --- a/erpnext/demo/user/sales.py +++ b/erpnext/demo/user/sales.py @@ -56,7 +56,7 @@ def work(domain="Manufacturing"): def make_opportunity(domain): b = frappe.get_doc({ "doctype": "Opportunity", - "enquiry_from": "Customer", + "opportunity_from": "Customer", "customer": get_random("Customer"), "opportunity_type": "Sales", "with_items": 1, diff --git a/erpnext/hub_node/legacy.py b/erpnext/hub_node/legacy.py index 9daee2752fa..95ada76a6a5 100644 --- a/erpnext/hub_node/legacy.py +++ b/erpnext/hub_node/legacy.py @@ -28,7 +28,7 @@ def make_opportunity(buyer_name, email_id): lead.save(ignore_permissions=True) o = frappe.new_doc("Opportunity") - o.enquiry_from = "Lead" + o.opportunity_from = "Lead" o.lead = frappe.get_all("Lead", filters={"email_id": email_id}, fields = ["name"])[0]["name"] o.save(ignore_permissions=True) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 7d015527456..d07457a956e 100755 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -590,6 +590,7 @@ erpnext.patches.v10_0.item_barcode_childtable_migrate # 16-02-2019 erpnext.patches.v11_0.make_italian_localization_fields # 26-03-2019 erpnext.patches.v11_1.make_job_card_time_logs erpnext.patches.v11_1.set_variant_based_on +erpnext.patches.v11_1.move_customer_lead_to_dynamic_column erpnext.patches.v11_1.woocommerce_set_creation_user erpnext.patches.v11_1.delete_bom_browser erpnext.patches.v11_1.set_salary_details_submittable diff --git a/erpnext/patches/v11_1/move_customer_lead_to_dynamic_column.py b/erpnext/patches/v11_1/move_customer_lead_to_dynamic_column.py new file mode 100644 index 00000000000..5b1251c31cf --- /dev/null +++ b/erpnext/patches/v11_1/move_customer_lead_to_dynamic_column.py @@ -0,0 +1,14 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doctype("Quotation") + frappe.db.sql(""" UPDATE `tabQuotation` set party_name = lead WHERE quotation_to = 'Lead' """) + frappe.db.sql(""" UPDATE `tabQuotation` set party_name = customer WHERE quotation_to = 'Customer' """) + + frappe.reload_doctype("Opportunity") + frappe.db.sql(""" UPDATE `tabOpportunity` set party_name = lead WHERE opportunity_from = 'Lead' """) + frappe.db.sql(""" UPDATE `tabOpportunity` set party_name = customer WHERE opportunity_from = 'Customer' """) \ No newline at end of file diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 2970d7a5e82..f815e5f97cb 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -104,10 +104,6 @@ class Customer(TransactionBase): if self.lead_name: frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False) - for doctype in ('Opportunity', 'Quotation'): - for d in frappe.get_all(doctype, {'lead': self.lead_name}): - frappe.db.set_value(doctype, d.name, 'customer', self.name, update_modified=False) - def create_lead_address_contact(self): if self.lead_name: # assign lead address to customer (if already not set) diff --git a/erpnext/selling/doctype/customer/customer_dashboard.py b/erpnext/selling/doctype/customer/customer_dashboard.py index f2f430a61e2..6d6c86fbefd 100644 --- a/erpnext/selling/doctype/customer/customer_dashboard.py +++ b/erpnext/selling/doctype/customer/customer_dashboard.py @@ -6,6 +6,10 @@ def get_data(): 'heatmap': True, 'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'), 'fieldname': 'customer', + 'non_standard_fieldnames': { + 'Quotation': 'party_name', + 'Opportunity': 'party_name' + }, 'transactions': [ { 'label': _('Pre Sales'), diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 6f7bfb3febf..3116e65b686 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -8,15 +8,27 @@ frappe.ui.form.on('Quotation', { setup: function(frm) { frm.custom_make_buttons = { 'Sales Order': 'Make Sales Order' - } + }, + + frm.set_query("quotation_to", function() { + return{ + "filters": { + "name": ["in", ["Customer", "Lead"]], + } + } + }); + }, refresh: function(frm) { frm.trigger("set_label"); + frm.trigger("set_dynamic_field_label"); }, quotation_to: function(frm) { frm.trigger("set_label"); + frm.trigger("toggle_reqd_lead_customer"); + frm.trigger("set_dynamic_field_label"); }, set_label: function(frm) { @@ -28,10 +40,6 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ onload: function(doc, dt, dn) { var me = this; this._super(doc, dt, dn); - if(doc.customer && !doc.quotation_to) - doc.quotation_to = "Customer"; - else if(doc.lead && !doc.quotation_to) - doc.quotation_to = "Lead"; }, refresh: function(doc, dt, dn) { @@ -97,25 +105,28 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ }, - quotation_to: function() { - var me = this; - if (this.frm.doc.quotation_to == "Lead") { - this.frm.set_value("customer", null); - this.frm.set_value("contact_person", null); - } else if (this.frm.doc.quotation_to == "Customer") { - this.frm.set_value("lead", null); + set_dynamic_field_label: function(){ + if (this.frm.doc.quotation_to == "Customer") + { + this.frm.set_df_property("party_name", "label", "Customer"); + this.frm.fields_dict.party_name.get_query = null; } - this.toggle_reqd_lead_customer(); + if (this.frm.doc.quotation_to == "Lead") + { + this.frm.set_df_property("party_name", "label", "Lead"); + + this.frm.fields_dict.party_name.get_query = function() { + return{ query: "erpnext.controllers.queries.lead_query" } + } + } }, toggle_reqd_lead_customer: function() { var me = this; - this.frm.toggle_reqd("lead", this.frm.doc.quotation_to == "Lead"); - this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer"); - // to overwrite the customer_filter trigger from queries.js + this.frm.toggle_reqd("party_name", this.frm.doc.quotation_to); this.frm.set_query('customer_address', erpnext.queries.address_query); this.frm.set_query('shipping_address_name', erpnext.queries.address_query); }, @@ -163,10 +174,6 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ cur_frm.script_manager.make(erpnext.selling.QuotationController); -cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) { - return{ query: "erpnext.controllers.queries.lead_query" } -} - cur_frm.cscript['Make Sales Order'] = function() { frappe.model.open_mapped_doc({ method: "erpnext.selling.doctype.quotation.quotation.make_sales_order", diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json index 6cc09933e8e..4b247075451 100644 --- a/erpnext/selling/doctype/quotation/quotation.json +++ b/erpnext/selling/doctype/quotation/quotation.json @@ -20,6 +20,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "customer_section", "fieldtype": "Section Break", "hidden": 0, @@ -53,6 +54,7 @@ "collapsible": 0, "columns": 0, "default": "{customer_name}", + "fetch_if_empty": 0, "fieldname": "title", "fieldtype": "Data", "hidden": 1, @@ -86,6 +88,7 @@ "collapsible": 0, "columns": 0, "default": "", + "fetch_if_empty": 0, "fieldname": "naming_series", "fieldtype": "Select", "hidden": 0, @@ -121,8 +124,9 @@ "collapsible": 0, "columns": 0, "default": "Customer", + "fetch_if_empty": 0, "fieldname": "quotation_to", - "fieldtype": "Select", + "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -135,7 +139,7 @@ "no_copy": 0, "oldfieldname": "quotation_to", "oldfieldtype": "Select", - "options": "\nLead\nCustomer", + "options": "DocType", "permlevel": 0, "print_hide": 1, "print_hide_if_no_value": 0, @@ -155,9 +159,10 @@ "bold": 1, "collapsible": 0, "columns": 0, - "depends_on": "eval:doc.quotation_to == \"Customer\"", - "fieldname": "customer", - "fieldtype": "Link", + "depends_on": "", + "fetch_if_empty": 0, + "fieldname": "party_name", + "fieldtype": "Dynamic Link", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -165,12 +170,12 @@ "in_global_search": 1, "in_list_view": 0, "in_standard_filter": 1, - "label": "Customer", + "label": "Customer/Lead", "length": 0, "no_copy": 0, "oldfieldname": "customer", "oldfieldtype": "Link", - "options": "Customer", + "options": "quotation_to", "permlevel": 0, "print_hide": 1, "print_hide_if_no_value": 0, @@ -183,41 +188,6 @@ "translatable": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:doc.quotation_to == \"Lead\"", - "fieldname": "lead", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 1, - "label": "Lead", - "length": 0, - "no_copy": 0, - "oldfieldname": "lead", - "oldfieldtype": "Link", - "options": "Lead", - "permlevel": 0, - "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, { "allow_bulk_edit": 0, "allow_in_quick_entry": 0, @@ -226,6 +196,7 @@ "collapsible": 0, "columns": 0, "fetch_from": "customer.customer_name", + "fetch_if_empty": 0, "fieldname": "customer_name", "fieldtype": "Data", "hidden": 1, @@ -258,6 +229,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break1", "fieldtype": "Column Break", "hidden": 0, @@ -290,6 +262,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "amended_from", "fieldtype": "Link", "hidden": 0, @@ -326,6 +299,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "company", "fieldtype": "Link", "hidden": 0, @@ -362,6 +336,7 @@ "collapsible": 0, "columns": 0, "default": "Today", + "fetch_if_empty": 0, "fieldname": "transaction_date", "fieldtype": "Date", "hidden": 0, @@ -396,6 +371,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "valid_till", "fieldtype": "Date", "hidden": 0, @@ -429,6 +405,7 @@ "collapsible": 0, "columns": 0, "default": "Sales", + "fetch_if_empty": 0, "fieldname": "order_type", "fieldtype": "Select", "hidden": 0, @@ -465,6 +442,7 @@ "collapsible_depends_on": "", "columns": 0, "depends_on": "eval:(doc.customer || doc.lead)", + "fetch_if_empty": 0, "fieldname": "contact_section", "fieldtype": "Section Break", "hidden": 0, @@ -497,6 +475,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "customer_address", "fieldtype": "Link", "hidden": 0, @@ -529,6 +508,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "address_display", "fieldtype": "Small Text", "hidden": 0, @@ -563,6 +543,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.customer", + "fetch_if_empty": 0, "fieldname": "contact_person", "fieldtype": "Link", "hidden": 0, @@ -597,6 +578,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "contact_display", "fieldtype": "Small Text", "hidden": 0, @@ -628,6 +610,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "contact_mobile", "fieldtype": "Small Text", "hidden": 0, @@ -659,6 +642,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "contact_email", "fieldtype": "Data", "hidden": 1, @@ -692,6 +676,7 @@ "collapsible": 0, "columns": 0, "depends_on": "customer", + "fetch_if_empty": 0, "fieldname": "col_break98", "fieldtype": "Column Break", "hidden": 0, @@ -723,6 +708,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "shipping_address_name", "fieldtype": "Link", "hidden": 0, @@ -755,6 +741,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "shipping_address", "fieldtype": "Small Text", "hidden": 0, @@ -788,6 +775,7 @@ "columns": 0, "depends_on": "customer", "description": "", + "fetch_if_empty": 0, "fieldname": "customer_group", "fieldtype": "Link", "hidden": 1, @@ -823,6 +811,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "territory", "fieldtype": "Link", "hidden": 0, @@ -855,6 +844,7 @@ "bold": 0, "collapsible": 1, "columns": 0, + "fetch_if_empty": 0, "fieldname": "currency_and_price_list", "fieldtype": "Section Break", "hidden": 0, @@ -887,6 +877,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "currency", "fieldtype": "Link", "hidden": 0, @@ -923,6 +914,7 @@ "collapsible": 0, "columns": 0, "description": "Rate at which customer's currency is converted to company's base currency", + "fetch_if_empty": 0, "fieldname": "conversion_rate", "fieldtype": "Float", "hidden": 0, @@ -958,6 +950,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break2", "fieldtype": "Column Break", "hidden": 0, @@ -989,6 +982,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "selling_price_list", "fieldtype": "Link", "hidden": 0, @@ -1024,6 +1018,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "price_list_currency", "fieldtype": "Link", "hidden": 0, @@ -1057,6 +1052,7 @@ "collapsible": 0, "columns": 0, "description": "Rate at which Price list currency is converted to company's base currency", + "fetch_if_empty": 0, "fieldname": "plc_conversion_rate", "fieldtype": "Float", "hidden": 0, @@ -1089,6 +1085,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "ignore_pricing_rule", "fieldtype": "Check", "hidden": 0, @@ -1120,6 +1117,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "items_section", "fieldtype": "Section Break", "hidden": 0, @@ -1153,6 +1151,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "items", "fieldtype": "Table", "hidden": 0, @@ -1188,6 +1187,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "sec_break23", "fieldtype": "Section Break", "hidden": 0, @@ -1218,6 +1218,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "total_qty", "fieldtype": "Float", "hidden": 0, @@ -1250,6 +1251,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_total", "fieldtype": "Currency", "hidden": 0, @@ -1283,6 +1285,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_net_total", "fieldtype": "Currency", "hidden": 0, @@ -1318,6 +1321,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_28", "fieldtype": "Column Break", "hidden": 0, @@ -1348,6 +1352,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "total", "fieldtype": "Currency", "hidden": 0, @@ -1381,6 +1386,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "net_total", "fieldtype": "Currency", "hidden": 0, @@ -1413,6 +1419,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "total_net_weight", "fieldtype": "Float", "hidden": 0, @@ -1445,6 +1452,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "taxes_section", "fieldtype": "Section Break", "hidden": 0, @@ -1478,6 +1486,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "taxes_and_charges", "fieldtype": "Link", "hidden": 0, @@ -1512,6 +1521,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_34", "fieldtype": "Column Break", "hidden": 0, @@ -1542,6 +1552,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "shipping_rule", "fieldtype": "Link", "hidden": 0, @@ -1575,6 +1586,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "section_break_36", "fieldtype": "Section Break", "hidden": 0, @@ -1605,6 +1617,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "taxes", "fieldtype": "Table", "hidden": 0, @@ -1639,6 +1652,7 @@ "bold": 0, "collapsible": 1, "columns": 0, + "fetch_if_empty": 0, "fieldname": "sec_tax_breakup", "fieldtype": "Section Break", "hidden": 0, @@ -1671,6 +1685,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "other_charges_calculation", "fieldtype": "Text", "hidden": 0, @@ -1703,6 +1718,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "section_break_39", "fieldtype": "Section Break", "hidden": 0, @@ -1733,6 +1749,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_total_taxes_and_charges", "fieldtype": "Currency", "hidden": 0, @@ -1767,6 +1784,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_42", "fieldtype": "Column Break", "hidden": 0, @@ -1797,6 +1815,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "total_taxes_and_charges", "fieldtype": "Currency", "hidden": 0, @@ -1830,6 +1849,7 @@ "collapsible": 1, "collapsible_depends_on": "discount_amount", "columns": 0, + "fetch_if_empty": 0, "fieldname": "section_break_44", "fieldtype": "Section Break", "hidden": 0, @@ -1863,6 +1883,7 @@ "collapsible": 0, "columns": 0, "default": "Grand Total", + "fetch_if_empty": 0, "fieldname": "apply_discount_on", "fieldtype": "Select", "hidden": 0, @@ -1896,6 +1917,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_discount_amount", "fieldtype": "Currency", "hidden": 0, @@ -1929,6 +1951,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_46", "fieldtype": "Column Break", "hidden": 0, @@ -1960,6 +1983,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "additional_discount_percentage", "fieldtype": "Float", "hidden": 0, @@ -1992,6 +2016,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "discount_amount", "fieldtype": "Currency", "hidden": 0, @@ -2024,6 +2049,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "totals", "fieldtype": "Section Break", "hidden": 0, @@ -2057,6 +2083,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_grand_total", "fieldtype": "Currency", "hidden": 0, @@ -2092,6 +2119,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_rounding_adjustment", "fieldtype": "Currency", "hidden": 0, @@ -2126,6 +2154,7 @@ "collapsible": 0, "columns": 0, "description": "In Words will be visible once you save the Quotation.", + "fetch_if_empty": 0, "fieldname": "base_in_words", "fieldtype": "Data", "hidden": 0, @@ -2160,6 +2189,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "base_rounded_total", "fieldtype": "Currency", "hidden": 0, @@ -2195,6 +2225,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break3", "fieldtype": "Column Break", "hidden": 0, @@ -2227,6 +2258,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "grand_total", "fieldtype": "Currency", "hidden": 0, @@ -2262,6 +2294,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "rounding_adjustment", "fieldtype": "Currency", "hidden": 0, @@ -2295,6 +2328,7 @@ "bold": 1, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "rounded_total", "fieldtype": "Currency", "hidden": 0, @@ -2330,6 +2364,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "in_words", "fieldtype": "Data", "hidden": 0, @@ -2366,6 +2401,7 @@ "collapsible_depends_on": "", "columns": 0, "depends_on": "", + "fetch_if_empty": 0, "fieldname": "payment_schedule_section", "fieldtype": "Section Break", "hidden": 0, @@ -2398,6 +2434,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "payment_terms_template", "fieldtype": "Link", "hidden": 0, @@ -2431,6 +2468,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "payment_schedule", "fieldtype": "Table", "hidden": 0, @@ -2465,6 +2503,7 @@ "collapsible": 1, "collapsible_depends_on": "terms", "columns": 0, + "fetch_if_empty": 0, "fieldname": "terms_section_break", "fieldtype": "Section Break", "hidden": 0, @@ -2498,6 +2537,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "tc_name", "fieldtype": "Link", "hidden": 0, @@ -2532,6 +2572,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "terms", "fieldtype": "Text Editor", "hidden": 0, @@ -2565,6 +2606,7 @@ "bold": 0, "collapsible": 1, "columns": 0, + "fetch_if_empty": 0, "fieldname": "print_settings", "fieldtype": "Section Break", "hidden": 0, @@ -2597,6 +2639,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "letter_head", "fieldtype": "Link", "hidden": 0, @@ -2631,6 +2674,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "group_same_items", "fieldtype": "Check", "hidden": 0, @@ -2663,6 +2707,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_73", "fieldtype": "Column Break", "hidden": 0, @@ -2694,6 +2739,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "select_print_heading", "fieldtype": "Link", "hidden": 0, @@ -2728,6 +2774,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "language", "fieldtype": "Data", "hidden": 0, @@ -2760,6 +2807,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "subscription_section", "fieldtype": "Section Break", "hidden": 0, @@ -2792,6 +2840,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "auto_repeat", "fieldtype": "Link", "hidden": 0, @@ -2826,6 +2875,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval: doc.auto_repeat", + "fetch_if_empty": 0, "fieldname": "update_auto_repeat_reference", "fieldtype": "Button", "hidden": 0, @@ -2858,6 +2908,7 @@ "bold": 0, "collapsible": 1, "columns": 0, + "fetch_if_empty": 0, "fieldname": "more_info", "fieldtype": "Section Break", "hidden": 0, @@ -2891,6 +2942,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "campaign", "fieldtype": "Link", "hidden": 0, @@ -2925,6 +2977,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "source", "fieldtype": "Link", "hidden": 0, @@ -2960,6 +3013,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:doc.status===\"Lost\"", + "fetch_if_empty": 0, "fieldname": "order_lost_reason", "fieldtype": "Small Text", "hidden": 0, @@ -2993,6 +3047,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break4", "fieldtype": "Column Break", "hidden": 0, @@ -3026,6 +3081,7 @@ "collapsible": 0, "columns": 0, "default": "Draft", + "fetch_if_empty": 0, "fieldname": "status", "fieldtype": "Select", "hidden": 0, @@ -3060,6 +3116,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "enq_det", "fieldtype": "Text", "hidden": 1, @@ -3093,6 +3150,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "supplier_quotation", "fieldtype": "Link", "hidden": 0, @@ -3126,6 +3184,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "opportunity", "fieldtype": "Link", "hidden": 0, @@ -3165,7 +3224,7 @@ "istable": 0, "max_attachments": 1, "menu_index": 0, - "modified": "2019-01-07 16:51:55.604845", + "modified": "2019-04-25 15:26:21.983298", "modified_by": "Administrator", "module": "Selling", "name": "Quotation", @@ -3331,11 +3390,11 @@ "quick_entry": 0, "read_only": 0, "read_only_onload": 1, - "search_fields": "status,transaction_date,customer,lead,order_type", + "search_fields": "status,transaction_date,party_name,order_type", "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", - "timeline_field": "customer", + "timeline_field": "party_name", "title_field": "title", "track_changes": 0, "track_seen": 0, diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 729256068be..42b68728ad2 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -28,11 +28,10 @@ class Quotation(SellingController): self.update_opportunity() self.validate_order_type() self.validate_uom_is_integer("stock_uom", "qty") - self.validate_quotation_to() self.validate_valid_till() if self.items: self.with_items = 1 - + def validate_valid_till(self): if self.valid_till and self.valid_till < self.transaction_date: frappe.throw(_("Valid till date cannot be before transaction date")) @@ -43,16 +42,9 @@ class Quotation(SellingController): def validate_order_type(self): super(Quotation, self).validate_order_type() - def validate_quotation_to(self): - if self.customer: - self.quotation_to = "Customer" - self.lead = None - elif self.lead: - self.quotation_to = "Lead" - def update_lead(self): - if self.lead: - frappe.get_doc("Lead", self.lead).set_status(update=True) + if self.quotation_to == "Lead" and self.party_name: + frappe.get_doc("Lead", self.party_name).set_status(update=True) def update_opportunity(self): for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])): @@ -209,12 +201,12 @@ def _make_sales_invoice(source_name, target_doc=None, ignore_permissions=False): } }, target_doc, set_missing_values, ignore_permissions=ignore_permissions) - return doclist + return doclist def _make_customer(source_name, ignore_permissions=False): - quotation = frappe.db.get_value("Quotation", source_name, ["lead", "order_type", "customer"]) - if quotation and quotation[0] and not quotation[2]: - lead_name = quotation[0] + quotation = frappe.db.get_value("Quotation", source_name, ["order_type", "party_name", "customer_name"]) + if quotation and quotation[1] and not quotation[2]: + lead_name = quotation[1] customer_name = frappe.db.get_value("Customer", {"lead_name": lead_name}, ["name", "customer_name"], as_dict=True) if not customer_name: @@ -242,3 +234,5 @@ def _make_customer(source_name, ignore_permissions=False): frappe.throw(_("Please create Customer from Lead {0}").format(lead_name)) else: return customer_name + else: + return frappe.get_doc("Customer",quotation[2]) diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index 78fb0c14042..8bb8c618f29 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -203,15 +203,15 @@ class TestQuotation(unittest.TestCase): test_records = frappe.get_test_records('Quotation') -def get_quotation_dict(customer=None, item_code=None): - if not customer: - customer = '_Test Customer' +def get_quotation_dict(party_name=None, item_code=None): + if not party_name: + party_name = '_Test Customer' if not item_code: item_code = '_Test Item' return { 'doctype': 'Quotation', - 'customer': customer, + 'party_name': party_name, 'items': [ { 'item_code': item_code, @@ -229,7 +229,7 @@ def make_quotation(**args): qo.transaction_date = args.transaction_date qo.company = args.company or "_Test Company" - qo.customer = args.customer or "_Test Customer" + qo.party_name = args.party_name or "_Test Customer" qo.currency = args.currency or "INR" if args.selling_price_list: qo.selling_price_list = args.selling_price_list diff --git a/erpnext/selling/doctype/quotation/test_records.json b/erpnext/selling/doctype/quotation/test_records.json index 7a9d3eb1e25..1564f7de0ce 100644 --- a/erpnext/selling/doctype/quotation/test_records.json +++ b/erpnext/selling/doctype/quotation/test_records.json @@ -1,37 +1,37 @@ [ - { - "company": "_Test Company", - "conversion_rate": 1.0, - "currency": "INR", - "customer": "_Test Customer", - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer", - "doctype": "Quotation", - "base_grand_total": 1000.0, - "grand_total": 1000.0, - "order_type": "Sales", - "plc_conversion_rate": 1.0, - "price_list_currency": "INR", - "items": [ - { - "base_amount": 1000.0, - "base_rate": 100.0, - "description": "CPU", - "doctype": "Quotation Item", - "item_code": "_Test Item Home Desktop 100", - "item_name": "CPU", - "parentfield": "items", - "qty": 10.0, - "rate": 100.0, - "uom": "_Test UOM 1", - "stock_uom": "_Test UOM 1", - "conversion_factor": 1.0 - } - ], - "quotation_to": "Customer", - "selling_price_list": "_Test Price List", - "territory": "_Test Territory", - "transaction_date": "2013-02-21", - "valid_till": "2013-03-21" - } + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "party_name": "_Test Customer", + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer", + "doctype": "Quotation", + "base_grand_total": 1000.0, + "grand_total": 1000.0, + "order_type": "Sales", + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "items": [ + { + "base_amount": 1000.0, + "base_rate": 100.0, + "description": "CPU", + "doctype": "Quotation Item", + "item_code": "_Test Item Home Desktop 100", + "item_name": "CPU", + "parentfield": "items", + "qty": 10.0, + "rate": 100.0, + "uom": "_Test UOM 1", + "stock_uom": "_Test UOM 1", + "conversion_factor": 1.0 + } + ], + "quotation_to": "Customer", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory", + "transaction_date": "2013-02-21", + "valid_till": "2013-03-21" + } ] \ No newline at end of file diff --git a/erpnext/setup/setup_wizard/operations/sample_data.py b/erpnext/setup/setup_wizard/operations/sample_data.py index 3f787347393..e21c9bd1089 100644 --- a/erpnext/setup/setup_wizard/operations/sample_data.py +++ b/erpnext/setup/setup_wizard/operations/sample_data.py @@ -33,7 +33,7 @@ def make_sample_data(domains, make_dependent = False): def make_opportunity(items, customer): b = frappe.get_doc({ "doctype": "Opportunity", - "enquiry_from": "Customer", + "opportunity_from": "Customer", "customer": customer, "opportunity_type": _("Sales"), "with_items": 1 diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 0abe057af9a..efc128aa0c5 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -196,7 +196,7 @@ def _get_cart_quotation(party=None): party = get_party() quotation = frappe.get_all("Quotation", fields=["name"], filters= - {party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0}, + {"party_name": party.name, "order_type": "Shopping Cart", "docstatus": 0}, order_by="modified desc", limit_page_length=1) if quotation: @@ -211,7 +211,7 @@ def _get_cart_quotation(party=None): "status": "Draft", "docstatus": 0, "__islocal": 1, - (party.doctype.lower()): party.name + "party_name": party.name }) qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user}) @@ -291,9 +291,9 @@ def _set_price_list(quotation, cart_settings): # check if customer price list exists selling_price_list = None - if quotation.customer: + if quotation.party_name: from erpnext.accounts.party import get_default_price_list - selling_price_list = get_default_price_list(frappe.get_doc("Customer", quotation.customer)) + selling_price_list = get_default_price_list(frappe.get_doc("Customer", quotation.party_name)) # else check for territory based price list if not selling_price_list: @@ -305,9 +305,9 @@ def set_taxes(quotation, cart_settings): """set taxes based on billing territory""" from erpnext.accounts.party import set_taxes - customer_group = frappe.db.get_value("Customer", quotation.customer, "customer_group") + customer_group = frappe.db.get_value("Customer", quotation.party_name, "customer_group") - quotation.taxes_and_charges = set_taxes(quotation.customer, "Customer", \ + quotation.taxes_and_charges = set_taxes(quotation.party_name, "Customer", \ quotation.transaction_date, quotation.company, customer_group, None, \ quotation.customer_address, quotation.shipping_address_name, 1) # diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py index 7d6b41ef5fc..be08ec44445 100644 --- a/erpnext/shopping_cart/test_shopping_cart.py +++ b/erpnext/shopping_cart/test_shopping_cart.py @@ -33,7 +33,6 @@ class TestShoppingCart(unittest.TestCase): self.assertEqual(quotation.quotation_to, "Customer") self.assertEqual(quotation.contact_person, frappe.db.get_value("Contact", dict(email_id="test_cart_user@example.com"))) - self.assertEqual(quotation.lead, None) self.assertEqual(quotation.contact_email, frappe.session.user) return quotation @@ -44,8 +43,7 @@ class TestShoppingCart(unittest.TestCase): # test if quotation with customer is fetched quotation = _get_cart_quotation() self.assertEqual(quotation.quotation_to, "Customer") - self.assertEqual(quotation.customer, "_Test Customer") - self.assertEqual(quotation.lead, None) + self.assertEqual(quotation.party_name, "_Test Customer") self.assertEqual(quotation.contact_email, frappe.session.user) return quotation @@ -107,7 +105,7 @@ class TestShoppingCart(unittest.TestCase): from erpnext.accounts.party import set_taxes - tax_rule_master = set_taxes(quotation.customer, "Customer", \ + tax_rule_master = set_taxes(quotation.party_name, "Customer", \ quotation.transaction_date, quotation.company, None, None, \ quotation.customer_address, quotation.shipping_address_name, 1) self.assertEqual(quotation.taxes_and_charges, tax_rule_master) @@ -122,7 +120,7 @@ class TestShoppingCart(unittest.TestCase): "doctype": "Quotation", "quotation_to": "Customer", "order_type": "Shopping Cart", - "customer": get_party(frappe.session.user).name, + "party_name": get_party(frappe.session.user).name, "docstatus": 0, "contact_email": frappe.session.user, "selling_price_list": "_Test Price List Rest of the World", diff --git a/erpnext/templates/utils.py b/erpnext/templates/utils.py index cb44fd30d22..97e2a7f7235 100644 --- a/erpnext/templates/utils.py +++ b/erpnext/templates/utils.py @@ -28,7 +28,7 @@ def send_message(subject="Website Query", message="", sender="", status="Open"): opportunity = frappe.get_doc(dict( doctype ='Opportunity', - enquiry_from = 'Customer' if customer else 'Lead', + opportunity_from = 'Customer' if customer else 'Lead', status = 'Open', title = subject, contact_email = sender,