salary slip will not submitted through salary manager if Send email checked and invalid email id
diff --git a/erpnext/hr/doctype/salary_manager/salary_manager.py b/erpnext/hr/doctype/salary_manager/salary_manager.py
index 111366b..660890a 100644
--- a/erpnext/hr/doctype/salary_manager/salary_manager.py
+++ b/erpnext/hr/doctype/salary_manager/salary_manager.py
@@ -24,7 +24,6 @@
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
-set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
@@ -84,7 +83,7 @@
emp_list = self.get_emp_list()
log = ""
if emp_list:
- log = "<table><tr><td colspan = 2>Following Salary Slip has been created: </td></tr><tr><td><u>SAL SLIP ID</u></td><td><u>EMPLOYEE NAME</u></td></tr>"
+ log = "<table width=100%><tr><td colspan = 2>Following Salary Slip has been created: </td></tr><tr><td width=50%><u>SAL SLIP ID</u></td><td width=50%><u>EMPLOYEE NAME</u></td></tr>"
else:
log = "<table><tr><td colspan = 2>No employee found for the above selected criteria</td></tr>"
@@ -111,7 +110,7 @@
for d in getlist(ss_obj.doclist, 'deduction_details'):
d.save()
- log += '<tr><td>' + ss.name + '</td><td>' + ss_obj.doc.employee_name + '</td></tr>'
+ log += '<tr><td width=50%>' + ss.name + '</td><td width=50%>' + ss_obj.doc.employee_name + '</td></tr>'
log += '</table>'
return log
@@ -132,28 +131,49 @@
"""
Submit all salary slips based on selected criteria
"""
- ss_list = self.get_sal_slip_list()
- log = ""
- if ss_list:
- log = """<table>
- <tr>
- <td colspan = 2>Following Salary Slip has been submitted: </td>
- </tr>
- <tr>
- <td><u>SAL SLIP ID</u></td>
- <td><u>EMPLOYEE NAME</u></td>
- </tr>
- """
- else:
- log = "<table><tr><td colspan = 2>No salary slip found to submit for the above selected criteria</td></tr>"
-
+ ss_list = self.get_sal_slip_list()
+ not_submitted_ss = []
for ss in ss_list:
ss_obj = get_obj("Salary Slip",ss[0],with_children=1)
- set(ss_obj.doc, 'docstatus', 1)
- ss_obj.on_submit()
+ try:
+ webnotes.conn.set(ss_obj.doc, 'email_check', cint(self.doc.send_mail))
+ if cint(self.doc.send_email) == 1:
+ ss_obj.send_mail_funct()
+
+ webnotes.conn.set(ss_obj.doc, 'docstatus', 1)
+ except Exception,e:
+ not_submitted_ss.append(ss[0])
+ msgprint(e)
+ continue
+
+ return self.create_log(ss_list, not_submitted_ss)
+
+
+ def create_log(self, all_ss, not_submitted_ss):
+ log = ''
+ if not all_ss:
+ log = "No salary slip found to submit for the above selected criteria"
+ else:
+ all_ss = [d[0] for d in all_ss]
- log += '<tr><td>' + ss[0] + '</td><td>' + ss_obj.doc.employee_name + '</td></tr>'
- log += '</table>'
+ submitted_ss = list(set(all_ss) - set(not_submitted_ss))
+ if submitted_ss:
+ mail_sent_msg = self.doc.send_email and " (Mail has been sent to the employee)" or ""
+ log = """
+ <b>Submitted Salary Slips%s:</b>\
+ <br><br> %s <br><br>
+ """ % (mail_sent_msg, '<br>'.join(submitted_ss))
+
+ if not_submitted_ss:
+ log += """
+ <b>Not Submitted Salary Slips: </b>\
+ <br><br> %s <br><br> \
+ Reason: <br>\
+ May be company email id specified in employee master is not valid. <br> \
+ Please mention correct email id in employee master or if you don't want to \
+ send mail, uncheck 'Send Email' checkbox. <br>\
+ Then try to submit Salary Slip again.
+ """% ('<br>'.join(not_submitted_ss))
return log
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index 3439fc8..3187eb4 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -281,4 +281,4 @@
</table></div>'''%(cstr(letter_head[0][0]),cstr(self.doc.employee), cstr(self.doc.employee_name), cstr(self.doc.month), cstr(self.doc.fiscal_year), cstr(self.doc.department), cstr(self.doc.branch), cstr(self.doc.designation), cstr(self.doc.grade), cstr(self.doc.bank_account_no), cstr(self.doc.bank_name), cstr(self.doc.arrear_amount), cstr(self.doc.payment_days), earn_table, ded_table, cstr(flt(self.doc.gross_pay)), cstr(flt(self.doc.total_deduction)), cstr(flt(self.doc.net_pay)), cstr(self.doc.total_in_words))
sendmail([receiver], subject=subj, msg = msg)
else:
- msgprint("Company Email ID not found.")
+ msgprint("Company Email ID not found, hence mail not sent")