From e447c79f9de10c6cc1373b206aece6868c6b9d16 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Thu, 13 Aug 2020 09:20:36 +0530 Subject: [PATCH] fix: Quotation lost reason options fix (#22814) * adding patch and lost reason child tables * fix: conflict resolved --- .../crm/doctype/opportunity/opportunity.json | 2 +- .../__init__.py | 0 .../opportunity_lost_reason_detail.json | 31 +++++++++++++++++++ .../opportunity_lost_reason_detail.py | 10 ++++++ erpnext/patches.txt | 1 + .../v12_0/rename_lost_reason_detail.py | 17 ++++++++++ .../selling/doctype/quotation/quotation.json | 4 +-- .../selling/doctype/quotation/quotation.py | 2 +- erpnext/selling/sales_common.js | 19 +++++++----- .../quotation_lost_reason_detail/__init__.py | 0 .../quotation_lost_reason_detail.json | 31 +++++++++++++++++++ .../quotation_lost_reason_detail.py | 10 ++++++ 12 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 erpnext/crm/doctype/opportunity_lost_reason_detail/__init__.py create mode 100644 erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.json create mode 100644 erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.py create mode 100644 erpnext/patches/v12_0/rename_lost_reason_detail.py create mode 100644 erpnext/setup/doctype/quotation_lost_reason_detail/__init__.py create mode 100644 erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.json create mode 100644 erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py diff --git a/erpnext/crm/doctype/opportunity/opportunity.json b/erpnext/crm/doctype/opportunity/opportunity.json index 5cd5233b2e..b61cad3620 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.json +++ b/erpnext/crm/doctype/opportunity/opportunity.json @@ -411,7 +411,7 @@ "fieldname": "lost_reasons", "fieldtype": "Table MultiSelect", "label": "Lost Reasons", - "options": "Lost Reason Detail", + "options": "Opportunity Lost Reason Detail", "read_only": 1 }, { diff --git a/erpnext/crm/doctype/opportunity_lost_reason_detail/__init__.py b/erpnext/crm/doctype/opportunity_lost_reason_detail/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.json b/erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.json new file mode 100644 index 0000000000..50620e2c34 --- /dev/null +++ b/erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.json @@ -0,0 +1,31 @@ +{ + "actions": [], + "creation": "2020-07-16 16:11:39.830389", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "lost_reason" + ], + "fields": [ + { + "fieldname": "lost_reason", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Opportunity Lost Reason", + "options": "Opportunity Lost Reason" + } + ], + "istable": 1, + "links": [], + "modified": "2020-07-26 17:58:26.313242", + "modified_by": "Administrator", + "module": "CRM", + "name": "Opportunity Lost Reason Detail", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.py b/erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.py new file mode 100644 index 0000000000..8723f1d045 --- /dev/null +++ b/erpnext/crm/doctype/opportunity_lost_reason_detail/opportunity_lost_reason_detail.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class OpportunityLostReasonDetail(Document): + pass diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 67774975fd..361fe8352a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -720,3 +720,4 @@ erpnext.patches.v13_0.move_branch_code_to_bank_account erpnext.patches.v13_0.healthcare_lab_module_rename_doctypes erpnext.patches.v13_0.stock_entry_enhancements erpnext.patches.v12_0.update_state_code_for_daman_and_diu +erpnext.patches.v12_0.rename_lost_reason_detail diff --git a/erpnext/patches/v12_0/rename_lost_reason_detail.py b/erpnext/patches/v12_0/rename_lost_reason_detail.py new file mode 100644 index 0000000000..044d0232e0 --- /dev/null +++ b/erpnext/patches/v12_0/rename_lost_reason_detail.py @@ -0,0 +1,17 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + if frappe.db.exists("DocType", "Lost Reason Detail"): + frappe.reload_doc("crm", "doctype", "opportunity_lost_reason_detail") + frappe.reload_doc("setup", "doctype", "quotation_lost_reason_detail") + + frappe.db.sql("""INSERT INTO `tabOpportunity Lost Reason Detail` SELECT * FROM `tabLost Reason Detail` WHERE `parenttype` = 'Opportunity'""") + + frappe.db.sql("""INSERT INTO `tabQuotation Lost Reason Detail` SELECT * FROM `tabLost Reason Detail` WHERE `parenttype` = 'Quotation'""") + + frappe.db.sql("""INSERT INTO `tabQuotation Lost Reason` (`name`, `creation`, `modified`, `modified_by`, `owner`, `docstatus`, `parent`, `parentfield`, `parenttype`, `idx`, `_comments`, `_assign`, `_user_tags`, `_liked_by`, `order_lost_reason`) + SELECT o.`name`, o.`creation`, o.`modified`, o.`modified_by`, o.`owner`, o.`docstatus`, o.`parent`, o.`parentfield`, o.`parenttype`, o.`idx`, o.`_comments`, o.`_assign`, o.`_user_tags`, o.`_liked_by`, o.`lost_reason` + FROM `tabOpportunity Lost Reason` o LEFT JOIN `tabQuotation Lost Reason` q ON q.name = o.name WHERE q.name IS NULL""") + + frappe.delete_doc("DocType", "Lost Reason Detail") \ No newline at end of file diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json index 6d34c2ac7f..5b85187ccb 100644 --- a/erpnext/selling/doctype/quotation/quotation.json +++ b/erpnext/selling/doctype/quotation/quotation.json @@ -923,7 +923,7 @@ "fieldname": "lost_reasons", "fieldtype": "Table MultiSelect", "label": "Lost Reasons", - "options": "Lost Reason Detail", + "options": "Quotation Lost Reason Detail", "read_only": 1 } ], @@ -932,7 +932,7 @@ "is_submittable": 1, "links": [], "max_attachments": 1, - "modified": "2020-07-18 04:59:09.960118", + "modified": "2020-07-26 17:46:19.951223", "modified_by": "Administrator", "module": "Selling", "name": "Quotation", diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 449a968a4f..ab095ebfe0 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -68,7 +68,7 @@ class Quotation(SellingController): def declare_enquiry_lost(self, lost_reasons_list, detailed_reason=None): if not self.has_sales_order(): - get_lost_reasons = frappe.get_list('Opportunity Lost Reason', + get_lost_reasons = frappe.get_list('Quotation Lost Reason', fields = ["name"]) lost_reasons_lst = [reason.get('name') for reason in get_lost_reasons] frappe.db.set(self, 'status', 'Lost') diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 333a563aa5..002cfe41e1 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -494,13 +494,18 @@ frappe.ui.form.on(cur_frm.doctype, { var dialog = new frappe.ui.Dialog({ title: __("Set as Lost"), fields: [ - {"fieldtype": "Table MultiSelect", - "label": __("Lost Reasons"), - "fieldname": "lost_reason", - "options": "Lost Reason Detail", - "reqd": 1}, - - {"fieldtype": "Text", "label": __("Detailed Reason"), "fieldname": "detailed_reason"}, + { + "fieldtype": "Table MultiSelect", + "label": __("Lost Reasons"), + "fieldname": "lost_reason", + "options": frm.doctype === 'Opportunity' ? 'Opportunity Lost Reason Detail': 'Quotation Lost Reason Detail', + "reqd": 1 + }, + { + "fieldtype": "Text", + "label": __("Detailed Reason"), + "fieldname": "detailed_reason" + }, ], primary_action: function() { var values = dialog.get_values(); diff --git a/erpnext/setup/doctype/quotation_lost_reason_detail/__init__.py b/erpnext/setup/doctype/quotation_lost_reason_detail/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.json b/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.json new file mode 100644 index 0000000000..543214101a --- /dev/null +++ b/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.json @@ -0,0 +1,31 @@ +{ + "actions": [], + "creation": "2020-07-14 09:21:44.057724", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "lost_reason" + ], + "fields": [ + { + "fieldname": "lost_reason", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Quotation Lost Reason", + "options": "Quotation Lost Reason" + } + ], + "istable": 1, + "links": [], + "modified": "2020-07-26 17:58:56.373775", + "modified_by": "Administrator", + "module": "Setup", + "name": "Quotation Lost Reason Detail", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py b/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py new file mode 100644 index 0000000000..7bb8d02670 --- /dev/null +++ b/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class QuotationLostReasonDetail(Document): + pass