newsletter reload

This commit is contained in:
Akhilesh Darjee 2014-01-31 19:59:25 +05:30
parent bec11fa86e
commit d6d2193f91
5 changed files with 69 additions and 55 deletions

View File

@ -16,4 +16,5 @@ erpnext.patches.4_0.reload_purchase_print_format
execute:webnotes.reload_doc('accounts', 'doctype', 'pos_setting') # 2014-01-29
execute:webnotes.reload_doc('selling', 'doctype', 'customer') # 2014-01-29
execute:webnotes.reload_doc('buying', 'doctype', 'supplier') # 2014-01-29
erpnext.patches.4_0.map_charge_to_taxes_and_charges
erpnext.patches.4_0.map_charge_to_taxes_and_charges
execute:webnotes.reload_doc('support', 'doctype', 'newsletter') # 2014-01-31

View File

@ -1,8 +1,7 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
// Settings
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn){
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
return cur_frm.call({
doc: cur_frm.doc,
method: 'get_transactions',
@ -10,7 +9,7 @@ cur_frm.cscript.onload_post_render = function(doc, cdt, cdn){
cur_frm.cscript.update_selects(r);
cur_frm.cscript.select_doc_for_series(doc, cdt, cdn);
}
})
});
}
cur_frm.cscript.update_selects = function(r) {
@ -18,29 +17,27 @@ cur_frm.cscript.update_selects = function(r) {
set_field_options('prefix', r.message.prefixes);
}
cur_frm.cscript.select_doc_for_series = function(doc, cdt, cdn) {
cur_frm.toggle_display(['help_html','set_options', 'user_must_always_select', 'update'],
doc.select_doc_for_series)
doc.select_doc_for_series);
var callback = function(r, rt){
locals[cdt][cdn].set_options = r.message;
refresh_field('set_options');
if(r.message && r.message.split('\n')[0]=='') {
cur_frm.set_value('user_must_always_select', 1)
}
if(r.message && r.message.split('\n')[0]=='')
cur_frm.set_value('user_must_always_select', 1);
}
if(doc.select_doc_for_series)
return $c_obj(make_doclist(doc.doctype, doc.name),'get_options','',callback)
return $c_obj(make_doclist(doc.doctype, doc.name),'get_options','',callback);
}
cur_frm.cscript.update = function() {
return cur_frm.call_server('update_series', '', cur_frm.cscript.update_selects)
return cur_frm.call_server('update_series', '', cur_frm.cscript.update_selects);
}
cur_frm.cscript.prefix = function(doc, dt, dn) {
return cur_frm.call_server('get_current', '', function(r) {
refresh_field('current_value');
})
}
});
}

View File

