def get_url(): import startup if hasattr(startup, "get_url"): url = startup.get_url() else: url = get_request_site_address() return url
def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0): """ Notify assignee that there is a change in assignment """ if not (assigned_by and owner and doc_type and doc_name): return # self assignment / closing - no message if assigned_by==owner: return from webnotes.boot import get_fullnames user_info = get_fullnames() # Search for email address in description -- i.e. assignee try: from startup import get_url url = get_url() except ImportError: from webnotes.utils import get_request_site_address url = get_request_site_address() assignment = """<a href="%s/app.html#!Form/%s/%s">%s: %s</a>""" % (url, doc_type, doc_name, doc_type, doc_name) if action=='CLOSE': if owner == webnotes.session.get('user'): arg = { 'contact': assigned_by, 'txt': "The task %s, that you assigned to %s, has been \ closed." % (assignment, user_info.get(owner, {}).get('fullname')) } else: arg = { 'contact': assigned_by, 'txt': "The task %s, that you assigned to %s, \ has been closed by %s." % (assignment, user_info.get(owner, {}).get('fullname'), user_info.get(webnotes.session.get('user'), {}).get('fullname')) } else: arg = { 'contact': owner, 'txt': "A new task, %s, has been assigned to you by %s." \ % (assignment, user_info.get(webnotes.session.get('user'), {}).get('fullname')), 'notify': notify } arg["parenttype"] = "Assignment" from utilities.page.messages import messages import json messages.post(json.dumps(arg))
def get_url_to_form(doctype, name, base_url=None, label=None): if not base_url: try: from startup import get_url base_url = get_url() except ImportError: base_url = get_request_site_address() if not label: label = name return """<a href="%(base_url)s/app.html#!Form/%(doctype)s/%(name)s">%(label)s</a>""" % locals()
def report_errors(): from webnotes.utils.email_lib import sendmail_to_system_managers from startup import get_url errors = [("""<p>Time: %(modified)s</p> <pre><code>%(error)s</code></pre>""" % d) for d in webnotes.conn.sql("""select modified, error from `tabScheduler Log` where DATEDIFF(NOW(), modified) < 1 limit 10""", as_dict=True)] if errors: sendmail_to_system_managers("ERPNext Scheduler Failure Report", (""" <p>Dear System Managers,</p> <p>Reporting ERPNext failed scheduler events for the day (max 10):</p> <p>URL: <a href="%(url)s" target="_blank">%(url)s</a></p><hr>""" % {"url":get_url()}) + "<hr>".join(errors))
def report_errors(): from webnotes.utils.email_lib import sendmail_to_system_managers from startup import get_url errors = [("""<p>Time: %(modified)s</p> <pre><code>%(error)s</code></pre>""" % d) for d in webnotes.conn.sql("""select modified, error from `tabScheduler Log` where DATEDIFF(NOW(), modified) < 1 limit 10""", as_dict=True)] if errors: sendmail_to_system_managers("ERPNext Scheduler Failure Report", (""" <p>Dear System Managers,</p> <p>Reporting ERPNext failed scheduler events for the day (max 10):</p> <p>URL: <a href="%(url)s" target="_blank">%(url)s</a></p><hr>""" % { "url": get_url() }) + "<hr>".join(errors))
def notify(arg=None): from webnotes.utils import cstr, get_fullname from startup import get_url fn = get_fullname(webnotes.user.name) or webnotes.user.name url = get_url() message = '''You have a message from <b>%s</b>: %s To answer, please login to your erpnext account at \ <a href=\"%s\" target='_blank'>%s</a> ''' % (fn, arg['txt'], url, url) sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \ or webnotes.user.name recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \ or arg["contact"]] from webnotes.utils.email_lib import sendmail sendmail(recipient, sender, message, arg.get("subject") or "You have a message from %s" % (fn, ))
def notify(arg=None): from webnotes.utils import cstr, get_fullname from startup import get_url fn = get_fullname(webnotes.user.name) or webnotes.user.name url = get_url() message = '''You have a message from <b>%s</b>: %s To answer, please login to your erpnext account at \ <a href=\"%s\" target='_blank'>%s</a> ''' % (fn, arg['txt'], url, url) sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \ or webnotes.user.name recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \ or arg["contact"]] from webnotes.utils.email_lib import sendmail sendmail(recipient, sender, message, arg.get("subject") or "You have a message from %s" % (fn,))