[enhancement] added priority in bulk emailversion-14
@@ -310,7 +310,8 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message | |||||
as_markdown=False, bulk=False, reference_doctype=None, reference_name=None, | as_markdown=False, bulk=False, reference_doctype=None, reference_name=None, | ||||
unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, | unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, | ||||
attachments=None, content=None, doctype=None, name=None, reply_to=None, | attachments=None, content=None, doctype=None, name=None, reply_to=None, | ||||
cc=(), message_id=None, as_bulk=False, send_after=None, expose_recipients=False): | |||||
cc=(), message_id=None, as_bulk=False, send_after=None, expose_recipients=False, | |||||
bulk_priority=1): | |||||
"""Send email using user's default **Email Account** or global default **Email Account**. | """Send email using user's default **Email Account** or global default **Email Account**. | ||||
@@ -320,6 +321,7 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message | |||||
:param message: (or `content`) Email Content. | :param message: (or `content`) Email Content. | ||||
:param as_markdown: Convert content markdown to HTML. | :param as_markdown: Convert content markdown to HTML. | ||||
:param bulk: Send via scheduled email sender **Bulk Email**. Don't send immediately. | :param bulk: Send via scheduled email sender **Bulk Email**. Don't send immediately. | ||||
:param bulk_priority: Priority for bulk email, default 1. | |||||
:param reference_doctype: (or `doctype`) Append as communication to this DocType. | :param reference_doctype: (or `doctype`) Append as communication to this DocType. | ||||
:param reference_name: (or `name`) Append as communication to this document name. | :param reference_name: (or `name`) Append as communication to this document name. | ||||
:param unsubscribe_method: Unsubscribe url with options email, doctype, name. e.g. `/api/method/unsubscribe` | :param unsubscribe_method: Unsubscribe url with options email, doctype, name. e.g. `/api/method/unsubscribe` | ||||
@@ -338,7 +340,7 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message | |||||
reference_doctype = doctype or reference_doctype, reference_name = name or reference_name, | reference_doctype = doctype or reference_doctype, reference_name = name or reference_name, | ||||
unsubscribe_method=unsubscribe_method, unsubscribe_params=unsubscribe_params, unsubscribe_message=unsubscribe_message, | unsubscribe_method=unsubscribe_method, unsubscribe_params=unsubscribe_params, unsubscribe_message=unsubscribe_message, | ||||
attachments=attachments, reply_to=reply_to, cc=cc, message_id=message_id, send_after=send_after, | attachments=attachments, reply_to=reply_to, cc=cc, message_id=message_id, send_after=send_after, | ||||
expose_recipients=expose_recipients) | |||||
expose_recipients=expose_recipients, bulk_priority=bulk_priority) | |||||
else: | else: | ||||
import frappe.email | import frappe.email | ||||
if as_markdown: | if as_markdown: | ||||
@@ -17,7 +17,7 @@ class BulkLimitCrossedError(frappe.ValidationError): pass | |||||
def send(recipients=None, sender=None, subject=None, message=None, reference_doctype=None, | def send(recipients=None, sender=None, subject=None, message=None, reference_doctype=None, | ||||
reference_name=None, unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, | reference_name=None, unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, | ||||
attachments=None, reply_to=None, cc=(), message_id=None, send_after=None, | attachments=None, reply_to=None, cc=(), message_id=None, send_after=None, | ||||
expose_recipients=False): | |||||
expose_recipients=False, bulk_priority=1): | |||||
"""Add email to sending queue (Bulk Email) | """Add email to sending queue (Bulk Email) | ||||
:param recipients: List of recipients. | :param recipients: List of recipients. | ||||
@@ -26,6 +26,7 @@ def send(recipients=None, sender=None, subject=None, message=None, reference_doc | |||||
:param message: Email message. | :param message: Email message. | ||||
:param reference_doctype: Reference DocType of caller document. | :param reference_doctype: Reference DocType of caller document. | ||||
:param reference_name: Reference name of caller document. | :param reference_name: Reference name of caller document. | ||||
:param bulk_priority: Priority for bulk email, default 1. | |||||
:param unsubscribe_method: URL method for unsubscribe. Default is `/api/method/frappe.email.bulk.unsubscribe`. | :param unsubscribe_method: URL method for unsubscribe. Default is `/api/method/frappe.email.bulk.unsubscribe`. | ||||
:param unsubscribe_params: additional params for unsubscribed links. default are name, doctype, email | :param unsubscribe_params: additional params for unsubscribed links. default are name, doctype, email | ||||
:param attachments: Attachments to be sent. | :param attachments: Attachments to be sent. | ||||
@@ -90,15 +91,16 @@ def send(recipients=None, sender=None, subject=None, message=None, reference_doc | |||||
# add to queue | # add to queue | ||||
add(email, sender, subject, email_content, email_text_context, reference_doctype, | add(email, sender, subject, email_content, email_text_context, reference_doctype, | ||||
reference_name, attachments, reply_to, cc, message_id, send_after) | |||||
reference_name, attachments, reply_to, cc, message_id, send_after, bulk_priority) | |||||
def add(email, sender, subject, formatted, text_content=None, | def add(email, sender, subject, formatted, text_content=None, | ||||
reference_doctype=None, reference_name=None, attachments=None, reply_to=None, | reference_doctype=None, reference_name=None, attachments=None, reply_to=None, | ||||
cc=(), message_id=None, send_after=None): | |||||
cc=(), message_id=None, send_after=None, bulk_priority=1): | |||||
"""add to bulk mail queue""" | """add to bulk mail queue""" | ||||
e = frappe.new_doc('Bulk Email') | e = frappe.new_doc('Bulk Email') | ||||
e.sender = sender | e.sender = sender | ||||
e.recipient = email | e.recipient = email | ||||
e.priority = bulk_priority | |||||
try: | try: | ||||
mail = get_email(email, sender=e.sender, formatted=formatted, subject=subject, | mail = get_email(email, sender=e.sender, formatted=formatted, subject=subject, | ||||
@@ -231,7 +233,7 @@ def flush(from_test=False): | |||||
for i in xrange(500): | for i in xrange(500): | ||||
email = frappe.db.sql("""select * from `tabBulk Email` where | email = frappe.db.sql("""select * from `tabBulk Email` where | ||||
status='Not Sent' and ifnull(send_after, "2000-01-01 00:00:00") < %s | status='Not Sent' and ifnull(send_after, "2000-01-01 00:00:00") < %s | ||||
order by creation asc limit 1 for update""", now_datetime(), as_dict=1) | |||||
order by priority desc, creation asc limit 1 for update""", now_datetime(), as_dict=1) | |||||
if email: | if email: | ||||
email = email[0] | email = email[0] | ||||
else: | else: | ||||
@@ -181,6 +181,29 @@ | |||||
"search_index": 0, | "search_index": 0, | ||||
"set_only_once": 0, | "set_only_once": 0, | ||||
"unique": 0 | "unique": 0 | ||||
}, | |||||
{ | |||||
"allow_on_submit": 0, | |||||
"bold": 0, | |||||
"collapsible": 0, | |||||
"default": "1", | |||||
"fieldname": "priority", | |||||
"fieldtype": "Int", | |||||
"hidden": 0, | |||||
"ignore_user_permissions": 0, | |||||
"in_filter": 0, | |||||
"in_list_view": 0, | |||||
"label": "Priority", | |||||
"no_copy": 0, | |||||
"permlevel": 0, | |||||
"precision": "", | |||||
"print_hide": 0, | |||||
"read_only": 1, | |||||
"report_hide": 0, | |||||
"reqd": 0, | |||||
"search_index": 0, | |||||
"set_only_once": 0, | |||||
"unique": 0 | |||||
} | } | ||||
], | ], | ||||
"hide_heading": 0, | "hide_heading": 0, | ||||
@@ -192,7 +215,7 @@ | |||||
"is_submittable": 0, | "is_submittable": 0, | ||||
"issingle": 0, | "issingle": 0, | ||||
"istable": 0, | "istable": 0, | ||||
"modified": "2015-05-21 07:26:13.627637", | |||||
"modified": "2015-09-29 05:16:31.857121", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Email", | "module": "Email", | ||||
"name": "Bulk Email", | "name": "Bulk Email", | ||||
@@ -203,6 +203,9 @@ def formatdate(string_date=None, format_string=None): | |||||
return babel.dates.format_date(date, format_string, locale=(frappe.local.lang or "").replace("-", "_")) | return babel.dates.format_date(date, format_string, locale=(frappe.local.lang or "").replace("-", "_")) | ||||
def format_time(txt): | |||||
return babel.dates.format_time(get_time(txt), locale=(frappe.local.lang or "").replace("-", "_")) | |||||
def format_datetime(datetime_string, format_string=None): | def format_datetime(datetime_string, format_string=None): | ||||
if not datetime_string: | if not datetime_string: | ||||
return | return | ||||