mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
[refactor] used frappe.sendmail
This commit is contained in:
@@ -185,12 +185,10 @@ class SalarySlip(TransactionBase):
|
|||||||
|
|
||||||
|
|
||||||
def send_mail_funct(self):
|
def send_mail_funct(self):
|
||||||
from frappe.email import sendmail
|
|
||||||
|
|
||||||
receiver = frappe.db.get_value("Employee", self.employee, "company_email")
|
receiver = frappe.db.get_value("Employee", self.employee, "company_email")
|
||||||
if receiver:
|
if receiver:
|
||||||
subj = 'Salary Slip - ' + cstr(self.month) +'/'+cstr(self.fiscal_year)
|
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=[{
|
attachments=[{
|
||||||
"fname": self.name + ".pdf",
|
"fname": self.name + ".pdf",
|
||||||
"fcontent": frappe.get_print_format(self.doctype, self.name, as_pdf = True)
|
"fcontent": frappe.get_print_format(self.doctype, self.name, as_pdf = True)
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ def take_backups_weekly():
|
|||||||
def take_backups_if(freq):
|
def take_backups_if(freq):
|
||||||
if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
|
if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
|
||||||
take_backups_dropbox()
|
take_backups_dropbox()
|
||||||
|
|
||||||
# if frappe.db.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
|
# if frappe.db.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
|
||||||
# take_backups_gdrive()
|
# take_backups_gdrive()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def take_backups_dropbox():
|
def take_backups_dropbox():
|
||||||
did_not_upload, error_log = [], []
|
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
|
from erpnext.setup.doctype.backup_manager.backup_dropbox import backup_to_dropbox
|
||||||
did_not_upload, error_log = backup_to_dropbox()
|
did_not_upload, error_log = backup_to_dropbox()
|
||||||
if did_not_upload: raise Exception
|
if did_not_upload: raise Exception
|
||||||
|
|
||||||
send_email(True, "Dropbox")
|
send_email(True, "Dropbox")
|
||||||
except Exception:
|
except Exception:
|
||||||
file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
|
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)
|
frappe.errprint(error_message)
|
||||||
send_email(False, "Dropbox", error_message)
|
send_email(False, "Dropbox", error_message)
|
||||||
|
|
||||||
#backup to gdrive
|
#backup to gdrive
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def take_backups_gdrive():
|
def take_backups_gdrive():
|
||||||
did_not_upload, error_log = [], []
|
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
|
from erpnext.setup.doctype.backup_manager.backup_googledrive import backup_to_gdrive
|
||||||
did_not_upload, error_log = backup_to_gdrive()
|
did_not_upload, error_log = backup_to_gdrive()
|
||||||
if did_not_upload: raise Exception
|
if did_not_upload: raise Exception
|
||||||
|
|
||||||
send_email(True, "Google Drive")
|
send_email(True, "Google Drive")
|
||||||
except Exception:
|
except Exception:
|
||||||
file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
|
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)
|
send_email(False, "Google Drive", error_message)
|
||||||
|
|
||||||
def send_email(success, service_name, error_status=None):
|
def send_email(success, service_name, error_status=None):
|
||||||
from frappe.email import sendmail
|
|
||||||
if success:
|
if success:
|
||||||
subject = "Backup Upload Successful"
|
subject = "Backup Upload Successful"
|
||||||
message ="""<h3>Backup Uploaded Successfully</h3><p>Hi there, this is just to inform you
|
message ="""<h3>Backup Uploaded Successfully</h3><p>Hi there, this is just to inform you
|
||||||
that your backup was successfully uploaded to your %s account. So relax!</p>
|
that your backup was successfully uploaded to your %s account. So relax!</p>
|
||||||
""" % service_name
|
""" % service_name
|
||||||
|
|
||||||
@@ -71,9 +70,9 @@ def send_email(success, service_name, error_status=None):
|
|||||||
<p>Error message: %s</p>
|
<p>Error message: %s</p>
|
||||||
<p>Please contact your system manager for more information.</p>
|
<p>Please contact your system manager for more information.</p>
|
||||||
""" % (service_name, error_status)
|
""" % (service_name, error_status)
|
||||||
|
|
||||||
if not frappe.db:
|
if not frappe.db:
|
||||||
frappe.connect()
|
frappe.connect()
|
||||||
|
|
||||||
recipients = frappe.db.get_value("Backup Manager", None, "send_notifications_to").split(",")
|
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)
|
||||||
|
|||||||
@@ -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 frappe.utils.dateutils import datetime_in_user_format
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from frappe.email import sendmail
|
|
||||||
from frappe.core.doctype.user.user import STANDARD_USERS
|
from frappe.core.doctype.user.user import STANDARD_USERS
|
||||||
|
|
||||||
content_sequence = [
|
content_sequence = [
|
||||||
@@ -83,10 +82,10 @@ class EmailDigest(Document):
|
|||||||
msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \
|
msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \
|
||||||
common_msg)
|
common_msg)
|
||||||
if msg_for_this_receipient:
|
if msg_for_this_receipient:
|
||||||
sendmail(recipients=user_id,
|
frappe.sendmail(recipients=user_id,
|
||||||
subject="[ERPNext] [{frequency} Digest] {name}".format(
|
subject="[ERPNext] [{frequency} Digest] {name}".format(
|
||||||
frequency=self.frequency, name=self.name),
|
frequency=self.frequency, name=self.name),
|
||||||
msg=msg_for_this_receipient)
|
msg=msg_for_this_receipient, bulk=True)
|
||||||
|
|
||||||
def get_digest_msg(self):
|
def get_digest_msg(self):
|
||||||
return self.get_msg_html(self.get_user_specific_content(frappe.session.user) + \
|
return self.get_msg_html(self.get_user_specific_content(frappe.session.user) + \
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from frappe import _
|
|||||||
import json
|
import json
|
||||||
from frappe.utils import flt, cstr, nowdate, add_days, cint
|
from frappe.utils import flt, cstr, nowdate, add_days, cint
|
||||||
from frappe.defaults import get_global_default
|
from frappe.defaults import get_global_default
|
||||||
from frappe.email import sendmail
|
|
||||||
from erpnext.accounts.utils import get_fiscal_year, FiscalYearError
|
from erpnext.accounts.utils import get_fiscal_year, FiscalYearError
|
||||||
|
|
||||||
class InvalidWarehouseCompany(frappe.ValidationError): pass
|
class InvalidWarehouseCompany(frappe.ValidationError): pass
|
||||||
@@ -336,11 +335,11 @@ def send_email_notification(mr_list):
|
|||||||
msg += "<tr><td>" + item.item_code + "</td><td>" + item.warehouse + "</td><td>" + \
|
msg += "<tr><td>" + item.item_code + "</td><td>" + item.warehouse + "</td><td>" + \
|
||||||
cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>"
|
cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>"
|
||||||
msg += "</table>"
|
msg += "</table>"
|
||||||
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):
|
def notify_errors(exceptions_list):
|
||||||
subject = "[Important] [ERPNext] Error(s) while creating Material Requests based on Re-order Levels"
|
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.
|
An error occured for certain Items while creating Material Requests based on Re-order level.
|
||||||
|
|
||||||
@@ -353,5 +352,5 @@ Please rectify these issues:
|
|||||||
Regards,
|
Regards,
|
||||||
Administrator""" % ("\n\n".join(exceptions_list),)
|
Administrator""" % ("\n\n".join(exceptions_list),)
|
||||||
|
|
||||||
from frappe.utils.user import get_system_managers
|
from frappe.email import sendmail_to_system_managers
|
||||||
sendmail(get_system_managers(), subject=subject, msg=msg)
|
sendmail_to_system_managers(subject, content)
|
||||||
|
|||||||
Reference in New Issue
Block a user