From 46ec268e9b3f457f665d9f57425028874f515692 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 29 Aug 2013 13:53:36 +0530 Subject: [PATCH] [communications] [minor] Code cleanup so it can be extended by custom script --- selling/doctype/lead/get_leads.py | 20 +++++--------------- utilities/doctype/contact/contact.py | 2 +- website/helpers/contact.py | 4 ++-- website/templates/js/contact.js | 7 ++++++- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py index c376f450a4..c63468e2f0 100644 --- a/selling/doctype/lead/get_leads.py +++ b/selling/doctype/lead/get_leads.py @@ -9,17 +9,8 @@ from core.doctype.communication.communication import make def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): - def set_status(doctype, name): - w = webnotes.bean(doctype, name) - w.ignore_permissions = True - w.doc.status = is_system_user and "Replied" or status - w.doc.save() - if mail: - mail.save_attachments_in_doc(w.doc) - lead_name = webnotes.conn.get_value("Lead", {"email_id": sender}) contact_name = webnotes.conn.get_value("Contact", {"email_id": sender}) - is_system_user = webnotes.conn.get_value("Profile", sender) if not (lead_name or contact_name): # none, create a new Lead @@ -34,14 +25,13 @@ def add_sales_communication(subject, content, sender, real_name, mail=None, lead.insert() lead_name = lead.doc.name - make(content=content, sender=sender, subject=subject, + message = make(content=content, sender=sender, subject=subject, lead=lead_name, contact=contact_name, date=date) - if contact_name: - set_status("Contact", contact_name) - elif lead_name: - set_status("Lead", lead_name) - + if mail: + # save attachments to parent if from mail + bean = webnotes.bean("Contact" if contact_name else "Lead", contact_name or lead_name) + mail.save_attachments_in_doc(bean.doc) class SalesMailbox(POP3Mailbox): def setup(self, args=None): diff --git a/utilities/doctype/contact/contact.py b/utilities/doctype/contact/contact.py index 89cfc8e0df..961bb52153 100644 --- a/utilities/doctype/contact/contact.py +++ b/utilities/doctype/contact/contact.py @@ -7,7 +7,7 @@ from webnotes.utils import cstr from utilities.transaction_base import TransactionBase -class DocType(TransactionBase): +class DocType(TransactionBase): def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist diff --git a/website/helpers/contact.py b/website/helpers/contact.py index 05ae4f797e..35446a3d24 100644 --- a/website/helpers/contact.py +++ b/website/helpers/contact.py @@ -20,7 +20,7 @@ def send_message(subject="Website Query", message="", sender="", status="Open"): # make lead / communication from selling.doctype.lead.get_leads import add_sales_communication - add_sales_communication(subject or "Website Query", message, sender, sender, + message = add_sales_communication(subject or "Website Query", message, sender, sender, mail=None, status=status) # guest method, cap max writes per hour @@ -29,4 +29,4 @@ def send_message(subject="Website Query", message="", sender="", status="Open"): webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later" return - webnotes.response["message"] = 'Thank You' \ No newline at end of file + webnotes.response.status = "okay" diff --git a/website/templates/js/contact.js b/website/templates/js/contact.js index a28abba246..caec94512a 100644 --- a/website/templates/js/contact.js +++ b/website/templates/js/contact.js @@ -26,7 +26,12 @@ $(document).ready(function() { sender: email, message: message, callback: function(r) { - msgprint(r.message); + if(r.status==="okay") { + msgprint(r.message or "Sent") + } else { + msgprint("There were errors"); + console.log(r.exc); + } $(':input').val(''); } });