From a5cb9ae8bdd7c810bf3241ea7525d378b91b05a4 Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Mon, 14 Aug 2017 09:50:15 +0530 Subject: [PATCH] send email via the background jobs (#10374) --- erpnext/hr/doctype/salary_slip/salary_slip.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py index 2bd08c22c1..1d17613381 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -11,6 +11,7 @@ from frappe import msgprint, _ from erpnext.hr.doctype.process_payroll.process_payroll import get_start_end_dates from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee from erpnext.utilities.transaction_base import TransactionBase +from frappe.utils.background_jobs import enqueue class SalarySlip(TransactionBase): def autoname(self): @@ -396,9 +397,15 @@ class SalarySlip(TransactionBase): receiver = frappe.db.get_value("Employee", self.employee, "prefered_email") if receiver: - subj = 'Salary Slip - from {0} to {1}'.format(self.start_date, self.end_date) - frappe.sendmail([receiver], subject=subj, message = _("Please see attachment"), - attachments=[frappe.attach_print(self.doctype, self.name, file_name=self.name)], reference_doctype= self.doctype, reference_name= self.name) + email_args = { + "recipients": [receiver], + "message": _("Please see attachment"), + "subject": 'Salary Slip - from {0} to {1}'.format(self.start_date, self.end_date), + "attachments": [frappe.attach_print(self.doctype, self.name, file_name=self.name)], + "reference_doctype": self.doctype, + "reference_name": self.name + } + enqueue(method=frappe.sendmail, queue='short', timeout=300, async=True, **email_args) else: msgprint(_("{0}: Employee email not found, hence email not sent").format(self.employee_name))