From 925eca0e4a3e539b8d1e4ae7200ea9fcc5d524ab Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Sat, 29 Jan 2022 22:32:03 +0530 Subject: [PATCH] fix: multiple CRM fixes (#29507) * fix: multiple CRM fixes --- erpnext/crm/doctype/campaign/campaign.js | 2 +- .../crm/doctype/crm_settings/crm_settings.py | 5 ++-- .../crm/doctype/opportunity/opportunity.js | 25 +++++++++++-------- .../crm/doctype/opportunity/opportunity.json | 20 ++------------- .../crm/doctype/opportunity/opportunity.py | 2 -- erpnext/crm/doctype/prospect/prospect.js | 2 ++ erpnext/crm/module_onboarding/crm/crm.json | 5 +++- .../create_and_send_quotation.json | 2 +- .../create_lead/create_lead.json | 2 +- .../create_opportunity.json | 2 +- .../crm_settings/crm_settings.json | 21 ++++++++++++++++ .../introduction_to_crm.json | 2 +- .../selling_settings/selling_settings.py | 2 +- erpnext/selling/sales_common.js | 2 +- 14 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 erpnext/crm/onboarding_step/crm_settings/crm_settings.json diff --git a/erpnext/crm/doctype/campaign/campaign.js b/erpnext/crm/doctype/campaign/campaign.js index 11bfa74b29c..cac45c682cb 100644 --- a/erpnext/crm/doctype/campaign/campaign.js +++ b/erpnext/crm/doctype/campaign/campaign.js @@ -5,7 +5,7 @@ frappe.ui.form.on('Campaign', { refresh: function(frm) { erpnext.toggle_naming_series(); - if (frm.doc.__islocal) { + if (frm.is_new()) { frm.toggle_display("naming_series", frappe.boot.sysdefaults.campaign_naming_by=="Naming Series"); } else { cur_frm.add_custom_button(__("View Leads"), function() { diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.py b/erpnext/crm/doctype/crm_settings/crm_settings.py index bde52547c95..98cf7d845e0 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.py +++ b/erpnext/crm/doctype/crm_settings/crm_settings.py @@ -1,9 +1,10 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -# import frappe +import frappe from frappe.model.document import Document class CRMSettings(Document): - pass + def validate(self): + frappe.db.set_default("campaign_naming_by", self.get("campaign_naming_by", "")) diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index f8376e6ca94..8e7d67e0575 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -24,6 +24,14 @@ frappe.ui.form.on("Opportunity", { frm.trigger('set_contact_link'); } }, + + validate: function(frm) { + if (frm.doc.status == "Lost" && !frm.doc.lost_reasons.length) { + frm.trigger('set_as_lost_dialog'); + frappe.throw(__("Lost Reasons are required in case opportunity is Lost.")); + } + }, + contact_date: function(frm) { if(frm.doc.contact_date < frappe.datetime.now_datetime()){ frm.set_value("contact_date", ""); @@ -82,7 +90,7 @@ frappe.ui.form.on("Opportunity", { frm.trigger('setup_opportunity_from'); erpnext.toggle_naming_series(); - if(!doc.__islocal && doc.status!=="Lost") { + if(!frm.is_new() && doc.status!=="Lost") { if(doc.with_items){ frm.add_custom_button(__('Supplier Quotation'), function() { @@ -187,11 +195,11 @@ frappe.ui.form.on("Opportunity", { change_form_labels: function(frm) { let company_currency = erpnext.get_currency(frm.doc.company); - frm.set_currency_labels(["base_opportunity_amount", "base_total", "base_grand_total"], company_currency); - frm.set_currency_labels(["opportunity_amount", "total", "grand_total"], frm.doc.currency); + frm.set_currency_labels(["base_opportunity_amount", "base_total"], company_currency); + frm.set_currency_labels(["opportunity_amount", "total"], frm.doc.currency); // toggle fields - frm.toggle_display(["conversion_rate", "base_opportunity_amount", "base_total", "base_grand_total"], + frm.toggle_display(["conversion_rate", "base_opportunity_amount", "base_total"], frm.doc.currency != company_currency); }, @@ -209,20 +217,15 @@ frappe.ui.form.on("Opportunity", { }, calculate_total: function(frm) { - let total = 0, base_total = 0, grand_total = 0, base_grand_total = 0; + let total = 0, base_total = 0; frm.doc.items.forEach(item => { total += item.amount; base_total += item.base_amount; }) - base_grand_total = base_total + frm.doc.base_opportunity_amount; - grand_total = total + frm.doc.opportunity_amount; - frm.set_value({ 'total': flt(total), - 'base_total': flt(base_total), - 'grand_total': flt(grand_total), - 'base_grand_total': flt(base_grand_total) + 'base_total': flt(base_total) }); } diff --git a/erpnext/crm/doctype/opportunity/opportunity.json b/erpnext/crm/doctype/opportunity/opportunity.json index dc32d9a4124..089f2d2faa8 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.json +++ b/erpnext/crm/doctype/opportunity/opportunity.json @@ -42,10 +42,8 @@ "items", "section_break_32", "base_total", - "base_grand_total", "column_break_33", "total", - "grand_total", "contact_info", "customer_address", "address_display", @@ -475,21 +473,6 @@ "fieldname": "column_break_33", "fieldtype": "Column Break" }, - { - "fieldname": "base_grand_total", - "fieldtype": "Currency", - "label": "Grand Total (Company Currency)", - "options": "Company:company:default_currency", - "print_hide": 1, - "read_only": 1 - }, - { - "fieldname": "grand_total", - "fieldtype": "Currency", - "label": "Grand Total", - "options": "currency", - "read_only": 1 - }, { "fieldname": "lost_detail_section", "fieldtype": "Section Break", @@ -510,7 +493,7 @@ "icon": "fa fa-info-sign", "idx": 195, "links": [], - "modified": "2021-10-21 12:04:30.151379", + "modified": "2022-01-29 19:32:26.382896", "modified_by": "Administrator", "module": "CRM", "name": "Opportunity", @@ -547,6 +530,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "subject_field": "title", "timeline_field": "party_name", "title_field": "title", diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index a4fd7658eed..2d538748ec2 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -69,8 +69,6 @@ class Opportunity(TransactionBase): self.total = flt(total) self.base_total = flt(base_total) - self.grand_total = flt(self.total) + flt(self.opportunity_amount) - self.base_grand_total = flt(self.base_total) + flt(self.base_opportunity_amount) def make_new_lead_if_required(self): """Set lead against new opportunity""" diff --git a/erpnext/crm/doctype/prospect/prospect.js b/erpnext/crm/doctype/prospect/prospect.js index 67018e1ef9c..8721a5b42d3 100644 --- a/erpnext/crm/doctype/prospect/prospect.js +++ b/erpnext/crm/doctype/prospect/prospect.js @@ -3,6 +3,8 @@ frappe.ui.form.on('Prospect', { refresh (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: frm.doctype }; + if (!frm.is_new() && frappe.boot.user.can_create.includes("Customer")) { frm.add_custom_button(__("Customer"), function() { frappe.model.open_mapped_doc({ diff --git a/erpnext/crm/module_onboarding/crm/crm.json b/erpnext/crm/module_onboarding/crm/crm.json index 8315218c842..0faad1d3151 100644 --- a/erpnext/crm/module_onboarding/crm/crm.json +++ b/erpnext/crm/module_onboarding/crm/crm.json @@ -16,7 +16,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/CRM", "idx": 0, "is_complete": 0, - "modified": "2020-07-08 14:05:42.644448", + "modified": "2022-01-29 20:14:29.502145", "modified_by": "Administrator", "module": "CRM", "name": "CRM", @@ -33,6 +33,9 @@ }, { "step": "Create and Send Quotation" + }, + { + "step": "CRM Settings" } ], "subtitle": "Lead, Opportunity, Customer, and more.", diff --git a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json index 78f7e4de9c7..f0f50de5d16 100644 --- a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json +++ b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-05-28 21:07:11.461172", @@ -13,6 +12,7 @@ "name": "Create and Send Quotation", "owner": "Administrator", "reference_document": "Quotation", + "show_form_tour": 0, "show_full_form": 1, "title": "Create and Send Quotation", "validate_action": 1 diff --git a/erpnext/crm/onboarding_step/create_lead/create_lead.json b/erpnext/crm/onboarding_step/create_lead/create_lead.json index c45e8b036c5..cb5cce66a5f 100644 --- a/erpnext/crm/onboarding_step/create_lead/create_lead.json +++ b/erpnext/crm/onboarding_step/create_lead/create_lead.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-05-28 21:07:01.373403", @@ -13,6 +12,7 @@ "name": "Create Lead", "owner": "Administrator", "reference_document": "Lead", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Lead", "validate_action": 1 diff --git a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json index 0ee9317c852..96e0256d700 100644 --- a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json +++ b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2021-01-21 15:28:52.483839", @@ -13,6 +12,7 @@ "name": "Create Opportunity", "owner": "Administrator", "reference_document": "Opportunity", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Opportunity", "validate_action": 1 diff --git a/erpnext/crm/onboarding_step/crm_settings/crm_settings.json b/erpnext/crm/onboarding_step/crm_settings/crm_settings.json new file mode 100644 index 00000000000..555d795987f --- /dev/null +++ b/erpnext/crm/onboarding_step/crm_settings/crm_settings.json @@ -0,0 +1,21 @@ +{ + "action": "Go to Page", + "creation": "2022-01-29 20:14:24.803844", + "description": "# CRM Settings\n\nCRM module\u2019s features are configurable as per your business needs. CRM Settings is the place where you can set your preferences for:\n- Campaign\n- Lead\n- Opportunity\n- Quotation", + "docstatus": 0, + "doctype": "Onboarding Step", + "idx": 0, + "is_complete": 0, + "is_single": 1, + "is_skipped": 0, + "modified": "2022-01-29 20:14:24.803844", + "modified_by": "Administrator", + "name": "CRM Settings", + "owner": "Administrator", + "path": "#crm-settings/CRM%20Settings", + "reference_document": "CRM Settings", + "show_form_tour": 0, + "show_full_form": 0, + "title": "CRM Settings", + "validate_action": 1 +} \ No newline at end of file diff --git a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json index fa26921ae2c..88717530945 100644 --- a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json +++ b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json @@ -5,13 +5,13 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-05-14 17:28:16.448676", "modified_by": "Administrator", "name": "Introduction to CRM", "owner": "Administrator", + "show_form_tour": 0, "show_full_form": 0, "title": "Introduction to CRM", "validate_action": 1, diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.py b/erpnext/selling/doctype/selling_settings/selling_settings.py index fb86e614b6c..e1ef63578e9 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.py +++ b/erpnext/selling/doctype/selling_settings/selling_settings.py @@ -16,7 +16,7 @@ class SellingSettings(Document): self.toggle_editable_rate_for_bundle_items() def validate(self): - for key in ["cust_master_name", "campaign_naming_by", "customer_group", "territory", + for key in ["cust_master_name", "customer_group", "territory", "maintain_same_sales_rate", "editable_price_list_rate", "selling_price_list"]: frappe.db.set_default(key, self.get(key, "")) diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 540aca234bd..bd3b41fd55b 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -486,7 +486,7 @@ frappe.ui.form.on(cur_frm.doctype, { "options": "Competitor Detail" }, { - "fieldtype": "Text", + "fieldtype": "Small Text", "label": __("Detailed Reason"), "fieldname": "detailed_reason" },