send email via the background jobs (#10374) (#10393)

* send the email via the background worker in the payment request (#10350)

* send email via the background jobs (#10374)
This commit is contained in:
Makarand Bauskar 2017-08-14 12:22:50 +05:30 committed by GitHub
parent 41d77e8d86
commit e5ae4d3bd3
2 changed files with 20 additions and 6 deletions

View File

@ -11,6 +11,7 @@ from erpnext.accounts.party import get_party_account
from erpnext.accounts.utils import get_account_currency
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry, get_company_defaults
from frappe.integrations.utils import get_payment_gateway_controller
from frappe.utils.background_jobs import enqueue
class PaymentRequest(Document):
def validate(self):
@ -142,9 +143,15 @@ class PaymentRequest(Document):
def send_email(self):
"""send email with payment link"""
frappe.sendmail(recipients=self.email_to, sender=None, subject=self.subject,
message=self.get_message(), attachments=[frappe.attach_print(self.reference_doctype,
self.reference_name, file_name=self.reference_name, print_format=self.print_format)])
email_args = {
"recipients": self.email_to,
"sender": None,
"subject": self.subject,
"message": self.get_message(),
"now": True,
"attachments": [frappe.attach_print(self.reference_doctype, self.reference_name,
file_name=self.reference_name, print_format=self.print_format)]}
enqueue(method=frappe.sendmail, queue='short', timeout=300, async=True, **email_args)
def get_message(self):
"""return message with payment gateway link"""

View File

@ -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))