@ -5,10 +5,9 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr
from webnotes import msgprint
from webnotes import msgprint, throw, _
import webnotes.model.doctype
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
@ -24,7 +23,7 @@ class DocType:
"prefixes": "\n".join([''] + [i[0] for i in
webnotes.conn.sql("""select name from tabSeries order by name""")])
}
def scrub_options_list(self, ol):
options = filter(lambda x: x, [cstr(n.upper()).strip() for n in ol])
return options
@ -33,29 +32,29 @@ class DocType:
"""update series list"""
self.check_duplicate()
series_list = self.doc.set_options.split("\n")
# set in doctype
self.set_series_for(self.doc.select_doc_for_series, series_list)
# create series
map(self.insert_series, [d.split('.')[0] for d in series_list])
msgprint('Series Updated')
msgprint(_("Series Updated"))
return self.get_transactions()
def set_series_for(self, doctype, ol):
options = self.scrub_options_list(ol)
# validate names
for i in options: self.validate_series_name(i)
if self.doc.user_must_always_select:
options = [''] + options
default = ''
else:
default = options[0]
# update in property setter
from webnotes.model.doc import Document
prop_dict = {'options': "\n".join(options), 'default': default}
@ -81,11 +80,11 @@ class DocType:
self.doc.set_options = "\n".join(options)
webnotes.clear_cache(doctype=doctype)
def check_duplicate(self):
from webnotes.core.doctype.doctype.doctype import DocType
dt = DocType()
parent = list(set(
webnotes.conn.sql_list("""select dt.name
from `tabDocField` df, `tabDocType` dt
@ -105,15 +104,20 @@ class DocType:
if i[0]:
existing_series = [d.split('.')[0] for d in i[0].split("\n")]
if series.split(".")[0] in existing_series:
msgprint("Oops! Series name %s is already in use in %s. \
Please select a new one" % (series, i[1]), raise_exception=1)
throw("{oops}! {sr} {series} {msg} {existing_series}. {select}".format(**{
"oops": _("Oops"),
"sr": _("Series Name"),
"series": series,
"msg": _("is already in use in"),
"existing_series": i[1],
"select": _("Please select a new one")
}))
def validate_series_name(self, n):
import re
if not re.match("^[a-zA-Z0-9-/.#]*$", n):
msgprint('Special Characters except "-" and "/" not allowed in naming series',
raise_exception=True)
throw('Special Characters except "-" and "/" not allowed in naming series')
def get_options(self, arg=''):
sr = webnotes.model.doctype.get_property(self.doc.select_doc_for_series,
'options', 'naming_series')
@ -121,14 +125,14 @@ class DocType:
def get_current(self, arg=None):
"""get series current"""
self.doc.current_value = webnotes.conn.get_value("Series",
self.doc.prefix.split('.')[0], "current")
if self.doc.prefix:
self.doc.current_value = webnotes.conn.get_value("Series",
self.doc.prefix.split('.')[0], "current")
def insert_series(self, series):
"""insert series if missing"""
if not webnotes.conn.exists('Series', series):
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 0)",
(series))
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 0)", (series))
def update_series_start(self):
if self.doc.prefix:
@ -136,9 +140,9 @@ class DocType:
self.insert_series(prefix)
webnotes.conn.sql("update `tabSeries` set current = %s where name = %s",
(self.doc.current_value, prefix))
msgprint("Series Updated Successfully")
msgprint(_("Series Updated Successfully"))
else:
msgprint("Please select prefix first")
msgprint(_("Please select prefix first"))
def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True):
from webnotes.core.doctype.property_setter.property_setter import make_property_setter
@ -148,7 +152,8 @@ def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True
# set values for mandatory
webnotes.conn.sql("""update `tab{doctype}` set naming_series={s} where
ifnull(naming_series, '')=''""".format(doctype=doctype, s="%s"), get_default_naming_series(doctype))
ifnull(naming_series, '')=''""".format(doctype=doctype, s="%s"),
get_default_naming_series(doctype))
if hide_name_field:
make_property_setter(doctype, fieldname, "reqd", 0, "Check")
@ -160,13 +165,13 @@ def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True
if hide_name_field:
make_property_setter(doctype, fieldname, "hidden", 0, "Check")
make_property_setter(doctype, fieldname, "reqd", 1, "Check")
# set values for mandatory
webnotes.conn.sql("""update `tab{doctype}` set `{fieldname}`=`name` where
ifnull({fieldname}, '')=''""".format(doctype=doctype, fieldname=fieldname))
def get_default_naming_series(doctype):
from webnotes.model.doctype import get_property
naming_series = get_property(doctype, "options", "naming_series")
naming_series = naming_series.split("\n")
return naming_series[0] or naming_series[1]
return naming_series[0] or naming_series[1]

View File

@ -6,7 +6,7 @@ from __future__ import unicode_literals
import webnotes
import webnotes.utils
from webnotes.utils import cstr
from webnotes import _
from webnotes import msgprint, throw, _
class DocType():
def __init__(self, d, dl):
@ -22,18 +22,24 @@ class DocType():
self.recipients = self.doc.test_email_id.split(",")
self.send_to_doctype = "Lead"
self.send_bulk()
webnotes.msgprint("""Scheduled to send to %s""" % self.doc.test_email_id)
msgprint("{send} {email}".format**{
"send": _("Scheduled to send to"),
"email": self.doc.test_email_id
})
def send_emails(self):
"""send emails to leads and customers"""
if self.doc.email_sent:
webnotes.msgprint("""Newsletter has already been sent""", raise_exception=1)
throw(_("Newsletter has already been sent"))
self.recipients = self.get_recipients()
self.send_bulk()
webnotes.msgprint("""Scheduled to send to %d %s(s)""" % (len(self.recipients),
self.send_to_doctype))
msgprint("{send} {recipients} {doctype}(s)".format(**{
"send": _("Scheduled to send to"),
"recipients": len(self.recipients),
"doctype": self.send_to_doctype
}))
webnotes.conn.set(self.doc, "email_sent", 1)
@ -62,6 +68,12 @@ class DocType():
return webnotes.conn.sql_list("""select email_id from tabLead
where ifnull(email_id, '') != '' %s""" % (conditions or ""))
elif self.doc.send_to_type=="Employee":
self.send_to_doctype = "Employee"
return webnotes.conn.sql_list("""select
if(ifnull(company_email, '')!='', company_email, personal_email) as email_id
from `tabEmployee` where status='Active'""")
elif self.doc.email_list:
email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")]
for email in email_list:
@ -90,13 +102,12 @@ class DocType():
def validate_send(self):
if self.doc.fields.get("__islocal"):
webnotes.msgprint(_("""Please save the Newsletter before sending."""),
raise_exception=1)
throw(_("Please save the Newsletter before sending."))
from webnotes import conf
if (conf.get("status") or None) == "Trial":
webnotes.msgprint(_("""Sending newsletters is not allowed for Trial users, \
to prevent abuse of this feature."""), raise_exception=1)
throw(_("Sending newsletters is not allowed for Trial users, \
to prevent abuse of this feature."))
@webnotes.whitelist()
def get_lead_options():

View File

@ -2,7 +2,7 @@
{
"creation": "2013-01-10 16:34:31",
"docstatus": 0,
"modified": "2014-01-31 17:32:47",
"modified": "2014-01-31 18:47:03",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -66,7 +66,7 @@
"fieldname": "send_to_type",
"fieldtype": "Select",
"label": "Send To Type",
"options": "Lead\nContact\nCustom"
"options": "Lead\nContact\nEmployee\nCustom"
},
{
"doctype": "DocField",
@ -93,7 +93,7 @@
"fieldname": "contact_type",
"fieldtype": "Select",
"label": "Contact Type",
"options": "Customer\nSupplier\nCustom"
"options": "Customer\nSupplier"
},
{
"depends_on": "eval:doc.send_to_type==\"Custom\"",