diff --git a/erpnext/support/doctype/newsletter/__init__.py b/erpnext/support/doctype/newsletter/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/support/doctype/newsletter/newsletter.js b/erpnext/support/doctype/newsletter/newsletter.js new file mode 100644 index 00000000000..1eadff3ad7c --- /dev/null +++ b/erpnext/support/doctype/newsletter/newsletter.js @@ -0,0 +1,25 @@ +// 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 . + +cur_frm.cscript.refresh = function(doc) { + if(!doc.__islocal && !cint(doc.email_sent) && !doc.__unsaved) { + cur_frm.add_custom_button('Send', function() { + $c_obj(make_doclist(doc.doctype, doc.name), 'send_emails', '', function(r) { + cur_frm.refresh(); + }); + }) + } +} \ No newline at end of file diff --git a/erpnext/support/doctype/newsletter/newsletter.py b/erpnext/support/doctype/newsletter/newsletter.py new file mode 100644 index 00000000000..51f7938e34f --- /dev/null +++ b/erpnext/support/doctype/newsletter/newsletter.py @@ -0,0 +1,107 @@ +# 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 + +class DocType(): + def __init__(self, d, dl): + self.doc, self.doclist = d, dl + self.dt_map = { + "Contact": { + "email_field": "email_id", + "first_name_field": "first_name", + }, + "Lead": { + "email_field": "email_id", + "first_name_field": "lead_name" + } + } + self.query_map = { + "contacts": """select distinct email_id from `tabContact` + where ifnull(email_id, '') != '' """, + "customer_contacts": """select distinct email_id from `tabContact` + where ifnull(customer, '') != '' and ifnull(email_id, '') != '' """, + "leads": """select distinct email_id from `tabLead` + where ifnull(email_id, '') != '' """, + "active_leads": """select distinct email_id from `tabLead` + where status = "Open" and ifnull(email_id, '') != '' """, + "blog_subscribers": """select distinct email_id from `tabLead` + where ifnull(blog_subscriber,0) = 1 and ifnull(email_id, '') != '' """ + } + + def autoname(self): + from webnotes.model.doc import make_autoname + self.doc.name = make_autoname(self.doc.naming_series+ '.#####') + + def send_emails(self): + """send emails to leads and customers""" + # TODO: create unsubscribed check in customer + if self.doc.email_sent: + webnotes.msgprint("""Newsletter has already been sent""", raise_exception=1) + + self.all_recipients = [] + self.send_count = {} + + if self.doc.contacts: + self.send("contacts", "Contact") + elif self.doc.customer_contacts: + self.send("customer_contacts", "Contact") + + if self.doc.leads: + self.send("leads", "Lead") + else: + if self.doc.active_leads: + self.send("active_leads", "Lead") + + if self.doc.blog_subscribers: + self.send("blog_subscribers", "Lead") + + webnotes.conn.set(self.doc, "email_sent", 1) + webnotes.msgprint("""Scheduled to send to %s""" % \ + ", ".join(["%d %s(s)" % (self.send_count[s], s) for s in self.send_count])) + + def test_send(self, doctype="Lead"): + args = self.dt_map[doctype] + recipients = self.doc.test_email_id.split(",") + from webnotes.utils.email_lib.bulk import send + send(recipients = recipients, subject = self.doc.subject, message = self.get_message(), + doctype = doctype, email_field = args["email_field"], + first_name_field = args["first_name_field"], last_name_field = "") + + def get_recipients(self, key): + recipients = webnotes.conn.sql(self.query_map[key]) + recipients = [r[0] for r in recipients if r not in self.all_recipients] + self.all_recipients += recipients + return recipients + + def get_message(self): + if not hasattr(self, "message"): + import markdown2 + self.message = markdown2.markdown(self.doc.message) + return self.message + + def send(self, query_key, doctype): + recipients = self.get_recipients(query_key) + webnotes.errprint(recipients) + args = self.dt_map[doctype] + self.send_count[doctype] = self.send_count.setdefault(doctype, 0) + len(recipients) + + from webnotes.utils.email_lib.bulk import send + send(recipients = recipients, subject = self.doc.subject, message = self.get_message(), + doctype = doctype, email_field = args["email_field"], + first_name_field = args["first_name_field"], last_name_field = "") \ No newline at end of file diff --git a/erpnext/support/doctype/newsletter/newsletter.txt b/erpnext/support/doctype/newsletter/newsletter.txt new file mode 100644 index 00000000000..0d47102368c --- /dev/null +++ b/erpnext/support/doctype/newsletter/newsletter.txt @@ -0,0 +1,235 @@ +# DocType, Newsletter +[ + + # These values are common in all dictionaries + { + u'creation': '2012-08-23 18:49:12', + u'docstatus': 0, + u'modified': '2012-08-24 13:39:53', + u'modified_by': u'Administrator', + u'owner': u'Administrator' + }, + + # These values are common for all DocType + { + 'description': u'Create and Send Newsletters', + u'doctype': u'DocType', + 'document_type': u'Other', + 'module': u'Support', + u'name': u'__common__', + 'version': 1 + }, + + # These values are common for all DocField + { + u'doctype': u'DocField', + u'name': u'__common__', + 'parent': u'Newsletter', + 'parentfield': u'fields', + 'parenttype': u'DocType' + }, + + # These values are common for all DocPerm + { + u'doctype': u'DocPerm', + u'name': u'__common__', + 'parent': u'Newsletter', + 'parentfield': u'permissions', + 'parenttype': u'DocType', + 'read': 1 + }, + + # DocType, Newsletter + { + u'doctype': u'DocType', + u'name': u'Newsletter' + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'basic_info', + 'fieldtype': u'Section Break', + 'label': u'Basic Info', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + 'default': u'NL-', + u'doctype': u'DocField', + 'fieldname': u'naming_series', + 'fieldtype': u'Select', + 'label': u'Naming Series', + 'options': u'NL-', + 'permlevel': 0, + 'reqd': 1 + }, + + # DocField + { + 'colour': u'White:FFF', + 'description': u'A Lead with this email id should exist', + u'doctype': u'DocField', + 'fieldname': u'test_email_id', + 'fieldtype': u'Data', + 'label': u'Test Email Id', + 'permlevel': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'test_send', + 'fieldtype': u'Button', + 'label': u'Test', + 'options': u'test_send', + 'permlevel': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'column_break1', + 'fieldtype': u'Column Break', + 'label': u'Send To', + 'permlevel': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'contacts', + 'fieldtype': u'Check', + 'label': u'All Contacts', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + 'default': u'0', + u'doctype': u'DocField', + 'fieldname': u'customer_contacts', + 'fieldtype': u'Check', + 'label': u'All Customer Contacts', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + 'default': u'0', + u'doctype': u'DocField', + 'fieldname': u'leads', + 'fieldtype': u'Check', + 'label': u'All Leads', + 'permlevel': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'active_leads', + 'fieldtype': u'Check', + 'label': u'All Active Leads', + 'permlevel': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'blog_subscribers', + 'fieldtype': u'Check', + 'label': u'All Blog Subscribers', + 'permlevel': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'newsletter_content', + 'fieldtype': u'Section Break', + 'label': u'Newsletter Content', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + u'doctype': u'DocField', + 'fieldname': u'subject', + 'fieldtype': u'Small Text', + 'label': u'Subject', + 'permlevel': 0, + 'reqd': 1 + }, + + # DocField + { + 'colour': u'White:FFF', + u'doctype': u'DocField', + 'fieldname': u'message', + 'fieldtype': u'Code', + 'label': u'Message', + 'options': u'Markdown', + 'permlevel': 0, + 'reqd': 0 + }, + + # DocField + { + u'doctype': u'DocField', + 'fieldname': u'newsletter_status', + 'fieldtype': u'Section Break', + 'label': u'Newsletter Status', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + 'default': u'0', + u'doctype': u'DocField', + 'fieldname': u'email_sent', + 'fieldtype': u'Check', + 'label': u'Email Sent?', + 'no_copy': 1, + 'permlevel': 1 + }, + + # DocPerm + { + 'cancel': 1, + 'create': 1, + u'doctype': u'DocPerm', + 'permlevel': 0, + 'role': u'Sales Manager', + 'write': 1 + }, + + # DocPerm + { + 'cancel': 1, + 'create': 1, + u'doctype': u'DocPerm', + 'permlevel': 0, + 'role': u'Support Manager', + 'write': 1 + }, + + # DocPerm + { + u'doctype': u'DocPerm', + 'permlevel': 1, + 'role': u'Sales Manager' + }, + + # DocPerm + { + u'doctype': u'DocPerm', + 'permlevel': 1, + 'role': u'Support Manager' + } +] \ No newline at end of file diff --git a/erpnext/website/doctype/blog/blog.py b/erpnext/website/doctype/blog/blog.py index 41e4f3a45a3..56f6c8683a2 100644 --- a/erpnext/website/doctype/blog/blog.py +++ b/erpnext/website/doctype/blog/blog.py @@ -15,11 +15,6 @@ # along with this program. If not, see . from __future__ import unicode_literals -""" -record of files - -naming for same name files: file.gif, file-1.gif, file-2.gif etc -""" import webnotes import website.utils