newsletter reload
This commit is contained in:
parent
bec11fa86e
commit
d6d2193f91
@ -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('accounts', 'doctype', 'pos_setting') # 2014-01-29
|
||||||
execute:webnotes.reload_doc('selling', 'doctype', 'customer') # 2014-01-29
|
execute:webnotes.reload_doc('selling', 'doctype', 'customer') # 2014-01-29
|
||||||
execute:webnotes.reload_doc('buying', 'doctype', 'supplier') # 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
|
||||||
@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||||
// License: GNU General Public License v3. See license.txt
|
// 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({
|
return cur_frm.call({
|
||||||
doc: cur_frm.doc,
|
doc: cur_frm.doc,
|
||||||
method: 'get_transactions',
|
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.update_selects(r);
|
||||||
cur_frm.cscript.select_doc_for_series(doc, cdt, cdn);
|
cur_frm.cscript.select_doc_for_series(doc, cdt, cdn);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript.update_selects = function(r) {
|
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);
|
set_field_options('prefix', r.message.prefixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cur_frm.cscript.select_doc_for_series = function(doc, cdt, cdn) {
|
cur_frm.cscript.select_doc_for_series = function(doc, cdt, cdn) {
|
||||||
cur_frm.toggle_display(['help_html','set_options', 'user_must_always_select', 'update'],
|
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){
|
var callback = function(r, rt){
|
||||||
locals[cdt][cdn].set_options = r.message;
|
locals[cdt][cdn].set_options = r.message;
|
||||||
refresh_field('set_options');
|
refresh_field('set_options');
|
||||||
if(r.message && r.message.split('\n')[0]=='') {
|
if(r.message && r.message.split('\n')[0]=='')
|
||||||
cur_frm.set_value('user_must_always_select', 1)
|
cur_frm.set_value('user_must_always_select', 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(doc.select_doc_for_series)
|
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() {
|
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) {
|
cur_frm.cscript.prefix = function(doc, dt, dn) {
|
||||||
return cur_frm.call_server('get_current', '', function(r) {
|
return cur_frm.call_server('get_current', '', function(r) {
|
||||||
refresh_field('current_value');
|
refresh_field('current_value');
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
@ -5,10 +5,9 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
from webnotes.utils import cstr
|
from webnotes.utils import cstr
|
||||||
from webnotes import msgprint
|
from webnotes import msgprint, throw, _
|
||||||
import webnotes.model.doctype
|
import webnotes.model.doctype
|
||||||
|
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
@ -24,7 +23,7 @@ class DocType:
|
|||||||
"prefixes": "\n".join([''] + [i[0] for i in
|
"prefixes": "\n".join([''] + [i[0] for i in
|
||||||
webnotes.conn.sql("""select name from tabSeries order by name""")])
|
webnotes.conn.sql("""select name from tabSeries order by name""")])
|
||||||
}
|
}
|
||||||
|
|
||||||
def scrub_options_list(self, ol):
|
def scrub_options_list(self, ol):
|
||||||
options = filter(lambda x: x, [cstr(n.upper()).strip() for n in ol])
|
options = filter(lambda x: x, [cstr(n.upper()).strip() for n in ol])
|
||||||
return options
|
return options
|
||||||
@ -33,29 +32,29 @@ class DocType:
|
|||||||
"""update series list"""
|
"""update series list"""
|
||||||
self.check_duplicate()
|
self.check_duplicate()
|
||||||
series_list = self.doc.set_options.split("\n")
|
series_list = self.doc.set_options.split("\n")
|
||||||
|
|
||||||
# set in doctype
|
# set in doctype
|
||||||
self.set_series_for(self.doc.select_doc_for_series, series_list)
|
self.set_series_for(self.doc.select_doc_for_series, series_list)
|
||||||
|
|
||||||
# create series
|
# create series
|
||||||
map(self.insert_series, [d.split('.')[0] for d in series_list])
|
map(self.insert_series, [d.split('.')[0] for d in series_list])
|
||||||
|
|
||||||
msgprint('Series Updated')
|
msgprint(_("Series Updated"))
|
||||||
|
|
||||||
return self.get_transactions()
|
return self.get_transactions()
|
||||||
|
|
||||||
def set_series_for(self, doctype, ol):
|
def set_series_for(self, doctype, ol):
|
||||||
options = self.scrub_options_list(ol)
|
options = self.scrub_options_list(ol)
|
||||||
|
|
||||||
# validate names
|
# validate names
|
||||||
for i in options: self.validate_series_name(i)
|
for i in options: self.validate_series_name(i)
|
||||||
|
|
||||||
if self.doc.user_must_always_select:
|
if self.doc.user_must_always_select:
|
||||||
options = [''] + options
|
options = [''] + options
|
||||||
default = ''
|
default = ''
|
||||||
else:
|
else:
|
||||||
default = options[0]
|
default = options[0]
|
||||||
|
|
||||||
# update in property setter
|
# update in property setter
|
||||||
from webnotes.model.doc import Document
|
from webnotes.model.doc import Document
|
||||||
prop_dict = {'options': "\n".join(options), 'default': default}
|
prop_dict = {'options': "\n".join(options), 'default': default}
|
||||||
@ -81,11 +80,11 @@ class DocType:
|
|||||||
self.doc.set_options = "\n".join(options)
|
self.doc.set_options = "\n".join(options)
|
||||||
|
|
||||||
webnotes.clear_cache(doctype=doctype)
|
webnotes.clear_cache(doctype=doctype)
|
||||||
|
|
||||||
def check_duplicate(self):
|
def check_duplicate(self):
|
||||||
from webnotes.core.doctype.doctype.doctype import DocType
|
from webnotes.core.doctype.doctype.doctype import DocType
|
||||||
dt = DocType()
|
dt = DocType()
|
||||||
|
|
||||||
parent = list(set(
|
parent = list(set(
|
||||||
webnotes.conn.sql_list("""select dt.name
|
webnotes.conn.sql_list("""select dt.name
|
||||||
from `tabDocField` df, `tabDocType` dt
|
from `tabDocField` df, `tabDocType` dt
|
||||||
@ -105,15 +104,20 @@ class DocType:
|
|||||||
if i[0]:
|
if i[0]:
|
||||||
existing_series = [d.split('.')[0] for d in i[0].split("\n")]
|
existing_series = [d.split('.')[0] for d in i[0].split("\n")]
|
||||||
if series.split(".")[0] in existing_series:
|
if series.split(".")[0] in existing_series:
|
||||||
msgprint("Oops! Series name %s is already in use in %s. \
|
throw("{oops}! {sr} {series} {msg} {existing_series}. {select}".format(**{
|
||||||
Please select a new one" % (series, i[1]), raise_exception=1)
|
"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):
|
def validate_series_name(self, n):
|
||||||
import re
|
import re
|
||||||
if not re.match("^[a-zA-Z0-9-/.#]*$", n):
|
if not re.match("^[a-zA-Z0-9-/.#]*$", n):
|
||||||
msgprint('Special Characters except "-" and "/" not allowed in naming series',
|
throw('Special Characters except "-" and "/" not allowed in naming series')
|
||||||
raise_exception=True)
|
|
||||||
|
|
||||||
def get_options(self, arg=''):
|
def get_options(self, arg=''):
|
||||||
sr = webnotes.model.doctype.get_property(self.doc.select_doc_for_series,
|
sr = webnotes.model.doctype.get_property(self.doc.select_doc_for_series,
|
||||||
'options', 'naming_series')
|
'options', 'naming_series')
|
||||||
@ -121,14 +125,14 @@ class DocType:
|
|||||||
|
|
||||||
def get_current(self, arg=None):
|
def get_current(self, arg=None):
|
||||||
"""get series current"""
|
"""get series current"""
|
||||||
self.doc.current_value = webnotes.conn.get_value("Series",
|
if self.doc.prefix:
|
||||||
self.doc.prefix.split('.')[0], "current")
|
self.doc.current_value = webnotes.conn.get_value("Series",
|
||||||
|
self.doc.prefix.split('.')[0], "current")
|
||||||
|
|
||||||
def insert_series(self, series):
|
def insert_series(self, series):
|
||||||
"""insert series if missing"""
|
"""insert series if missing"""
|
||||||
if not webnotes.conn.exists('Series', series):
|
if not webnotes.conn.exists('Series', series):
|
||||||
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 0)",
|
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 0)", (series))
|
||||||
(series))
|
|
||||||
|
|
||||||
def update_series_start(self):
|
def update_series_start(self):
|
||||||
if self.doc.prefix:
|
if self.doc.prefix:
|
||||||
@ -136,9 +140,9 @@ class DocType:
|
|||||||
self.insert_series(prefix)
|
self.insert_series(prefix)
|
||||||
webnotes.conn.sql("update `tabSeries` set current = %s where name = %s",
|
webnotes.conn.sql("update `tabSeries` set current = %s where name = %s",
|
||||||
(self.doc.current_value, prefix))
|
(self.doc.current_value, prefix))
|
||||||
msgprint("Series Updated Successfully")
|
msgprint(_("Series Updated Successfully"))
|
||||||
else:
|
else:
|
||||||
msgprint("Please select prefix first")
|
msgprint(_("Please select prefix first"))
|
||||||
|
|
||||||
def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True):
|
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
|
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
|
# set values for mandatory
|
||||||
webnotes.conn.sql("""update `tab{doctype}` set naming_series={s} where
|
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:
|
if hide_name_field:
|
||||||
make_property_setter(doctype, fieldname, "reqd", 0, "Check")
|
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:
|
if hide_name_field:
|
||||||
make_property_setter(doctype, fieldname, "hidden", 0, "Check")
|
make_property_setter(doctype, fieldname, "hidden", 0, "Check")
|
||||||
make_property_setter(doctype, fieldname, "reqd", 1, "Check")
|
make_property_setter(doctype, fieldname, "reqd", 1, "Check")
|
||||||
|
|
||||||
# set values for mandatory
|
# set values for mandatory
|
||||||
webnotes.conn.sql("""update `tab{doctype}` set `{fieldname}`=`name` where
|
webnotes.conn.sql("""update `tab{doctype}` set `{fieldname}`=`name` where
|
||||||
ifnull({fieldname}, '')=''""".format(doctype=doctype, fieldname=fieldname))
|
ifnull({fieldname}, '')=''""".format(doctype=doctype, fieldname=fieldname))
|
||||||
|
|
||||||
def get_default_naming_series(doctype):
|
def get_default_naming_series(doctype):
|
||||||
from webnotes.model.doctype import get_property
|
from webnotes.model.doctype import get_property
|
||||||
naming_series = get_property(doctype, "options", "naming_series")
|
naming_series = get_property(doctype, "options", "naming_series")
|
||||||
naming_series = naming_series.split("\n")
|
naming_series = naming_series.split("\n")
|
||||||
return naming_series[0] or naming_series[1]
|
return naming_series[0] or naming_series[1]
|
||||||
@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
import webnotes.utils
|
import webnotes.utils
|
||||||
from webnotes.utils import cstr
|
from webnotes.utils import cstr
|
||||||
from webnotes import _
|
from webnotes import msgprint, throw, _
|
||||||
|
|
||||||
class DocType():
|
class DocType():
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
@ -22,18 +22,24 @@ class DocType():
|
|||||||
self.recipients = self.doc.test_email_id.split(",")
|
self.recipients = self.doc.test_email_id.split(",")
|
||||||
self.send_to_doctype = "Lead"
|
self.send_to_doctype = "Lead"
|
||||||
self.send_bulk()
|
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):
|
def send_emails(self):
|
||||||
"""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)
|
throw(_("Newsletter has already been sent"))
|
||||||
|
|
||||||
self.recipients = self.get_recipients()
|
self.recipients = self.get_recipients()
|
||||||
self.send_bulk()
|
self.send_bulk()
|
||||||
|
|
||||||
webnotes.msgprint("""Scheduled to send to %d %s(s)""" % (len(self.recipients),
|
msgprint("{send} {recipients} {doctype}(s)".format(**{
|
||||||
self.send_to_doctype))
|
"send": _("Scheduled to send to"),
|
||||||
|
"recipients": len(self.recipients),
|
||||||
|
"doctype": self.send_to_doctype
|
||||||
|
}))
|
||||||
|
|
||||||
webnotes.conn.set(self.doc, "email_sent", 1)
|
webnotes.conn.set(self.doc, "email_sent", 1)
|
||||||
|
|
||||||
@ -62,6 +68,12 @@ class DocType():
|
|||||||
return webnotes.conn.sql_list("""select email_id from tabLead
|
return webnotes.conn.sql_list("""select email_id from tabLead
|
||||||
where ifnull(email_id, '') != '' %s""" % (conditions or ""))
|
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:
|
elif self.doc.email_list:
|
||||||
email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")]
|
email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")]
|
||||||
for email in email_list:
|
for email in email_list:
|
||||||
@ -90,13 +102,12 @@ class DocType():
|
|||||||
|
|
||||||
def validate_send(self):
|
def validate_send(self):
|
||||||
if self.doc.fields.get("__islocal"):
|
if self.doc.fields.get("__islocal"):
|
||||||
webnotes.msgprint(_("""Please save the Newsletter before sending."""),
|
throw(_("Please save the Newsletter before sending."))
|
||||||
raise_exception=1)
|
|
||||||
|
|
||||||
from webnotes import conf
|
from webnotes import conf
|
||||||
if (conf.get("status") or None) == "Trial":
|
if (conf.get("status") or None) == "Trial":
|
||||||
webnotes.msgprint(_("""Sending newsletters is not allowed for Trial users, \
|
throw(_("Sending newsletters is not allowed for Trial users, \
|
||||||
to prevent abuse of this feature."""), raise_exception=1)
|
to prevent abuse of this feature."))
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_lead_options():
|
def get_lead_options():
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
"creation": "2013-01-10 16:34:31",
|
"creation": "2013-01-10 16:34:31",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2014-01-31 17:32:47",
|
"modified": "2014-01-31 18:47:03",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -66,7 +66,7 @@
|
|||||||
"fieldname": "send_to_type",
|
"fieldname": "send_to_type",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Send To Type",
|
"label": "Send To Type",
|
||||||
"options": "Lead\nContact\nCustom"
|
"options": "Lead\nContact\nEmployee\nCustom"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -93,7 +93,7 @@
|
|||||||
"fieldname": "contact_type",
|
"fieldname": "contact_type",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Contact Type",
|
"label": "Contact Type",
|
||||||
"options": "Customer\nSupplier\nCustom"
|
"options": "Customer\nSupplier"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.send_to_type==\"Custom\"",
|
"depends_on": "eval:doc.send_to_type==\"Custom\"",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user