diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 5814e56c9e6..99f17c8bab2 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -8,7 +8,6 @@ import webnotes.defaults
from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, \
get_first_day, get_last_day
-from webnotes.utils.email_lib import sendmail
from webnotes.utils import comma_and, get_url
from webnotes.model.doc import make_autoname
from webnotes.model.bean import getlist
@@ -689,7 +688,7 @@ def manage_recurring_invoices(next_date=None, commit=True):
webnotes.conn.begin()
webnotes.conn.sql("update `tabSales Invoice` set \
convert_into_recurring_invoice = 0 where name = %s", ref_invoice)
- notify_errors(ref_invoice, ref_wrapper.doc.owner)
+ notify_errors(ref_invoice, ref_wrapper.doc.customer, ref_wrapper.doc.owner)
webnotes.conn.commit()
exception_list.append(webnotes.get_traceback())
@@ -738,101 +737,23 @@ def make_new_invoice(ref_wrapper, posting_date):
def send_notification(new_rv):
"""Notify concerned persons about recurring invoice generation"""
- subject = "Invoice : " + new_rv.doc.name
-
- com = new_rv.doc.company
-
- hd = '''
%s
- Invoice: %s
-
-
- Customer %s %s |
- Invoice Date : %s Invoice Period : %s to %s Due Date : %s |
-
-
- ''' % (com, new_rv.doc.name, new_rv.doc.customer_name, new_rv.doc.address_display, getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"), \
- getdate(new_rv.doc.invoice_period_from_date).strftime("%d-%m-%Y"), getdate(new_rv.doc.invoice_period_to_date).strftime("%d-%m-%Y"),\
- getdate(new_rv.doc.due_date).strftime("%d-%m-%Y"))
-
- tbl = '''
-
- | Item |
- Description |
- Qty |
- Rate |
- Amount |
-
- '''
- for d in getlist(new_rv.doclist, 'entries'):
- tbl += '| ' + cstr(d.item_code) +' | ' + cstr(d.description) + \
- ' | ' + cstr(d.qty) +' | ' + cstr(d.basic_rate) + \
- ' | ' + cstr(d.amount) +' |
'
- tbl += '
'
-
- totals ='''
-
- |
-
-
-
- | Net Total: | %s |
-
- | Total Tax: | %s |
-
- | Grand Total: | %s |
-
- | In Words: | %s |
-
-
- |
-
- | Terms and Conditions: |
- | %s |
-
- ''' % (new_rv.doc.net_total,
- new_rv.doc.other_charges_total,new_rv.doc.grand_total,
- new_rv.doc.in_words,new_rv.doc.terms)
-
-
- msg = hd + tbl + totals
-
- sendmail(new_rv.doc.notification_email_address, subject=subject, msg = msg)
+ from webnotes.core.doctype.print_format.print_format import get_html
+ webnotes.sendmail(new_rv.doc.notification_email_address,
+ subject="New Invoice : " + new_rv.doc.name,
+ message = get_html(new_rv.doc, new_rv.doclist, "SalesInvoice"))
-def notify_errors(inv, owner):
- import webnotes
-
- exception_msg = """
- Dear User,
-
- An error occured while creating recurring invoice from %s (at %s).
-
- May be there are some invalid email ids mentioned in the invoice.
-
- To stop sending repetitive error notifications from the system, we have unchecked
- "Convert into Recurring" field in the invoice %s.
-
-
- Please correct the invoice and make the invoice recurring again.
-
- It is necessary to take this action today itself for the above mentioned recurring invoice \
- to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \
- of this invoice for generating the recurring invoice.
-
- Regards,
- Administrator
-
- """ % (inv, get_url(), inv)
- subj = "[Urgent] Error while creating recurring invoice from %s" % inv
-
+def notify_errors(inv, customer, owner):
from webnotes.profile import get_system_managers
- recipients = get_system_managers()
- owner_email = webnotes.conn.get_value("Profile", owner, "email")
- if not owner_email in recipients:
- recipients.append(owner_email)
-
- assign_task_to_owner(inv, exception_msg, recipients)
- sendmail(recipients, subject=subj, msg = exception_msg)
+
+ webnotes.sendmail(recipients=get_system_managers() + [webnotes.conn.get_value("Profile", owner, "email")],
+ subject="[Urgent] Error while creating recurring invoice for %s" % inv,
+ message = webnotes.get_template("template/emails/recurring_invoice_failed.html").render({
+ "name": inv,
+ "customer": customer
+ })
+
+ assign_task_to_owner(inv, "Recurring Invoice Failed", recipients)
def assign_task_to_owner(inv, msg, users):
for d in users:
diff --git a/erpnext/templates/emails/recurring_invoice_failed.html b/erpnext/templates/emails/recurring_invoice_failed.html
new file mode 100644
index 00000000000..dd3b913cea4
--- /dev/null
+++ b/erpnext/templates/emails/recurring_invoice_failed.html
@@ -0,0 +1,12 @@
+Recurring Invoice Failed
+
+An error occured while creating recurring invoice {{ name }} for {{ customer }}.
+This could be because of some invalid email ids in the invoice.
+To stop sending repetitive error notifications from the system, we have unchecked
+"Convert into Recurring" field in the invoice {{ name }}.
+Please correct the invoice and make the invoice recurring again.
+
+It is necessary to take this action today itself for the above mentioned recurring invoice \
+to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \
+of this invoice for generating the recurring invoice.
+[This email is autogenerated]