From bf8715dba4621977896eef099ec30c4c2b2527d6 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 16 Sep 2014 14:57:31 +0530 Subject: [PATCH] [refactor] used frappe.sendmail --- erpnext/hr/doctype/salary_slip/salary_slip.py | 4 +--- .../doctype/backup_manager/backup_manager.py | 19 +++++++++---------- .../doctype/email_digest/email_digest.py | 5 ++--- erpnext/stock/utils.py | 9 ++++----- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py index 638500b996..f3ac6521a0 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -185,12 +185,10 @@ class SalarySlip(TransactionBase): def send_mail_funct(self): - from frappe.email import sendmail - receiver = frappe.db.get_value("Employee", self.employee, "company_email") if receiver: subj = 'Salary Slip - ' + cstr(self.month) +'/'+cstr(self.fiscal_year) - sendmail([receiver], subject=subj, msg = _("Please see attachment"), + frappe.sendmail([receiver], subject=subj, msg = _("Please see attachment"), attachments=[{ "fname": self.name + ".pdf", "fcontent": frappe.get_print_format(self.doctype, self.name, as_pdf = True) diff --git a/erpnext/setup/doctype/backup_manager/backup_manager.py b/erpnext/setup/doctype/backup_manager/backup_manager.py index 99cae9aa75..2695a4621a 100644 --- a/erpnext/setup/doctype/backup_manager/backup_manager.py +++ b/erpnext/setup/doctype/backup_manager/backup_manager.py @@ -21,10 +21,10 @@ def take_backups_weekly(): def take_backups_if(freq): if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq: take_backups_dropbox() - + # if frappe.db.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq: # take_backups_gdrive() - + @frappe.whitelist() def take_backups_dropbox(): did_not_upload, error_log = [], [] @@ -32,7 +32,7 @@ def take_backups_dropbox(): from erpnext.setup.doctype.backup_manager.backup_dropbox import backup_to_dropbox did_not_upload, error_log = backup_to_dropbox() if did_not_upload: raise Exception - + send_email(True, "Dropbox") except Exception: file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] @@ -40,7 +40,7 @@ def take_backups_dropbox(): frappe.errprint(error_message) send_email(False, "Dropbox", error_message) -#backup to gdrive +#backup to gdrive @frappe.whitelist() def take_backups_gdrive(): did_not_upload, error_log = [], [] @@ -48,7 +48,7 @@ def take_backups_gdrive(): from erpnext.setup.doctype.backup_manager.backup_googledrive import backup_to_gdrive did_not_upload, error_log = backup_to_gdrive() if did_not_upload: raise Exception - + send_email(True, "Google Drive") except Exception: file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] @@ -57,10 +57,9 @@ def take_backups_gdrive(): send_email(False, "Google Drive", error_message) def send_email(success, service_name, error_status=None): - from frappe.email import sendmail if success: subject = "Backup Upload Successful" - message ="""

Backup Uploaded Successfully

Hi there, this is just to inform you + message ="""

Backup Uploaded Successfully

Hi there, this is just to inform you that your backup was successfully uploaded to your %s account. So relax!

""" % service_name @@ -71,9 +70,9 @@ def send_email(success, service_name, error_status=None):

Error message: %s

Please contact your system manager for more information.

""" % (service_name, error_status) - + if not frappe.db: frappe.connect() - + recipients = frappe.db.get_value("Backup Manager", None, "send_notifications_to").split(",") - sendmail(recipients, subject=subject, msg=message) + frappe.sendmail(recipients=recipients, subject=subject, msg=message) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index c66d3de0f1..89a87f7a91 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -9,7 +9,6 @@ from frappe.utils import fmt_money, formatdate, now_datetime, cstr, esc, \ from frappe.utils.dateutils import datetime_in_user_format from datetime import timedelta from dateutil.relativedelta import relativedelta -from frappe.email import sendmail from frappe.core.doctype.user.user import STANDARD_USERS content_sequence = [ @@ -83,10 +82,10 @@ class EmailDigest(Document): msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \ common_msg) if msg_for_this_receipient: - sendmail(recipients=user_id, + frappe.sendmail(recipients=user_id, subject="[ERPNext] [{frequency} Digest] {name}".format( frequency=self.frequency, name=self.name), - msg=msg_for_this_receipient) + msg=msg_for_this_receipient, bulk=True) def get_digest_msg(self): return self.get_msg_html(self.get_user_specific_content(frappe.session.user) + \ diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 31172902d3..c441ae7d2a 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -6,7 +6,6 @@ from frappe import _ import json from frappe.utils import flt, cstr, nowdate, add_days, cint from frappe.defaults import get_global_default -from frappe.email import sendmail from erpnext.accounts.utils import get_fiscal_year, FiscalYearError class InvalidWarehouseCompany(frappe.ValidationError): pass @@ -336,11 +335,11 @@ def send_email_notification(mr_list): msg += "" + item.item_code + "" + item.warehouse + "" + \ cstr(item.qty) + "" + cstr(item.uom) + "" msg += "" - sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg) + frappe.sendmail(recipients=email_list, subject='Auto Material Request Generation Notification', msg = msg) def notify_errors(exceptions_list): subject = "[Important] [ERPNext] Error(s) while creating Material Requests based on Re-order Levels" - msg = """Dear System Manager, + content = """Dear System Manager, An error occured for certain Items while creating Material Requests based on Re-order level. @@ -353,5 +352,5 @@ Please rectify these issues: Regards, Administrator""" % ("\n\n".join(exceptions_list),) - from frappe.utils.user import get_system_managers - sendmail(get_system_managers(), subject=subject, msg=msg) + from frappe.email import sendmail_to_system_managers + sendmail_to_system_managers(subject, content)