From 0e5401ccbf9726095ddd0246b66fecde8a931d97 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Feb 2013 15:08:24 +0530 Subject: [PATCH 1/5] 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` From d015dfce92da7e3baa1680f3462358c864047b79 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Feb 2013 15:10:53 +0530 Subject: [PATCH 2/5] sales communication fix for status --- selling/doctype/lead/get_leads.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py index c5e1434e5f..d1a4a3d411 100644 --- a/selling/doctype/lead/get_leads.py +++ b/selling/doctype/lead/get_leads.py @@ -24,7 +24,7 @@ def add_sales_communication(subject, content, sender, real_name, mail=None, stat def set_status(doctype, name): w = webnotes.model_wrapper(doctype, name) w.ignore_permissions = True - w.doc.status = status + w.doc.status = is_system_user and "Replied" or status w.doc.save() if mail: mail.save_attachments_in_doc(w.doc) @@ -50,9 +50,9 @@ def add_sales_communication(subject, content, sender, real_name, mail=None, stat lead=lead_name, contact=contact_name) if contact_name: - doc = set_status("Contact", contact_name, is_system_user and "Replied" or status) + set_status("Contact", contact_name) elif lead_name: - doc set_status("Lead", lead_name, is_system_user and "Replied" or status) + set_status("Lead", lead_name) class SalesMailbox(POP3Mailbox): From e38d783aff1660c6ae40e585906a32d71f4bc9d4 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Feb 2013 15:55:20 +0530 Subject: [PATCH 3/5] removed session timeout for getting emails --- hr/doctype/job_applicant/get_job_applications.py | 6 +----- selling/doctype/lead/get_leads.py | 6 +----- support/doctype/support_ticket/get_support_mails.py | 7 +------ 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/hr/doctype/job_applicant/get_job_applications.py b/hr/doctype/job_applicant/get_job_applications.py index 4484bc5039..64d7823ccf 100644 --- a/hr/doctype/job_applicant/get_job_applications.py +++ b/hr/doctype/job_applicant/get_job_applications.py @@ -23,11 +23,7 @@ from core.doctype.communication.communication import make class JobsMailbox(POP3Mailbox): def setup(self, args=None): self.settings = args or webnotes.doc("Jobs Email Settings", "Jobs Email Settings") - - def check_mails(self): - return webnotes.conn.sql("select user from tabSessions where \ - time_to_sec(timediff(now(), lastupdate)) < 1800") - + def process_message(self, mail): if mail.from_email == self.settings.email_id: return diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py index d1a4a3d411..08a9b1c297 100644 --- a/selling/doctype/lead/get_leads.py +++ b/selling/doctype/lead/get_leads.py @@ -58,11 +58,7 @@ def add_sales_communication(subject, content, sender, real_name, mail=None, stat class SalesMailbox(POP3Mailbox): def setup(self, args=None): self.settings = args or webnotes.doc("Sales Email Settings", "Sales Email Settings") - - def check_mails(self): - return webnotes.conn.sql("select user from tabSessions where \ - time_to_sec(timediff(now(), lastupdate)) < 1800") - + def process_message(self, mail): if mail.from_email == self.settings.email_id: return diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py index e0cbc0760a..99eaf6958a 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -30,12 +30,7 @@ class SupportMailbox(POP3Mailbox): "username": self.email_settings.support_username, "password": self.email_settings.support_password }) - - def check_mails(self): - self.auto_close_tickets() - return webnotes.conn.sql("select user from tabSessions where \ - time_to_sec(timediff(now(), lastupdate)) < 1800") - + def process_message(self, mail): if mail.from_email == self.email_settings.fields.get('support_email'): return From 629c1966069dbb4344c83eb8cf1f9617f73825f5 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Feb 2013 16:21:14 +0530 Subject: [PATCH 4/5] added date in pop3 mails --- hr/doctype/job_applicant/get_job_applications.py | 1 + selling/doctype/lead/get_leads.py | 7 ++++--- support/doctype/support_ticket/get_support_mails.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hr/doctype/job_applicant/get_job_applications.py b/hr/doctype/job_applicant/get_job_applications.py index 64d7823ccf..4737a6a81b 100644 --- a/hr/doctype/job_applicant/get_job_applications.py +++ b/hr/doctype/job_applicant/get_job_applications.py @@ -39,6 +39,7 @@ class JobsMailbox(POP3Mailbox): name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \ + mail.from_email applicant = webnotes.model_wrapper({ + "creation": mail.date, "doctype":"Job Applicant", "applicant_name": name, "email_id": mail.from_email, diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py index 08a9b1c297..cda74129dd 100644 --- a/selling/doctype/lead/get_leads.py +++ b/selling/doctype/lead/get_leads.py @@ -20,7 +20,8 @@ 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, status="Open"): +def add_sales_communication(subject, content, sender, real_name, mail=None, + status="Open", date=None): def set_status(doctype, name): w = webnotes.model_wrapper(doctype, name) w.ignore_permissions = True @@ -47,7 +48,7 @@ def add_sales_communication(subject, content, sender, real_name, mail=None, stat lead_name = lead.doc.name make(content=content, sender=sender, subject=subject, - lead=lead_name, contact=contact_name) + lead=lead_name, contact=contact_name, date=date) if contact_name: set_status("Contact", contact_name) @@ -64,7 +65,7 @@ class SalesMailbox(POP3Mailbox): return add_sales_communication(mail.subject, mail.content, mail.form_email, - mail.from_real_name, mail) + mail.from_real_name, mail=mail, date=mail.date) def get_leads(): if cint(webnotes.conn.get_value('Sales Email Settings', None, 'extract_emails')): diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py index 99eaf6958a..9e15236b3e 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -61,7 +61,7 @@ class SupportMailbox(POP3Mailbox): make(content=mail.content, sender=mail.from_email, doctype="Support Ticket", name=ticket.doc.name, - lead = ticket.doc.lead, contact=ticket.doc.contact) + lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date) def send_auto_reply(self, d): signature = self.email_settings.fields.get('support_signature') or '' From 9a8319dd0b6cbad11204105a00f5dc875be6d57c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Feb 2013 16:40:01 +0530 Subject: [PATCH 5/5] added date in pop3 mails --- support/doctype/support_ticket/get_support_mails.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py index 9e15236b3e..d431d8f135 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -59,7 +59,7 @@ class SupportMailbox(POP3Mailbox): mail.save_attachments_in_doc(ticket.doc) - make(content=mail.content, sender=mail.from_email, + make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject, doctype="Support Ticket", name=ticket.doc.name, lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date)