[Enhance] Custom notification messages for subscription documents (#10970)
* [minor] configurable subscription email message and subject for notification * [minor] added description for subject field
This commit is contained in:
parent
bdb4c542e7
commit
9c339145b2
@ -439,7 +439,7 @@
|
|||||||
"allow_bulk_edit": 0,
|
"allow_bulk_edit": 0,
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 1,
|
||||||
"columns": 0,
|
"columns": 0,
|
||||||
"fieldname": "notification",
|
"fieldname": "notification",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
@ -495,6 +495,38 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_bulk_edit": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"depends_on": "eval: doc.notify_by_email",
|
||||||
|
"description": "To add dynamic subject, use jinja tags like\n\n<div><pre><code>New {{ doc.doctype }} #{{ doc.name }}</code></pre></div>",
|
||||||
|
"fieldname": "subject",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_global_search": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Subject",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_bulk_edit": 0,
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -593,6 +625,69 @@
|
|||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
"columns": 0,
|
"columns": 0,
|
||||||
|
"depends_on": "eval:doc.notify_by_email",
|
||||||
|
"fieldname": "section_break_20",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_global_search": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Message",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allow_bulk_edit": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"default": "Please find attached {{ doc.doctype }} #{{ doc.name }}",
|
||||||
|
"fieldname": "message",
|
||||||
|
"fieldtype": "Text",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_global_search": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Message",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allow_bulk_edit": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 1,
|
||||||
|
"columns": 0,
|
||||||
|
"depends_on": "eval: !doc.__islocal",
|
||||||
"fieldname": "section_break_16",
|
"fieldname": "section_break_16",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
@ -690,7 +785,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2017-09-14 12:09:38.471458",
|
"modified": "2017-09-28 18:27:48.522098",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Subscription",
|
"name": "Subscription",
|
||||||
|
@ -7,6 +7,7 @@ import frappe
|
|||||||
import calendar
|
import calendar
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.desk.form import assign_to
|
from frappe.desk.form import assign_to
|
||||||
|
from frappe.utils.jinja import validate_template
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from frappe.utils.user import get_system_managers
|
from frappe.utils.user import get_system_managers
|
||||||
from frappe.utils import cstr, getdate, split_emails, add_days, today
|
from frappe.utils import cstr, getdate, split_emails, add_days, today
|
||||||
@ -20,6 +21,9 @@ class Subscription(Document):
|
|||||||
self.validate_next_schedule_date()
|
self.validate_next_schedule_date()
|
||||||
self.validate_email_id()
|
self.validate_email_id()
|
||||||
|
|
||||||
|
validate_template(self.subject or "")
|
||||||
|
validate_template(self.message or "")
|
||||||
|
|
||||||
def before_submit(self):
|
def before_submit(self):
|
||||||
self.set_next_schedule_date()
|
self.set_next_schedule_date()
|
||||||
|
|
||||||
@ -114,7 +118,7 @@ def create_documents(data, schedule_date):
|
|||||||
doc = make_new_document(data, schedule_date)
|
doc = make_new_document(data, schedule_date)
|
||||||
if data.notify_by_email and data.recipients:
|
if data.notify_by_email and data.recipients:
|
||||||
print_format = data.print_format or "Standard"
|
print_format = data.print_format or "Standard"
|
||||||
send_notification(doc, print_format, data.recipients)
|
send_notification(doc, data, print_format=print_format)
|
||||||
|
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -174,14 +178,25 @@ def get_next_date(dt, mcount, day=None):
|
|||||||
|
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
def send_notification(new_rv, print_format='Standard', recipients=None):
|
def send_notification(new_rv, subscription_doc, print_format='Standard'):
|
||||||
"""Notify concerned persons about recurring document generation"""
|
"""Notify concerned persons about recurring document generation"""
|
||||||
print_format = print_format
|
print_format = print_format
|
||||||
|
|
||||||
frappe.sendmail(recipients,
|
if not subscription_doc.subject:
|
||||||
subject= _("New {0}: #{1}").format(new_rv.doctype, new_rv.name),
|
subject = _("New {0}: #{1}").format(new_rv.doctype, new_rv.name)
|
||||||
message = _("Please find attached {0} #{1}").format(new_rv.doctype, new_rv.name),
|
elif "{" in subscription_doc.subject:
|
||||||
attachments = [frappe.attach_print(new_rv.doctype, new_rv.name, file_name=new_rv.name, print_format=print_format)])
|
subject = frappe.render_template(subscription_doc.subject, {'doc': new_rv})
|
||||||
|
|
||||||
|
if not subscription_doc.message:
|
||||||
|
message = _("Please find attached {0} #{1}").format(new_rv.doctype, new_rv.name)
|
||||||
|
elif "{" in subscription_doc.message:
|
||||||
|
message = frappe.render_template(subscription_doc.message, {'doc': new_rv})
|
||||||
|
|
||||||
|
attachments = [frappe.attach_print(new_rv.doctype, new_rv.name,
|
||||||
|
file_name=new_rv.name, print_format=print_format)]
|
||||||
|
|
||||||
|
frappe.sendmail(subscription_doc.recipients,
|
||||||
|
subject=subject, message=message, attachments=attachments)
|
||||||
|
|
||||||
def notify_errors(doc, doctype, party, owner, name):
|
def notify_errors(doc, doctype, party, owner, name):
|
||||||
recipients = get_system_managers(only_name=True)
|
recipients = get_system_managers(only_name=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user