From 0e5401ccbf9726095ddd0246b66fecde8a931d97 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Feb 2013 15:08:24 +0530 Subject: [PATCH] sales communication fix for status --- selling/doctype/lead/get_leads.py | 44 +++++++++++++++---------------- website/helpers/contact.py | 3 ++- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py index c08e5e0a23..c5e1434e5f 100644 --- a/selling/doctype/lead/get_leads.py +++ b/selling/doctype/lead/get_leads.py @@ -20,11 +20,11 @@ from webnotes.utils import cstr, cint from webnotes.utils.email_lib.receive import POP3Mailbox from core.doctype.communication.communication import make -def add_sales_communication(subject, content, sender, real_name, mail=None): - def set_status_open(doctype, name): +def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open"): + def set_status(doctype, name): w = webnotes.model_wrapper(doctype, name) w.ignore_permissions = True - w.doc.status = "Open" + w.doc.status = status w.doc.save() if mail: mail.save_attachments_in_doc(w.doc) @@ -32,28 +32,28 @@ def add_sales_communication(subject, content, sender, real_name, mail=None): 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 is_system_user: - if contact_name: - set_status_open("Contact", contact_name) - elif lead_name: - set_status_open("Lead", lead_name) - else: - # none, create a new Lead - lead = webnotes.model_wrapper({ - "doctype":"Lead", - "lead_name": real_name or sender, - "email_id": sender, - "status": "Open", - "source": "Email" - }) - lead.ignore_permissions = True - lead.insert() - if mail: - mail.save_attachments_in_doc(lead.doc) + + if not (lead_name or contact_name): + # none, create a new Lead + lead = webnotes.model_wrapper({ + "doctype":"Lead", + "lead_name": real_name or sender, + "email_id": sender, + "status": status, + "source": "Email" + }) + lead.ignore_permissions = True + lead.insert() + lead_name = lead.doc.name make(content=content, sender=sender, subject=subject, lead=lead_name, contact=contact_name) + + if contact_name: + doc = set_status("Contact", contact_name, is_system_user and "Replied" or status) + elif lead_name: + doc set_status("Lead", lead_name, is_system_user and "Replied" or status) + class SalesMailbox(POP3Mailbox): def setup(self, args=None): diff --git a/website/helpers/contact.py b/website/helpers/contact.py index a16e2aa28f..251e1f6bb3 100644 --- a/website/helpers/contact.py +++ b/website/helpers/contact.py @@ -33,7 +33,8 @@ 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) + add_sales_communication(subject or "Website Query", message, sender, sender, + mail=None, status=status) # guest method, cap max writes per hour if webnotes.conn.sql("""select count(*) from `tabCommunication`