added Send From field in newsletter
This commit is contained in:
parent
488d0ab6cd
commit
325caf33f7
@ -23,4 +23,9 @@ cur_frm.cscript.refresh = function(doc) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(doc.__islocal && !doc.send_from) {
|
||||||
|
cur_frm.set_value("send_from",
|
||||||
|
repl("%(fullname)s <%(email)s>", wn.user_info(doc.owner)));
|
||||||
|
}
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ import webnotes
|
|||||||
import webnotes.utils
|
import webnotes.utils
|
||||||
from webnotes.utils import cstr
|
from webnotes.utils import cstr
|
||||||
from webnotes.model.doc import Document
|
from webnotes.model.doc import Document
|
||||||
|
from webnotes import _
|
||||||
|
|
||||||
class DocType():
|
class DocType():
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
@ -51,7 +52,7 @@ class DocType():
|
|||||||
"""send emails to leads and customers"""
|
"""send emails to leads and customers"""
|
||||||
if self.doc.email_sent:
|
if self.doc.email_sent:
|
||||||
webnotes.msgprint("""Newsletter has already been sent""", raise_exception=1)
|
webnotes.msgprint("""Newsletter has already been sent""", raise_exception=1)
|
||||||
|
|
||||||
self.all_recipients = []
|
self.all_recipients = []
|
||||||
self.send_count = {}
|
self.send_count = {}
|
||||||
|
|
||||||
@ -82,8 +83,11 @@ class DocType():
|
|||||||
", ".join(["%d %s(s)" % (self.send_count[s], s) for s in self.send_count]))
|
", ".join(["%d %s(s)" % (self.send_count[s], s) for s in self.send_count]))
|
||||||
|
|
||||||
def test_send(self, doctype="Lead"):
|
def test_send(self, doctype="Lead"):
|
||||||
|
self.validate_send()
|
||||||
|
|
||||||
args = self.dt_map[doctype]
|
args = self.dt_map[doctype]
|
||||||
sender = webnotes.utils.get_email_id(self.doc.owner)
|
|
||||||
|
sender = self.doc.send_from or webnotes.utils.get_email_id(self.doc.owner)
|
||||||
recipients = self.doc.test_email_id.split(",")
|
recipients = self.doc.test_email_id.split(",")
|
||||||
from webnotes.utils.email_lib.bulk import send
|
from webnotes.utils.email_lib.bulk import send
|
||||||
send(recipients = recipients, sender = sender,
|
send(recipients = recipients, sender = sender,
|
||||||
@ -98,12 +102,14 @@ class DocType():
|
|||||||
return recipients
|
return recipients
|
||||||
|
|
||||||
def send(self, query_key, doctype):
|
def send(self, query_key, doctype):
|
||||||
|
self.validate_send()
|
||||||
|
|
||||||
webnotes.conn.auto_commit_on_many_writes = True
|
webnotes.conn.auto_commit_on_many_writes = True
|
||||||
if isinstance(query_key, basestring) and self.query_map.has_key(query_key):
|
if isinstance(query_key, basestring) and self.query_map.has_key(query_key):
|
||||||
recipients = self.get_recipients(query_key)
|
recipients = self.get_recipients(query_key)
|
||||||
else:
|
else:
|
||||||
recipients = query_key
|
recipients = query_key
|
||||||
sender = webnotes.utils.get_email_id(self.doc.owner)
|
sender = self.doc.send_from or webnotes.utils.get_email_id(self.doc.owner)
|
||||||
args = self.dt_map[doctype]
|
args = self.dt_map[doctype]
|
||||||
self.send_count[doctype] = self.send_count.setdefault(doctype, 0) + \
|
self.send_count[doctype] = self.send_count.setdefault(doctype, 0) + \
|
||||||
len(recipients)
|
len(recipients)
|
||||||
@ -112,7 +118,17 @@ class DocType():
|
|||||||
send(recipients = recipients, sender = sender,
|
send(recipients = recipients, sender = sender,
|
||||||
subject = self.doc.subject, message = self.doc.message,
|
subject = self.doc.subject, message = self.doc.message,
|
||||||
doctype = doctype, email_field = args["email_field"])
|
doctype = doctype, email_field = args["email_field"])
|
||||||
|
|
||||||
|
def validate_send(self):
|
||||||
|
if self.doc.fields.get("__islocal"):
|
||||||
|
webnotes.msgprint(_("""Please save the Newsletter before sending."""),
|
||||||
|
raise_exception=1)
|
||||||
|
|
||||||
|
import conf
|
||||||
|
if getattr(conf, "status", None) == "Trial":
|
||||||
|
webnotes.msgprint(_("""Sending newsletters is not allowed for Trial users, \
|
||||||
|
to prevent abuse of this feature."""), raise_exception=1)
|
||||||
|
|
||||||
lead_naming_series = None
|
lead_naming_series = None
|
||||||
def create_lead(email_id):
|
def create_lead(email_id):
|
||||||
"""create a lead if it does not exist"""
|
"""create a lead if it does not exist"""
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
{
|
{
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"creation": "2012-12-07 15:15:31",
|
"creation": "2013-01-01 13:46:34",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"modified": "2013-01-01 10:54:40"
|
"modified": "2013-01-02 13:03:29"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"autoname": "naming_series:",
|
"autoname": "naming_series:",
|
||||||
@ -107,6 +107,15 @@
|
|||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description": "If specified, send the newsletter using this email address",
|
||||||
|
"no_copy": 1,
|
||||||
|
"doctype": "DocField",
|
||||||
|
"label": "Send From",
|
||||||
|
"fieldname": "send_from",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"permlevel": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"label": "Subject",
|
"label": "Subject",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user