diff --git a/hrms/payroll/doctype/payroll_settings/payroll_settings.json b/hrms/payroll/doctype/payroll_settings/payroll_settings.json
index 85c2f93369..a49d6679cc 100644
--- a/hrms/payroll/doctype/payroll_settings/payroll_settings.json
+++ b/hrms/payroll/doctype/payroll_settings/payroll_settings.json
@@ -22,6 +22,7 @@
"email_salary_slip_to_employee",
"sender",
"sender_email",
+ "email_template",
"column_break_iewr",
"encrypt_salary_slips_in_emails",
"password_policy",
@@ -172,13 +173,20 @@
"fieldtype": "Data",
"label": "Sender Email",
"read_only": 1
+ },
+ {
+ "depends_on": "eval:doc.email_salary_slip_to_employee",
+ "fieldname": "email_template",
+ "fieldtype": "Link",
+ "label": "Email Template",
+ "options": "Email Template"
}
],
"icon": "fa fa-cog",
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2023-11-01 13:51:04.225492",
+ "modified": "2024-01-23 17:42:52.958013",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Settings",
diff --git a/hrms/payroll/doctype/salary_slip/salary_slip.py b/hrms/payroll/doctype/salary_slip/salary_slip.py
index 635c752d9d..9df4919546 100644
--- a/hrms/payroll/doctype/salary_slip/salary_slip.py
+++ b/hrms/payroll/doctype/salary_slip/salary_slip.py
@@ -1794,21 +1794,29 @@ def get_component_totals(self, component_type, depends_on_payment_days=0):
def email_salary_slip(self):
receiver = frappe.db.get_value("Employee", self.employee, "prefered_email", cache=True)
payroll_settings = frappe.get_single("Payroll Settings")
- message = "Please see attachment"
+ subject = "Salary Slip - from {0} to {1}".format(self.start_date, self.end_date)
+ message = _("Please see attachment")
+ if payroll_settings.email_template:
+ email_template = frappe.get_doc("Email Template", payroll_settings.email_template)
+ doc = frappe.get_doc("Salary Slip", self.name)
+ context = doc.as_dict()
+ subject = frappe.render_template(email_template.subject, context)
+ message = frappe.render_template(email_template.response_, context)
password = None
if payroll_settings.encrypt_salary_slips_in_emails:
password = generate_password_for_pdf(payroll_settings.password_policy, self.employee)
- message += """
Note: Your salary slip is password protected,
- the password to unlock the PDF is of the format {0}. """.format(
- payroll_settings.password_policy
- )
+ if not payroll_settings.email_template:
+ message += _("""
Note: Your salary slip is password protected,
+ the password to unlock the PDF is of the format {0}. """.format(
+ payroll_settings.password_policy)
+ )
if receiver:
email_args = {
"sender": payroll_settings.sender_email,
"recipients": [receiver],
- "message": _(message),
- "subject": "Salary Slip - from {0} to {1}".format(self.start_date, self.end_date),
+ "message": message,
+ "subject": subject,
"attachments": [
frappe.attach_print(self.doctype, self.name, file_name=self.name, password=password)
],
diff --git a/hrms/payroll/doctype/salary_slip/test_salary_slip.py b/hrms/payroll/doctype/salary_slip/test_salary_slip.py
index 01048108cc..df23a6f2c8 100644
--- a/hrms/payroll/doctype/salary_slip/test_salary_slip.py
+++ b/hrms/payroll/doctype/salary_slip/test_salary_slip.py
@@ -52,6 +52,7 @@ class TestSalarySlip(FrappeTestCase):
def setUp(self):
setup_test()
frappe.flags.pop("via_payroll_entry", None)
+ create_ss_email_template()
clear_cache()
def tearDown(self):
@@ -607,6 +608,22 @@ def test_email_salary_slip(self):
email_queue = frappe.db.a_row_exists("Email Queue")
self.assertTrue(email_queue)
+ @change_settings(
+ "Payroll Settings",
+ {"email_salary_slip_to_employee": 1, "email_template": "Salary Slip"}
+ )
+ def test_email_salary_slip_with_email_template(self):
+ frappe.db.delete("Email Queue")
+
+ emp_id = make_employee("test_email_salary_slip@salary.com", company="_Test Company")
+ ss = make_employee_salary_slip(emp_id, "Monthly", "Test Salary Slip Email")
+ ss.company = "_Test Company"
+ ss.save()
+ ss.submit()
+
+ email_queue = frappe.db.a_row_exists("Email Queue")
+ self.assertTrue(email_queue)
+
@if_lending_app_installed
def test_loan_repayment_salary_slip(self):
from lending.loan_management.doctype.loan.test_loan import (
@@ -2391,6 +2408,20 @@ def mark_attendance(
attendance.submit()
+def create_ss_email_template():
+ if not frappe.db.exists("Email Template", "Salary Slip"):
+ ss_template = frappe.get_doc(
+ {
+ "doctype": "Salary Slip",
+ "name": "Delivery Notification",
+ "response": "Test Salary Slip",
+ "subject": "Test Subject",
+ "owner": frappe.session.user,
+ }
+ )
+ ss_template.insert()
+
+
def clear_cache():
for key in [
HOLIDAYS_BETWEEN_DATES,