From 1b48fde986e2beacb73bf41160f16b968a396184 Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Wed, 16 May 2018 10:47:02 +0530 Subject: [PATCH] Make the communication from the issue webform (#14015) --- erpnext/support/doctype/issue/issue.json | 33 ++++++++++++++++++++- erpnext/support/doctype/issue/issue.py | 28 +++++++++++++++++ erpnext/support/web_form/issues/issues.json | 13 +++++++- erpnext/support/web_form/issues/issues.py | 3 +- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/erpnext/support/doctype/issue/issue.json b/erpnext/support/doctype/issue/issue.json index d2ec7c30a90..923a79c8e42 100644 --- a/erpnext/support/doctype/issue/issue.json +++ b/erpnext/support/doctype/issue/issue.json @@ -926,6 +926,37 @@ "set_only_once": 0, "translatable": 0, "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "via_customer_portal", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Via Customer Portal", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "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 } ], "has_web_view": 0, @@ -939,7 +970,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-04-13 13:03:14.748090", + "modified": "2018-05-07 05:53:20.684275", "modified_by": "Administrator", "module": "Support", "name": "Issue", diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index 6a18f1153bc..dfcc2a8936d 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -17,6 +17,8 @@ class Issue(Document): return "{0}: {1}".format(_(self.status), self.subject) def validate(self): + if (self.get("__islocal") and self.via_customer_portal): + self.flags.create_communication = True if not self.raised_by: self.raised_by = frappe.session.user self.update_status() @@ -26,6 +28,12 @@ class Issue(Document): from frappe.desk.form.assign_to import clear clear(self.doctype, self.name) + def on_update(self): + # create the communication email and remove the description + if (self.flags.create_communication and self.via_customer_portal): + self.create_communication() + self.flags.communication_created = None + def set_lead_contact(self, email_id): import email.utils email_id = email.utils.parseaddr(email_id)[1] @@ -53,6 +61,26 @@ class Issue(Document): # if no date, it should be set as None and not a blank string "", as per mysql strict config self.resolution_date = None + def create_communication(self): + communication = frappe.new_doc("Communication") + communication.update({ + "communication_type": "Communication", + "communication_medium": "Email", + "sent_or_received": "Received", + "email_status": "Open", + "subject": self.subject, + "sender": self.raised_by, + "content": self.description, + "status": "Linked", + "reference_doctype": "Issue", + "reference_name": self.name + }) + communication.ignore_permissions = True + communication.ignore_mandatory = True + communication.save() + + self.db_set("description", "") + def get_list_context(context=None): return { "title": _("Issues"), diff --git a/erpnext/support/web_form/issues/issues.json b/erpnext/support/web_form/issues/issues.json index 264b9dfbc24..a8c7ab97e0b 100644 --- a/erpnext/support/web_form/issues/issues.json +++ b/erpnext/support/web_form/issues/issues.json @@ -18,7 +18,7 @@ "is_standard": 1, "login_required": 1, "max_attachment_size": 0, - "modified": "2017-07-25 22:49:10.762704", + "modified": "2018-05-07 05:54:22.213127", "modified_by": "Administrator", "module": "Support", "name": "issues", @@ -83,6 +83,17 @@ "max_value": 0, "read_only": 0, "reqd": 0 + }, + { + "default": "1", + "fieldname": "via_customer_portal", + "fieldtype": "Check", + "hidden": 1, + "label": "Via Customer Portal", + "max_length": 0, + "max_value": 0, + "read_only": 1, + "reqd": 0 } ] } \ No newline at end of file diff --git a/erpnext/support/web_form/issues/issues.py b/erpnext/support/web_form/issues/issues.py index 2334f8b26d8..bb9197af358 100644 --- a/erpnext/support/web_form/issues/issues.py +++ b/erpnext/support/web_form/issues/issues.py @@ -4,4 +4,5 @@ import frappe def get_context(context): # do your magic here - pass + if context.doc: + context.read_only = 1 \ No newline at end of file