From 6084a3e63a635c95ae60261a1c1d663e3370eee7 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 2 Jul 2014 17:13:08 +0530 Subject: [PATCH 1/2] formatting fix in support ticket autoreply --- .../support_ticket/get_support_mails.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/erpnext/support/doctype/support_ticket/get_support_mails.py b/erpnext/support/doctype/support_ticket/get_support_mails.py index 92e90312b9..21f7c901d2 100644 --- a/erpnext/support/doctype/support_ticket/get_support_mails.py +++ b/erpnext/support/doctype/support_ticket/get_support_mails.py @@ -4,11 +4,11 @@ from __future__ import unicode_literals import frappe from frappe.utils import cstr, cint, decode_dict, today -from frappe.utils.email_lib import sendmail +from frappe.utils.email_lib import sendmail from frappe.utils.email_lib.receive import POP3Mailbox from frappe.core.doctype.communication.communication import _make -class SupportMailbox(POP3Mailbox): +class SupportMailbox(POP3Mailbox): def setup(self, args=None): self.email_settings = frappe.get_doc("Support Email Settings", "Support Email Settings") self.settings = args or frappe._dict({ @@ -17,7 +17,7 @@ class SupportMailbox(POP3Mailbox): "username": self.email_settings.mail_login, "password": self.email_settings.mail_password }) - + def process_message(self, mail): if mail.from_email == self.email_settings.get('support_email'): return @@ -26,10 +26,10 @@ class SupportMailbox(POP3Mailbox): if not (thread_id and frappe.db.exists("Support Ticket", thread_id)): new_ticket = True - + ticket = add_support_communication(mail.subject, mail.content, mail.from_email, docname=None if new_ticket else thread_id, mail=mail) - + if new_ticket and cint(self.email_settings.send_autoreply) and \ "mailer-daemon" not in mail.from_email.lower(): self.send_auto_reply(ticket) @@ -39,23 +39,25 @@ class SupportMailbox(POP3Mailbox): response = self.email_settings.get('support_autoreply') or (""" A new Ticket has been raised for your query. If you have any additional information, please reply back to this mail. - -We will get back to you as soon as possible ----------------------- + +### We will get back to you as soon as possible + +--- + Original Query: -""" + d.description + "\n----------------------\n" + cstr(signature)) +""" + d.description + "\n\n---\n\n" + cstr(signature)) sendmail(\ recipients = [cstr(d.raised_by)], \ sender = cstr(self.email_settings.get('support_email')), \ subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \ msg = cstr(response)) - + def get_support_mails(): if cint(frappe.db.get_value('Support Email Settings', None, 'sync_support_mails')): SupportMailbox() - + def add_support_communication(subject, content, sender, docname=None, mail=None): if docname: ticket = frappe.get_doc("Support Ticket", docname) @@ -74,12 +76,12 @@ def add_support_communication(subject, content, sender, docname=None, mail=None) ticket.ignore_permissions = True ticket.ignore_mandatory = True ticket.insert() - + _make(content=content, sender=sender, subject = subject, doctype="Support Ticket", name=ticket.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: mail.save_attachments_in_doc(ticket) - - return ticket \ No newline at end of file + + return ticket From 501b2cc6174593ca400b0e0e9e95b9a6d7598b8d Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 2 Jul 2014 18:01:30 +0530 Subject: [PATCH 2/2] duplicate name fix for customer --- erpnext/selling/doctype/customer/customer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 0d430e39c3..c065b54dbb 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -56,6 +56,7 @@ class Customer(TransactionBase): (self.name, self.customer_name, self.lead_name)) lead = frappe.db.get_value("Lead", self.lead_name, ["lead_name", "email_id", "phone", "mobile_no"], as_dict=True) + c = frappe.new_doc('Contact') c.first_name = lead.lead_name c.email_id = lead.email_id @@ -65,10 +66,9 @@ class Customer(TransactionBase): c.customer_name = self.customer_name c.is_primary_contact = 1 c.ignore_permissions = getattr(self, "ignore_permissions", None) - try: - c.save() - except frappe.NameError: - pass + c.autoname() + if not frappe.db.exists("Contact", c.name): + c.insert() def on_update(self): self.validate_name_with_customer_group()