[fix] enqueue salary slip print email after completing accounting entries (#13633)
diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.py b/erpnext/hr/doctype/payroll_entry/payroll_entry.py
index 111df4c..c9d6290 100644
--- a/erpnext/hr/doctype/payroll_entry/payroll_entry.py
+++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.py
@@ -146,6 +146,7 @@
ss_list = self.get_sal_slip_list(ss_status=0)
submitted_ss = []
not_submitted_ss = []
+ frappe.flags.via_payroll_entry = True
for ss in ss_list:
ss_obj = frappe.get_doc("Salary Slip",ss[0])
ss_dict = {}
@@ -159,7 +160,7 @@
else:
try:
ss_obj.submit()
- submitted_ss.append(ss_dict)
+ submitted_ss.append(ss_obj)
except frappe.ValidationError:
not_submitted_ss.append(ss_dict)
@@ -168,8 +169,15 @@
frappe.msgprint(_("Salary Slip submitted for period from {0} to {1}")
.format(ss_obj.start_date, ss_obj.end_date))
+ self.email_salary_slip(submitted_ss)
+
return create_submit_log(submitted_ss, not_submitted_ss, jv_name)
+ def email_salary_slip(self, submitted_ss):
+ if frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee"):
+ for ss in submitted_ss:
+ ss.email_salary_slip()
+
def get_loan_details(self):
"""
Get loan details from submitted salary slip based on selected criteria
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index b9371e3..5fbd3b1 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -411,7 +411,7 @@
else:
self.set_status()
self.update_status(self.name)
- if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")):
+ if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")) and not frappe.flags.via_payroll_entry:
self.email_salary_slip()
def on_cancel(self):