diff --git a/erpnext/hr/doctype/salary_manager/salary_manager.py b/erpnext/hr/doctype/salary_manager/salary_manager.py
index 111366b9186..660890a3c89 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.doclist import getlist, copy_doclist
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 @@ class DocType:
emp_list = self.get_emp_list()
log = ""
if emp_list:
- log = "
| Following Salary Slip has been created: |
| SAL SLIP ID | EMPLOYEE NAME |
"
+ log = "| Following Salary Slip has been created: |
| SAL SLIP ID | EMPLOYEE NAME |
"
else:
log = "| No employee found for the above selected criteria |
"
@@ -111,7 +110,7 @@ class DocType:
for d in getlist(ss_obj.doclist, 'deduction_details'):
d.save()
- log += '| ' + ss.name + ' | ' + ss_obj.doc.employee_name + ' |
'
+ log += '| ' + ss.name + ' | ' + ss_obj.doc.employee_name + ' |
'
log += '
'
return log
@@ -132,28 +131,49 @@ class DocType:
"""
Submit all salary slips based on selected criteria
"""
- ss_list = self.get_sal_slip_list()
- log = ""
- if ss_list:
- log = """
-
- | Following Salary Slip has been submitted: |
-
-
- | SAL SLIP ID |
- EMPLOYEE NAME |
-
- """
- else:
- log = "| No salary slip found to submit for the above selected criteria |
"
-
+ 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 += '| ' + ss[0] + ' | ' + ss_obj.doc.employee_name + ' |
'
- log += '
'
+ 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 = """
+ Submitted Salary Slips%s:\
+
%s
+ """ % (mail_sent_msg, '
'.join(submitted_ss))
+
+ if not_submitted_ss:
+ log += """
+ Not Submitted Salary Slips: \
+
%s
\
+ Reason:
\
+ May be company email id specified in employee master is not valid.
\
+ Please mention correct email id in employee master or if you don't want to \
+ send mail, uncheck 'Send Email' checkbox.
\
+ Then try to submit Salary Slip again.
+ """% ('
'.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 3439fc861fd..3187eb43ffd 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -281,4 +281,4 @@ class DocType(TransactionBase):
'''%(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")