From e2089fb7122e05f6722adf134ba9ef0907361150 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 21 May 2013 16:53:31 +0530 Subject: [PATCH] [fixes] set lead, contact and company on support ticket --- .../support_ticket/get_support_mails.py | 4 +- .../doctype/support_ticket/support_ticket.py | 24 ++++++-- .../doctype/support_ticket/support_ticket.txt | 59 +++++++------------ 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py index d1fe0dc8da..82ae9a34b6 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -50,7 +50,7 @@ class SupportMailbox(POP3Mailbox): "subject": mail.mail["Subject"], "raised_by": mail.from_email, "content_type": mail.content_type, - "status": "Open" + "status": "Open", }]) ticket.insert() new_ticket = True @@ -58,7 +58,7 @@ class SupportMailbox(POP3Mailbox): mail.save_attachments_in_doc(ticket.doc) make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject, - doctype="Support Ticket", name=ticket.doc.name, + doctype="Support Ticket", name=ticket.doc.name, lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date) if new_ticket and cint(self.email_settings.send_autoreply) and \ diff --git a/support/doctype/support_ticket/support_ticket.py b/support/doctype/support_ticket/support_ticket.py index ca46a8e073..5f01516ba0 100644 --- a/support/doctype/support_ticket/support_ticket.py +++ b/support/doctype/support_ticket/support_ticket.py @@ -18,7 +18,6 @@ from __future__ import unicode_literals import webnotes from utilities.transaction_base import TransactionBase -from home import update_feed from webnotes.utils import now class DocType(TransactionBase): @@ -44,6 +43,7 @@ class DocType(TransactionBase): def validate(self): self.update_status() + self.set_lead_contact(self.doc.raised_by) if self.doc.status == "Closed": from webnotes.widgets.form.assign_to import clear @@ -51,10 +51,24 @@ class DocType(TransactionBase): def on_communication_sent(self, comm): webnotes.conn.set(self.doc, 'status', 'Waiting for Customer') - if comm.lead and not self.doc.lead: - webnotes.conn.set(self.doc, 'lead', comm.lead) - if comm.contact and not self.doc.contact: - webnotes.conn.set(self.doc, 'contact', comm.contact) + + + def set_lead_contact(self, email_id): + import email.utils + email_id = email.utils.parseaddr(email_id) + if email_id: + if not self.doc.lead: + self.doc.lead = webnotes.conn.get_value("Lead", {"email_id": email_id}) + if not self.doc.contact: + self.doc.contact = webnotes.conn.get_value("Contact", {"email_id": email_id}) + + if not self.doc.company: + if self.doc.lead: + company = webnotes.conn.get_value("Lead", self.doc.lead, "company") + elif self.doc.contact: + company = webnotes.conn.get_value("Contact", self.doc.contact, "company") + + self.doc.company = company or webnotes.conn.get_default("company") def on_trash(self): webnotes.conn.sql("""update `tabCommunication` set support_ticket=NULL diff --git a/support/doctype/support_ticket/support_ticket.txt b/support/doctype/support_ticket/support_ticket.txt index 769bb9d701..50e547ece7 100644 --- a/support/doctype/support_ticket/support_ticket.txt +++ b/support/doctype/support_ticket/support_ticket.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-01-31 22:22:27", + "creation": "2013-02-01 10:36:25", "docstatus": 0, - "modified": "2013-01-31 22:17:24", + "modified": "2013-05-21 16:27:46", "modified_by": "Administrator", "owner": "Administrator" }, @@ -23,13 +23,18 @@ "permlevel": 0 }, { + "amend": 0, + "create": 1, "doctype": "DocPerm", "name": "__common__", "parent": "Support Ticket", "parentfield": "permissions", "parenttype": "DocType", + "permlevel": 0, "read": 1, - "submit": 0 + "report": 1, + "submit": 0, + "write": 1 }, { "doctype": "DocType", @@ -191,6 +196,15 @@ "oldfieldtype": "Time", "read_only": 1 }, + { + "doctype": "DocField", + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "print_hide": 1, + "reqd": 0 + }, { "depends_on": "eval:!doc.__islocal", "doctype": "DocField", @@ -237,51 +251,18 @@ "label": "Content Type" }, { - "amend": 0, "cancel": 0, - "create": 1, "doctype": "DocPerm", - "permlevel": 0, - "report": 1, - "role": "Guest", - "write": 1 + "role": "Guest" }, { - "create": 1, + "cancel": 0, "doctype": "DocPerm", - "match": "customer", - "permlevel": 0, - "report": 1, - "role": "Customer", - "write": 1 + "role": "Customer" }, { "cancel": 1, - "create": 1, "doctype": "DocPerm", - "permlevel": 0, - "report": 1, - "role": "Support Team", - "write": 1 - }, - { - "amend": 0, - "cancel": 0, - "create": 0, - "doctype": "DocPerm", - "match": "", - "permlevel": 1, - "report": 1, - "role": "Support Team", - "write": 1 - }, - { - "amend": 0, - "cancel": 0, - "create": 0, - "doctype": "DocPerm", - "match": "", - "permlevel": 2, "role": "Support Team" } ] \ No newline at end of file