From fd1536b50bbdfc7e42dae251b67e51d3efabcce5 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 12:29:42 +0530 Subject: [PATCH 01/10] cleaned up support email --- support/doctype/newsletter/newsletter.py | 4 +- support/doctype/support_ticket/__init__.py | 87 ++++------------------ 2 files changed, 16 insertions(+), 75 deletions(-) diff --git a/support/doctype/newsletter/newsletter.py b/support/doctype/newsletter/newsletter.py index c4b622a1a3..48ed21a327 100644 --- a/support/doctype/newsletter/newsletter.py +++ b/support/doctype/newsletter/newsletter.py @@ -87,7 +87,7 @@ class DocType(): args = self.dt_map[doctype] - sender = self.doc.send_from or webnotes.utils.get_email_id(self.doc.owner) + sender = self.doc.send_from or webnotes.utils.get_formatted_email(self.doc.owner) recipients = self.doc.test_email_id.split(",") from webnotes.utils.email_lib.bulk import send send(recipients = recipients, sender = sender, @@ -109,7 +109,7 @@ class DocType(): recipients = self.get_recipients(query_key) else: recipients = query_key - sender = self.doc.send_from or webnotes.utils.get_email_id(self.doc.owner) + sender = self.doc.send_from or webnotes.utils.get_formatted_email(self.doc.owner) args = self.dt_map[doctype] self.send_count[doctype] = self.send_count.setdefault(doctype, 0) + \ len(recipients) diff --git a/support/doctype/support_ticket/__init__.py b/support/doctype/support_ticket/__init__.py index da1755feb9..113671462b 100644 --- a/support/doctype/support_ticket/__init__.py +++ b/support/doctype/support_ticket/__init__.py @@ -22,17 +22,7 @@ from webnotes.utils.email_lib.receive import POP3Mailbox class SupportMailbox(POP3Mailbox): def __init__(self): - """ - settings_doc must contain - use_ssl, host, username, password - """ - from webnotes.model.doc import Document - - # extract email settings - self.email_settings = Document('Email Settings','Email Settings') - if not self.email_settings.fields.get('sync_support_mails'): return - - s = Document('Support Email Settings') + s = webnotes.doc('Support Email Settings') s.use_ssl = self.email_settings.support_use_ssl s.host = self.email_settings.support_host s.username = self.email_settings.support_username @@ -41,37 +31,15 @@ class SupportMailbox(POP3Mailbox): POP3Mailbox.__init__(self, s) def check_mails(self): - """ - returns true if there are active sessions - """ self.auto_close_tickets() - return webnotes.conn.sql("select user from tabSessions where time_to_sec(timediff(now(), lastupdate)) < 1800") + return webnotes.conn.sql("select user from tabSessions where \ + time_to_sec(timediff(now(), lastupdate)) < 1800") def process_message(self, mail): - """ - Updates message from support email as either new or reply - """ from home import update_feed - - content, content_type = '[Blank Email]', 'text/plain' - if mail.text_content: - content, content_type = mail.text_content, 'text/plain' - else: - content, content_type = mail.html_content, 'text/html' thread_list = mail.get_thread_id() - email_id = mail.mail['From'] - if "<" in mail.mail['From']: - import re - re_result = re.findall('(?<=\<)(\S+)(?=\>)', mail.mail['From']) - if re_result and re_result[0]: - email_id = re_result[0] - - from webnotes.utils import decode_email_header - - full_email_id = decode_email_header(mail.mail['From']) - for thread_id in thread_list: exists = webnotes.conn.sql("""\ SELECT name @@ -83,7 +51,8 @@ class SupportMailbox(POP3Mailbox): from core.doctype.communication.communication import make - make(content=content, sender=full_email_id, doctype="Support Ticket", + make(content=mail.content, sender=mail.from_email, + doctype="Support Ticket", name=thread_id, lead = st.doc.lead, contact=st.doc.contact) st.doc.status = 'Open' @@ -91,7 +60,7 @@ class SupportMailbox(POP3Mailbox): update_feed(st, 'on_update') # extract attachments - self.save_attachments(st.doc, mail.attachments) + mail.save_attachments_in_doc(st.doc) return from webnotes.model.doctype import get_property @@ -99,21 +68,17 @@ class SupportMailbox(POP3Mailbox): # new ticket from webnotes.model.doc import Document d = Document('Support Ticket') - d.description = content + d.description = mail.content - d.subject = decode_email_header(mail.mail['Subject']) + d.subject = mail.mail['Subject'] - d.raised_by = full_email_id - d.content_type = content_type + d.raised_by = mail.from_email + d.content_type = mail.content_type d.status = 'Open' d.naming_series = opts and opts.split("\n")[0] or 'SUP' try: d.save(1) - try: - # extract attachments - self.save_attachments(d, mail.attachments) - except Exception, e: - self.description += "\n\n[Did not pull attachment]" + mail.save_attachments_in_doc(d) except: d.description = 'Unable to extract message' d.save(1) @@ -122,28 +87,8 @@ class SupportMailbox(POP3Mailbox): if cint(self.email_settings.send_autoreply): if "mailer-daemon" not in d.raised_by.lower(): self.send_auto_reply(d) - - - def save_attachments(self, doc, attachment_list=[]): - """ - Saves attachments from email - - attachment_list is a list of dict containing: - 'filename', 'content', 'content-type' - """ - from webnotes.utils.file_manager import save_file, add_file_list - for attachment in attachment_list: - fid = save_file(attachment['filename'], attachment['content'], 'Support') - status = add_file_list('Support Ticket', doc.name, fid, fid) - if not status: - doc.description = doc.description \ - + "\nCould not attach: " + cstr(attachment['filename']) - doc.save() def send_auto_reply(self, d): - """ - Send auto reply to emails - """ from webnotes.utils import cstr signature = self.email_settings.fields.get('support_signature') or '' @@ -167,16 +112,12 @@ Original Query: msg = cstr(response)) def auto_close_tickets(self): - """ - Auto Closes Waiting for Customer Support Ticket after 15 days - """ - webnotes.conn.sql("update `tabSupport Ticket` set status = 'Closed' where status = 'Waiting for Customer' and date_sub(curdate(),interval 15 Day) > modified") + webnotes.conn.sql("""update `tabSupport Ticket` set status = 'Closed' + where status = 'Waiting for Customer' + and date_sub(curdate(),interval 15 Day) > modified""") def get_support_mails(): - """ - Gets new emails from support inbox and updates / creates Support Ticket records - """ import webnotes from webnotes.utils import cint if cint(webnotes.conn.get_value('Email Settings', None, 'sync_support_mails')): From 971ccf9c0f5e3b233fec0484195bfe977c529478 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 12:46:17 +0530 Subject: [PATCH 02/10] support fixes --- support/doctype/support_ticket/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/support/doctype/support_ticket/__init__.py b/support/doctype/support_ticket/__init__.py index 113671462b..81a5050725 100644 --- a/support/doctype/support_ticket/__init__.py +++ b/support/doctype/support_ticket/__init__.py @@ -22,6 +22,7 @@ from webnotes.utils.email_lib.receive import POP3Mailbox class SupportMailbox(POP3Mailbox): def __init__(self): + self.email_settings = webnotes.doc("Email Settings") s = webnotes.doc('Support Email Settings') s.use_ssl = self.email_settings.support_use_ssl s.host = self.email_settings.support_host From 8e10cea6d6acc040f272d28f2ac52909d559181c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 12:51:01 +0530 Subject: [PATCH 03/10] support fixes --- support/doctype/support_ticket/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/doctype/support_ticket/__init__.py b/support/doctype/support_ticket/__init__.py index 81a5050725..85ee89a7b8 100644 --- a/support/doctype/support_ticket/__init__.py +++ b/support/doctype/support_ticket/__init__.py @@ -22,7 +22,7 @@ from webnotes.utils.email_lib.receive import POP3Mailbox class SupportMailbox(POP3Mailbox): def __init__(self): - self.email_settings = webnotes.doc("Email Settings") + self.email_settings = webnotes.doc("Email Settings", "Email Settings") s = webnotes.doc('Support Email Settings') s.use_ssl = self.email_settings.support_use_ssl s.host = self.email_settings.support_host From 3e4f3405646a0ad81a57c36021efec88b07153f3 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 12:54:31 +0530 Subject: [PATCH 04/10] support fixes --- support/doctype/support_ticket/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/doctype/support_ticket/__init__.py b/support/doctype/support_ticket/__init__.py index 85ee89a7b8..316eff8086 100644 --- a/support/doctype/support_ticket/__init__.py +++ b/support/doctype/support_ticket/__init__.py @@ -46,7 +46,7 @@ class SupportMailbox(POP3Mailbox): SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s - """ , (thread_id, '(' + email_id + ')')) + """ , (thread_id, '(' + mail.from_email + ')')) if exists and exists[0] and exists[0][0]: st = webnotes.get_obj('Support Ticket', thread_id) From 133d752ca4a32652aa665e9b3799c61e4f336488 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 14:17:31 +0530 Subject: [PATCH 05/10] cleanup get_support_ticket --- startup/schedule_handlers.py | 2 +- support/doctype/support_ticket/__init__.py | 125 ------------------ .../support_ticket/get_support_mails.py | 94 +++++++++++++ .../doctype/support_ticket/support_ticket.js | 16 ++- 4 files changed, 106 insertions(+), 131 deletions(-) create mode 100644 support/doctype/support_ticket/get_support_mails.py diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py index 668c11d92c..54b9892b13 100644 --- a/startup/schedule_handlers.py +++ b/startup/schedule_handlers.py @@ -26,7 +26,7 @@ def execute_all(): * recurring invoice """ # pull emails - from support.doctype.support_ticket import get_support_mails + from support.doctype.support_ticket.get_support_mails import get_support_mails run_fn(get_support_mails) # bulk email diff --git a/support/doctype/support_ticket/__init__.py b/support/doctype/support_ticket/__init__.py index 316eff8086..e69de29bb2 100644 --- a/support/doctype/support_ticket/__init__.py +++ b/support/doctype/support_ticket/__init__.py @@ -1,125 +0,0 @@ -# ERPNext - web based ERP (http://erpnext.com) -# Copyright (C) 2012 Web Notes Technologies Pvt Ltd -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -from __future__ import unicode_literals -import webnotes -from webnotes.utils import cstr, cint - -from webnotes.utils.email_lib.receive import POP3Mailbox - -class SupportMailbox(POP3Mailbox): - def __init__(self): - self.email_settings = webnotes.doc("Email Settings", "Email Settings") - s = webnotes.doc('Support Email Settings') - s.use_ssl = self.email_settings.support_use_ssl - s.host = self.email_settings.support_host - s.username = self.email_settings.support_username - s.password = self.email_settings.support_password - - POP3Mailbox.__init__(self, s) - - 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): - from home import update_feed - - thread_list = mail.get_thread_id() - - for thread_id in thread_list: - exists = webnotes.conn.sql("""\ - SELECT name - FROM `tabSupport Ticket` - WHERE name=%s AND raised_by REGEXP %s - """ , (thread_id, '(' + mail.from_email + ')')) - if exists and exists[0] and exists[0][0]: - st = webnotes.get_obj('Support Ticket', thread_id) - - from core.doctype.communication.communication import make - - make(content=mail.content, sender=mail.from_email, - doctype="Support Ticket", - name=thread_id, lead = st.doc.lead, contact=st.doc.contact) - - st.doc.status = 'Open' - st.doc.save() - - update_feed(st, 'on_update') - # extract attachments - mail.save_attachments_in_doc(st.doc) - return - - from webnotes.model.doctype import get_property - opts = get_property('Support Ticket', 'options', 'naming_series') - # new ticket - from webnotes.model.doc import Document - d = Document('Support Ticket') - d.description = mail.content - - d.subject = mail.mail['Subject'] - - d.raised_by = mail.from_email - d.content_type = mail.content_type - d.status = 'Open' - d.naming_series = opts and opts.split("\n")[0] or 'SUP' - try: - d.save(1) - mail.save_attachments_in_doc(d) - except: - d.description = 'Unable to extract message' - d.save(1) - else: - # send auto reply - if cint(self.email_settings.send_autoreply): - if "mailer-daemon" not in d.raised_by.lower(): - self.send_auto_reply(d) - - def send_auto_reply(self, d): - from webnotes.utils import cstr - - signature = self.email_settings.fields.get('support_signature') or '' - - response = self.email_settings.fields.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 ----------------------- -Original Query: - -""" + d.description + "\n----------------------\n" + cstr(signature)) - - from webnotes.utils.email_lib import sendmail - - sendmail(\ - recipients = [cstr(d.raised_by)], \ - sender = cstr(self.email_settings.fields.get('support_email')), \ - subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \ - msg = cstr(response)) - - def auto_close_tickets(self): - webnotes.conn.sql("""update `tabSupport Ticket` set status = 'Closed' - where status = 'Waiting for Customer' - and date_sub(curdate(),interval 15 Day) > modified""") - - -def get_support_mails(): - import webnotes - from webnotes.utils import cint - if cint(webnotes.conn.get_value('Email Settings', None, 'sync_support_mails')): - SupportMailbox().get_messages() \ No newline at end of file diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py new file mode 100644 index 0000000000..204ca3431f --- /dev/null +++ b/support/doctype/support_ticket/get_support_mails.py @@ -0,0 +1,94 @@ +# ERPNext - web based ERP (http://erpnext.com) +# Copyright (C) 2012 Web Notes Technologies Pvt Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from __future__ import unicode_literals +import webnotes +from webnotes.utils import cstr, cint +from webnotes.utils.email_lib import sendmail +from webnotes.utils.email_lib.receive import POP3Mailbox +from core.doctype.communication.communication import make + +class SupportMailbox(POP3Mailbox): + def setup(self): + self.email_settings = webnotes.doc("Email Settings", "Email Settings") + self.settings = webnotes._dict({ + "use_ssl": self.email_settings.support_use_ssl, + "host": self.email_settings.support_host, + "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): + thread_id = mail.get_thread_id() + ticket = None + + if thread_id and webnotes.conn.exists("Support Ticket", thread_id): + ticket = webnotes.model_wrapper("Support Ticket", thread_id) + ticket.doc.status = 'Open' + ticket.doc.save() + + else: + ticket = webnotes.model_wrapper([{ + "doctype":"Support Ticket", + "description": mail.content, + "subject": mail.mail["Subject"], + "raised_by": mail.from_email, + "content_type": mail.content_type, + "status": "Open" + }]) + ticket.insert() + + if cint(self.email_settings.send_autoreply): + if "mailer-daemon" not in mail.from_email.lower(): + self.send_auto_reply(ticket.doc) + + mail.save_attachments_in_doc(ticket.doc) + + make(content=mail.content, sender=mail.from_email, + doctype="Support Ticket", + name=thread_id, lead = st.doc.lead, contact=st.doc.contact) + + def send_auto_reply(self, d): + signature = self.email_settings.fields.get('support_signature') or '' + response = self.email_settings.fields.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 +---------------------- +Original Query: + +""" + d.description + "\n----------------------\n" + cstr(signature)) + + sendmail(\ + recipients = [cstr(d.raised_by)], \ + sender = cstr(self.email_settings.fields.get('support_email')), \ + subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \ + msg = cstr(response)) + + def auto_close_tickets(self): + webnotes.conn.sql("""update `tabSupport Ticket` set status = 'Closed' + where status = 'Waiting for Customer' + and date_sub(curdate(),interval 15 Day) > modified""") + +def get_support_mails(): + if cint(webnotes.conn.get_value('Email Settings', None, 'sync_support_mails')): + SupportMailbox() \ No newline at end of file diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js index 159dddd62a..28b08f8ccb 100644 --- a/support/doctype/support_ticket/support_ticket.js +++ b/support/doctype/support_ticket/support_ticket.js @@ -49,11 +49,17 @@ $.extend(cur_frm.cscript, { var wrapper = cur_frm.fields_dict['thread_html'].wrapper; var comm_list = wn.model.get("Communication", {"support_ticket": doc.name}) - comm_list.push({ - "sender": doc.raised_by, - "creation": doc.creation, - "modified": doc.creation, - "content": doc.description}); + + var sortfn = function (a, b) { return (b.creation > a.creation) ? 1 : -1; } + comm_list = comm_list.sort(sortfn); + + if(!comm_list.length || (comm_list[0].sender != doc.raised_by)) { + comm_list.push({ + "sender": doc.raised_by, + "creation": doc.creation, + "modified": doc.creation, + "content": doc.description}); + } cur_frm.communication_view = new wn.views.CommunicationList({ list: comm_list, From c6bdbe62036e8a3cd987978bed5454c2af0d5eb0 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 14:26:45 +0530 Subject: [PATCH 06/10] cleanup get_support_ticket --- 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 204ca3431f..bb0c008444 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -28,7 +28,7 @@ class SupportMailbox(POP3Mailbox): "use_ssl": self.email_settings.support_use_ssl, "host": self.email_settings.support_host, "username": self.email_settings.support_username, - "password", self.email_settings.support_password + "password": self.email_settings.support_password }) def check_mails(self): From 8a8c5ad74cf8a0973a3821afe70973e2a0d5b9c6 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 14:30:08 +0530 Subject: [PATCH 07/10] cleanup get_support_ticket --- 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 bb0c008444..12c2fbc770 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -64,7 +64,7 @@ class SupportMailbox(POP3Mailbox): make(content=mail.content, sender=mail.from_email, doctype="Support Ticket", - name=thread_id, lead = st.doc.lead, contact=st.doc.contact) + name=thread_id, lead = ticket.doc.lead, contact=ticket.doc.contact) def send_auto_reply(self, d): signature = self.email_settings.fields.get('support_signature') or '' From 64eff9124e4cb488453a13649c631a8a9b403e79 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 14:38:29 +0530 Subject: [PATCH 08/10] cleanup get_support_ticket --- support/doctype/support_ticket/get_support_mails.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py index 12c2fbc770..e5e99f5942 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -63,8 +63,8 @@ class SupportMailbox(POP3Mailbox): mail.save_attachments_in_doc(ticket.doc) make(content=mail.content, sender=mail.from_email, - doctype="Support Ticket", - name=thread_id, lead = ticket.doc.lead, contact=ticket.doc.contact) + doctype="Support Ticket", name=ticket.doc.name, + lead = ticket.doc.lead, contact=ticket.doc.contact) def send_auto_reply(self, d): signature = self.email_settings.fields.get('support_signature') or '' From 0e7751b9feb6f1109a336ba21654cbe0ce0a34d9 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 16:38:16 +0530 Subject: [PATCH 09/10] added job_applicant, job_opening doctypes --- hr/doctype/job_applicant/__init__.py | 0 hr/doctype/job_applicant/job_applicant.py | 8 ++ hr/doctype/job_applicant/job_applicant.txt | 84 +++++++++++++++++++ hr/doctype/job_opening/__init__.py | 0 hr/doctype/job_opening/job_opening.py | 8 ++ hr/doctype/job_opening/job_opening.txt | 66 +++++++++++++++ .../support_ticket/get_support_mails.py | 2 + 7 files changed, 168 insertions(+) create mode 100644 hr/doctype/job_applicant/__init__.py create mode 100644 hr/doctype/job_applicant/job_applicant.py create mode 100644 hr/doctype/job_applicant/job_applicant.txt create mode 100644 hr/doctype/job_opening/__init__.py create mode 100644 hr/doctype/job_opening/job_opening.py create mode 100644 hr/doctype/job_opening/job_opening.txt diff --git a/hr/doctype/job_applicant/__init__.py b/hr/doctype/job_applicant/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/hr/doctype/job_applicant/job_applicant.py b/hr/doctype/job_applicant/job_applicant.py new file mode 100644 index 0000000000..928aa9ff9f --- /dev/null +++ b/hr/doctype/job_applicant/job_applicant.py @@ -0,0 +1,8 @@ +# For license information, please see license.txt + +from __future__ import unicode_literals +import webnotes + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d, dl \ No newline at end of file diff --git a/hr/doctype/job_applicant/job_applicant.txt b/hr/doctype/job_applicant/job_applicant.txt new file mode 100644 index 0000000000..3031211f3b --- /dev/null +++ b/hr/doctype/job_applicant/job_applicant.txt @@ -0,0 +1,84 @@ +[ + { + "owner": "Administrator", + "docstatus": 0, + "creation": "2013-01-15 16:32:13", + "modified_by": "Administrator", + "modified": "2013-01-15 16:32:13" + }, + { + "autoname": "field:applicant_name", + "description": "Applicant for a Job", + "doctype": "DocType", + "module": "HR", + "document_type": "Transaction", + "name": "__common__" + }, + { + "name": "__common__", + "parent": "Job Applicant", + "doctype": "DocField", + "parenttype": "DocType", + "permlevel": 0, + "parentfield": "fields" + }, + { + "parent": "Job Applicant", + "read": 1, + "cancel": 1, + "name": "__common__", + "create": 1, + "doctype": "DocPerm", + "write": 1, + "parenttype": "DocType", + "role": "HR User", + "report": 1, + "permlevel": 0, + "parentfield": "permissions" + }, + { + "name": "Job Applicant", + "doctype": "DocType" + }, + { + "doctype": "DocField", + "label": "Applicant Name", + "fieldname": "applicant_name", + "fieldtype": "Data", + "reqd": 1 + }, + { + "doctype": "DocField", + "label": "Status", + "fieldname": "status", + "fieldtype": "Select", + "options": "Open\nReject\nHold" + }, + { + "doctype": "DocField", + "width": "50%", + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "doctype": "DocField", + "label": "Job Opening", + "fieldname": "job_opening", + "fieldtype": "Link", + "options": "Job Opening" + }, + { + "doctype": "DocField", + "fieldname": "section_break_5", + "fieldtype": "Section Break" + }, + { + "doctype": "DocField", + "label": "Thread HTML", + "fieldname": "thread_html", + "fieldtype": "HTML" + }, + { + "doctype": "DocPerm" + } +] \ No newline at end of file diff --git a/hr/doctype/job_opening/__init__.py b/hr/doctype/job_opening/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/hr/doctype/job_opening/job_opening.py b/hr/doctype/job_opening/job_opening.py new file mode 100644 index 0000000000..928aa9ff9f --- /dev/null +++ b/hr/doctype/job_opening/job_opening.py @@ -0,0 +1,8 @@ +# For license information, please see license.txt + +from __future__ import unicode_literals +import webnotes + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d, dl \ No newline at end of file diff --git a/hr/doctype/job_opening/job_opening.txt b/hr/doctype/job_opening/job_opening.txt new file mode 100644 index 0000000000..bd994c6ad9 --- /dev/null +++ b/hr/doctype/job_opening/job_opening.txt @@ -0,0 +1,66 @@ +[ + { + "owner": "Administrator", + "docstatus": 0, + "creation": "2013-01-15 16:13:36", + "modified_by": "Administrator", + "modified": "2013-01-15 16:13:36" + }, + { + "description": "Description of a Job Opening", + "doctype": "DocType", + "module": "HR", + "document_type": "Transaction", + "name": "__common__" + }, + { + "name": "__common__", + "parent": "Job Opening", + "doctype": "DocField", + "parenttype": "DocType", + "permlevel": 0, + "parentfield": "fields" + }, + { + "parent": "Job Opening", + "read": 1, + "cancel": 1, + "name": "__common__", + "create": 1, + "doctype": "DocPerm", + "write": 1, + "parenttype": "DocType", + "role": "HR User", + "report": 1, + "permlevel": 0, + "parentfield": "permissions" + }, + { + "name": "Job Opening", + "doctype": "DocType" + }, + { + "doctype": "DocField", + "label": "Job Title", + "fieldname": "job_title", + "fieldtype": "Data", + "reqd": 1 + }, + { + "doctype": "DocField", + "label": "Status", + "fieldname": "status", + "fieldtype": "Select", + "options": "Open\nClosed" + }, + { + "description": "Job profile, qualifications required etc.", + "doctype": "DocField", + "label": "Description", + "fieldname": "description", + "fieldtype": "Text Editor" + }, + { + "doctype": "DocPerm" + } +] \ No newline at end of file diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py index e5e99f5942..c0b85e49b8 100644 --- a/support/doctype/support_ticket/get_support_mails.py +++ b/support/doctype/support_ticket/get_support_mails.py @@ -37,6 +37,8 @@ class SupportMailbox(POP3Mailbox): time_to_sec(timediff(now(), lastupdate)) < 1800") def process_message(self, mail): + if mail.from_email == self.email_settings.fields.get('support_email'): + return thread_id = mail.get_thread_id() ticket = None From 3169ef06919b3f923aaf16041dc1e077ac8bcd81 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 15 Jan 2013 17:23:23 +0530 Subject: [PATCH 10/10] added job application --- .../job_applicant/get_job_applications.py | 55 ++++++++++++ hr/doctype/job_applicant/job_applicant.js | 22 +++++ hr/doctype/job_applicant/job_applicant.txt | 8 +- hr/doctype/job_opening/job_opening.txt | 3 +- setup/doctype/jobs_email_settings/__init__.py | 0 .../jobs_email_settings.js | 12 +++ .../jobs_email_settings.py | 17 ++++ .../jobs_email_settings.txt | 89 +++++++++++++++++++ startup/schedule_handlers.py | 3 + .../doctype/support_ticket/support_ticket.js | 11 +-- 10 files changed, 208 insertions(+), 12 deletions(-) create mode 100644 hr/doctype/job_applicant/get_job_applications.py create mode 100644 hr/doctype/job_applicant/job_applicant.js create mode 100644 setup/doctype/jobs_email_settings/__init__.py create mode 100644 setup/doctype/jobs_email_settings/jobs_email_settings.js create mode 100644 setup/doctype/jobs_email_settings/jobs_email_settings.py create mode 100644 setup/doctype/jobs_email_settings/jobs_email_settings.txt diff --git a/hr/doctype/job_applicant/get_job_applications.py b/hr/doctype/job_applicant/get_job_applications.py new file mode 100644 index 0000000000..c5066dcc4e --- /dev/null +++ b/hr/doctype/job_applicant/get_job_applications.py @@ -0,0 +1,55 @@ +# ERPNext - web based ERP (http://erpnext.com) +# Copyright (C) 2012 Web Notes Technologies Pvt Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from __future__ import unicode_literals +import webnotes +from webnotes.utils import cstr, cint +from webnotes.utils.email_lib.receive import POP3Mailbox +from core.doctype.communication.communication import make + +class JobsMailbox(POP3Mailbox): + def setup(self): + self.settings = 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 get_existing_application(self, email_id): + name = webnotes.conn.sql("""select name from `tabJob Applicant` where + email_id = %s""", email_id) + return name and name[0][0] or None + + def process_message(self, mail): + name = self.get_existing_application(mail.from_email) + if name: + applicant = webnotes.model_wrapper("Job Applicant", name) + else: + applicant = webnotes.model_wrapper({ + "doctype":"Job Applicant", + "applicant_name": mail.from_real_name or mail.from_email, + "email_id": mail.from_email + }) + applicant.insert() + + mail.save_attachments_in_doc(applicant.doc) + + make(content=mail.content, sender=mail.from_email, + doctype="Job Applicant", name=applicant.doc.name, set_lead=False) + +def get_job_applications(): + if cint(webnotes.conn.get_value('Jobs Email Settings', None, 'extract_emails')): + JobsMailbox() \ No newline at end of file diff --git a/hr/doctype/job_applicant/job_applicant.js b/hr/doctype/job_applicant/job_applicant.js new file mode 100644 index 0000000000..2b8e064e8d --- /dev/null +++ b/hr/doctype/job_applicant/job_applicant.js @@ -0,0 +1,22 @@ +// For license information, please see license.txt + +cur_frm.cscript = { + refresh: function(doc) { + cur_frm.set_intro(""); + if(doc.extract_emails) { + cur_frm.set_intro(wn._("Active: Will extract emails from ") + doc.email_id); + } else { + cur_frm.set_intro(wn._("Not Active")); + } + cur_frm.cscript.make_listing(doc); + }, + make_listing: function(doc) { + var wrapper = cur_frm.fields_dict['thread_html'].wrapper; + cur_frm.communication_view = new wn.views.CommunicationList({ + list: comm_list, + parent: wn.model.get("Communication", {"job_applicant": doc.name}), + doc: doc, + recipients: doc.email_id + }) + }, +} \ No newline at end of file diff --git a/hr/doctype/job_applicant/job_applicant.txt b/hr/doctype/job_applicant/job_applicant.txt index 3031211f3b..390b659a99 100644 --- a/hr/doctype/job_applicant/job_applicant.txt +++ b/hr/doctype/job_applicant/job_applicant.txt @@ -4,7 +4,7 @@ "docstatus": 0, "creation": "2013-01-15 16:32:13", "modified_by": "Administrator", - "modified": "2013-01-15 16:32:13" + "modified": "2013-01-15 17:08:46" }, { "autoname": "field:applicant_name", @@ -47,6 +47,12 @@ "fieldtype": "Data", "reqd": 1 }, + { + "doctype": "DocField", + "label": "Email Id", + "fieldname": "email_id", + "fieldtype": "Data" + }, { "doctype": "DocField", "label": "Status", diff --git a/hr/doctype/job_opening/job_opening.txt b/hr/doctype/job_opening/job_opening.txt index bd994c6ad9..5e26f0d1c1 100644 --- a/hr/doctype/job_opening/job_opening.txt +++ b/hr/doctype/job_opening/job_opening.txt @@ -4,9 +4,10 @@ "docstatus": 0, "creation": "2013-01-15 16:13:36", "modified_by": "Administrator", - "modified": "2013-01-15 16:13:36" + "modified": "2013-01-15 16:43:05" }, { + "autoname": "field:job_title", "description": "Description of a Job Opening", "doctype": "DocType", "module": "HR", diff --git a/setup/doctype/jobs_email_settings/__init__.py b/setup/doctype/jobs_email_settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/jobs_email_settings/jobs_email_settings.js b/setup/doctype/jobs_email_settings/jobs_email_settings.js new file mode 100644 index 0000000000..0a75b89360 --- /dev/null +++ b/setup/doctype/jobs_email_settings/jobs_email_settings.js @@ -0,0 +1,12 @@ +// For license information, please see license.txt + +cur_frm.cscript = { + refresh: function(doc) { + cur_frm.set_intro(""); + if(doc.extract_emails) { + cur_frm.set_intro(wn._("Active: Will extract emails from ") + doc.email_id); + } else { + cur_frm.set_intro(wn._("Not Active")); + } + } +} \ No newline at end of file diff --git a/setup/doctype/jobs_email_settings/jobs_email_settings.py b/setup/doctype/jobs_email_settings/jobs_email_settings.py new file mode 100644 index 0000000000..b09cefd5e2 --- /dev/null +++ b/setup/doctype/jobs_email_settings/jobs_email_settings.py @@ -0,0 +1,17 @@ +# For license information, please see license.txt + +from __future__ import unicode_literals +import webnotes +from webnotes import _ +from webnotes.utils import cint + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d, dl + + def validate(self): + if cint(self.doc.extract_emails) and not (self.doc.email_id and self.doc.host and \ + self.doc.username and self.doc.password): + + webnotes.msgprint(_("""Host, Email and Password required if emails are to be pulled"""), + raise_exception=True) \ No newline at end of file diff --git a/setup/doctype/jobs_email_settings/jobs_email_settings.txt b/setup/doctype/jobs_email_settings/jobs_email_settings.txt new file mode 100644 index 0000000000..788f51b7e9 --- /dev/null +++ b/setup/doctype/jobs_email_settings/jobs_email_settings.txt @@ -0,0 +1,89 @@ +[ + { + "owner": "Administrator", + "docstatus": 0, + "creation": "2013-01-15 16:50:01", + "modified_by": "Administrator", + "modified": "2013-01-15 16:57:08" + }, + { + "issingle": 1, + "description": "Email settings for jobs email id \"jobs@example.com\"", + "doctype": "DocType", + "module": "Setup", + "name": "__common__" + }, + { + "name": "__common__", + "parent": "Jobs Email Settings", + "doctype": "DocField", + "parenttype": "DocType", + "permlevel": 0, + "parentfield": "fields" + }, + { + "parent": "Jobs Email Settings", + "read": 1, + "name": "__common__", + "create": 1, + "doctype": "DocPerm", + "write": 1, + "parenttype": "DocType", + "role": "System Manager", + "permlevel": 0, + "parentfield": "permissions" + }, + { + "name": "Jobs Email Settings", + "doctype": "DocType" + }, + { + "description": "Settings to extract Job Applicants from a mailbox e.g. \"jobs@example.com\"", + "doctype": "DocField", + "label": "POP3 Mail Settings", + "fieldname": "pop3_mail_settings", + "fieldtype": "Section Break" + }, + { + "description": "Check to activate", + "doctype": "DocField", + "label": "Extract Emails", + "fieldname": "extract_emails", + "fieldtype": "Check" + }, + { + "description": "Email Id where a job applicant will email e.g. \"jobs@example.com\"", + "doctype": "DocField", + "label": "Email Id", + "fieldname": "email_id", + "fieldtype": "Data" + }, + { + "description": "POP3 server e.g. (pop.gmail.com)", + "doctype": "DocField", + "label": "Host", + "fieldname": "host", + "fieldtype": "Data" + }, + { + "doctype": "DocField", + "label": "Use SSL", + "fieldname": "use_ssl", + "fieldtype": "Check" + }, + { + "doctype": "DocField", + "label": "Username", + "fieldname": "username", + "fieldtype": "Data" + }, + { + "doctype": "DocField", + "label": "Password", + "fieldname": "password", + "fieldtype": "Password" + }, + { + "doctype": "DocPerm" + } +] \ No newline at end of file diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py index 54b9892b13..ab53b211ed 100644 --- a/startup/schedule_handlers.py +++ b/startup/schedule_handlers.py @@ -28,6 +28,9 @@ def execute_all(): # pull emails from support.doctype.support_ticket.get_support_mails import get_support_mails run_fn(get_support_mails) + + from hr.doctype.job_applicant.get_job_applications import get_job_applications + run_fn(get_job_applications) # bulk email from webnotes.utils.email_lib.bulk import flush diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js index 28b08f8ccb..bbaf95b523 100644 --- a/support/doctype/support_ticket/support_ticket.js +++ b/support/doctype/support_ticket/support_ticket.js @@ -69,16 +69,7 @@ $.extend(cur_frm.cscript, { }) }, - - send: function(doc, dt, dn) { - $c_obj(make_doclist(doc.doctype, doc.name), 'send_response', '', function(r,rt) { - locals[dt][dn].new_response = ''; - if(!(r.exc || r.server_messages)) { - cur_frm.refresh(); - } - }); - }, - + customer: function(doc, dt, dn) { var callback = function(r,rt) { var doc = locals[cur_frm.doctype][cur_frm.docname];