mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
Email Digest changes
This commit is contained in:
@@ -8,6 +8,15 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 1);
|
}, 1);
|
||||||
|
cur_frm.add_custom_button('Send Now', function() {
|
||||||
|
$c_obj(make_doclist(dt, dn), 'send', '', function(r, rt) {
|
||||||
|
if(r.exc) {
|
||||||
|
msgprint(r.exc);
|
||||||
|
} else {
|
||||||
|
console.log(arguments);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript['Add Recipients'] = function(doc, dt, dn) {
|
cur_frm.cscript['Add Recipients'] = function(doc, dt, dn) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
self.doc, self.doclist = doc, doclist
|
self.doc, self.doclist = doc, doclist
|
||||||
|
self.sending = False
|
||||||
|
|
||||||
|
|
||||||
def get_profiles(self):
|
def get_profiles(self):
|
||||||
@@ -110,7 +111,7 @@ class DocType:
|
|||||||
for query in query_dict.keys():
|
for query in query_dict.keys():
|
||||||
if self.doc.fields[query]:
|
if self.doc.fields[query]:
|
||||||
#webnotes.msgprint(query)
|
#webnotes.msgprint(query)
|
||||||
res = webnotes.conn.sql(query_dict[query], as_dict=1)
|
res = webnotes.conn.sql(query_dict[query], as_dict=1, debug=1)
|
||||||
if query == 'income':
|
if query == 'income':
|
||||||
for r in res:
|
for r in res:
|
||||||
r['value'] = float(r['credit'] - r['debit'])
|
r['value'] = float(r['credit'] - r['debit'])
|
||||||
@@ -238,8 +239,41 @@ class DocType:
|
|||||||
"""
|
"""
|
||||||
Returns start and end date depending on the frequency of email digest
|
Returns start and end date depending on the frequency of email digest
|
||||||
"""
|
"""
|
||||||
start_date = '2011-11-01'
|
from datetime import datetime, date, timedelta
|
||||||
end_date = '2011-11-31'
|
today = datetime.now().date()
|
||||||
|
year, month, day = today.year, today.month, today.day
|
||||||
|
|
||||||
|
if self.doc.frequency == 'Daily':
|
||||||
|
if self.sending:
|
||||||
|
start_date = end_date = today - timedelta(days=1)
|
||||||
|
else:
|
||||||
|
start_date = end_date = today
|
||||||
|
|
||||||
|
elif self.doc.frequency == 'Weekly':
|
||||||
|
if self.sending:
|
||||||
|
start_date = today - timedelta(weeks=1)
|
||||||
|
end_date = today - timedelta(days=1)
|
||||||
|
else:
|
||||||
|
start_date = today - timedelta(days=today.weekday())
|
||||||
|
end_date = start_date + timedelta(weeks=1)
|
||||||
|
|
||||||
|
else:
|
||||||
|
import calendar
|
||||||
|
|
||||||
|
if self.sending:
|
||||||
|
if month == 1:
|
||||||
|
year = year - 1
|
||||||
|
prev_month = 12
|
||||||
|
else:
|
||||||
|
prev_month = month - 1
|
||||||
|
start_date = date(year, prev_month, 1)
|
||||||
|
last_day = calendar.monthrange(year, prev_month)[1]
|
||||||
|
end_date = date(year, prev_month, last_day)
|
||||||
|
else:
|
||||||
|
start_date = date(year, month, 1)
|
||||||
|
last_day = calendar.monthrange(year, month)[1]
|
||||||
|
end_date = date(year, month, last_day)
|
||||||
|
|
||||||
return start_date, end_date
|
return start_date, end_date
|
||||||
|
|
||||||
|
|
||||||
@@ -281,9 +315,10 @@ class DocType:
|
|||||||
* Execute Query
|
* Execute Query
|
||||||
* Prepare Email Body from Print Format
|
* Prepare Email Body from Print Format
|
||||||
"""
|
"""
|
||||||
result = self.execute_queries()
|
result, email_body = self.execute_queries()
|
||||||
webnotes.msgprint(result)
|
webnotes.msgprint(result)
|
||||||
return result
|
webnotes.msgprint(email_body)
|
||||||
|
return result, email_body
|
||||||
|
|
||||||
|
|
||||||
def execute_queries(self):
|
def execute_queries(self):
|
||||||
@@ -294,15 +329,27 @@ class DocType:
|
|||||||
result = {}
|
result = {}
|
||||||
if self.doc.use_standard==1:
|
if self.doc.use_standard==1:
|
||||||
result = self.get_standard_data()
|
result = self.get_standard_data()
|
||||||
|
email_body = self.get_standard_body(result)
|
||||||
else:
|
else:
|
||||||
result = self.execute_custom_code()
|
result, email_body = self.execute_custom_code(self.doc)
|
||||||
|
|
||||||
#webnotes.msgprint(result)
|
#webnotes.msgprint(result)
|
||||||
|
|
||||||
return result
|
return result, email_body
|
||||||
|
|
||||||
|
|
||||||
def execute_custom_code(self):
|
def get_standard_body(self, result):
|
||||||
|
"""
|
||||||
|
Generate email body depending on the result
|
||||||
|
"""
|
||||||
|
return """
|
||||||
|
<div>
|
||||||
|
Invoiced Amount: %(invoiced_amount)s<br />
|
||||||
|
Payables: %(payables)s<br />
|
||||||
|
</div>""" % result
|
||||||
|
|
||||||
|
|
||||||
|
def execute_custom_code(self, doc):
|
||||||
"""
|
"""
|
||||||
Execute custom python code
|
Execute custom python code
|
||||||
"""
|
"""
|
||||||
@@ -314,4 +361,33 @@ class DocType:
|
|||||||
* Execute get method
|
* Execute get method
|
||||||
* Send email to recipients
|
* Send email to recipients
|
||||||
"""
|
"""
|
||||||
pass
|
self.sending = True
|
||||||
|
result, email_body = self.get()
|
||||||
|
# TODO: before sending, check if user is disabled or not
|
||||||
|
from webnotes.utils.email_lib import sendmail
|
||||||
|
try:
|
||||||
|
sendmail(
|
||||||
|
recipients=self.doc.recipient_list.split("\n"),
|
||||||
|
sender='anand@erpnext.com',
|
||||||
|
reply_to='support@erpnext.com',
|
||||||
|
subject='Digest',
|
||||||
|
msg=email_body,
|
||||||
|
from_defs=1
|
||||||
|
)
|
||||||
|
except Exception, e:
|
||||||
|
webnotes.msgprint('There was a problem in sending your email. Please contact support@erpnext.com')
|
||||||
|
#webnotes.errprint(webnotes.getTraceback())
|
||||||
|
|
||||||
|
|
||||||
|
def schedule(self):
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Get TimeZone
|
||||||
|
# Get System TimeZone
|
||||||
|
import time
|
||||||
|
from pytz import timezone
|
||||||
|
server_tz = timezone(time.tzname[0])
|
||||||
|
cp = webnotes.model.doc.Document('Control Panel','Control Panel')
|
||||||
|
app_tz = timezone(cp.time_zone)
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
{
|
{
|
||||||
'creation': '2011-11-28 13:11:56',
|
'creation': '2011-11-28 13:11:56',
|
||||||
'docstatus': 0,
|
'docstatus': 0,
|
||||||
'modified': '2011-12-05 11:55:31',
|
'modified': '2011-12-05 18:54:27',
|
||||||
'modified_by': 'Administrator',
|
'modified_by': 'Administrator',
|
||||||
'owner': 'Administrator'
|
'owner': 'Administrator'
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocType
|
# These values are common for all DocType
|
||||||
{
|
{
|
||||||
'_last_update': '1323066269',
|
'_last_update': '1323083188',
|
||||||
'autoname': 'Prompt',
|
'autoname': 'Prompt',
|
||||||
'colour': 'White:FFF',
|
'colour': 'White:FFF',
|
||||||
'doctype': 'DocType',
|
'doctype': 'DocType',
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
'name': '__common__',
|
'name': '__common__',
|
||||||
'section_style': 'Simple',
|
'section_style': 'Simple',
|
||||||
'show_in_menu': 0,
|
'show_in_menu': 0,
|
||||||
'version': 51
|
'version': 61
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocField
|
# These values are common for all DocField
|
||||||
@@ -114,12 +114,10 @@
|
|||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'send_time',
|
'fieldname': 'next_send_datetime',
|
||||||
'fieldtype': 'Select',
|
'fieldtype': 'Text',
|
||||||
'label': 'At what time?',
|
'label': 'Next email will be sent on:',
|
||||||
'options': '\n1 AM\n2 AM\n3 AM\n4 AM\n5 AM\n6 AM\n7 AM\n8 AM\n9 AM\n10 AM\n11 AM\nNoon\n1 PM\n2 PM\n3 PM\n4 PM\n5 PM\n6 PM\n7 PM\n8 PM\n9 PM\n10 PM\n11 PM\nMidnight',
|
'permlevel': 1
|
||||||
'permlevel': 0,
|
|
||||||
'reqd': 1
|
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@@ -128,6 +126,7 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'use_standard',
|
'fieldname': 'use_standard',
|
||||||
'fieldtype': 'Check',
|
'fieldtype': 'Check',
|
||||||
|
'hidden': 1,
|
||||||
'label': 'Use standard?',
|
'label': 'Use standard?',
|
||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
@@ -309,21 +308,13 @@
|
|||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
|
'depends_on': 'eval:!doc.use_standard',
|
||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldtype': 'Section Break',
|
'fieldtype': 'Section Break',
|
||||||
'label': 'Enter Custom Code',
|
'label': 'Enter Custom Code',
|
||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
|
||||||
{
|
|
||||||
'doctype': 'DocField',
|
|
||||||
'fieldname': 'email_template',
|
|
||||||
'fieldtype': 'Code',
|
|
||||||
'label': 'Email Template',
|
|
||||||
'permlevel': 0
|
|
||||||
},
|
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'default': '\n',
|
'default': '\n',
|
||||||
@@ -333,5 +324,15 @@
|
|||||||
'fieldtype': 'Code',
|
'fieldtype': 'Code',
|
||||||
'label': 'Custom Python Code',
|
'label': 'Custom Python Code',
|
||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
|
},
|
||||||
|
|
||||||
|
# DocField
|
||||||
|
{
|
||||||
|
'depends_on': 'eval:!doc.use_standard',
|
||||||
|
'doctype': 'DocField',
|
||||||
|
'fieldname': 'email_template',
|
||||||
|
'fieldtype': 'Code',
|
||||||
|
'label': 'Email Template',
|
||||||
|
'permlevel': 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user