Exemple #1
0
def send_anniversary_reminders():
    from frappe.utils.user import get_enabled_system_users
    users = None

    work_anniversary = get_employees_who_have_anniversary_today()
    if work_anniversary:
        if not users:
            users = [u.email_id or u.name for u in get_enabled_system_users()]

        for e in work_anniversary:
            exp = calculate_exp(e.date_of_joining)
            experience = exp + 1
            wish = """We are Proud to have an Employee like you as a part of VHRS Family,
                    We wish you Heartfelt Congratulations and Best Wishes on your %sth anniversary""" % (
                exp)
            args = dict(employee=e.employee_name,
                        experience=experience,
                        wish=wish,
                        company=frappe.defaults.get_defaults().company)
            frappe.sendmail(
                recipients=filter(
                    lambda u: u not in
                    (e.company_email, e.personal_email, e.user_id), users),
                subject=_("Work Anniversary Reminder for {0}").format(
                    e.employee_name),
                template='work_anniversary',
                args=args)
def get_usage_info():
	'''Get data to show for Usage Info'''
	# imported here to prevent circular import
	from frappe.email.queue import get_emails_sent_this_month

	limits = get_limits()
	if not (limits and any([limits.users, limits.space, limits.emails, limits.expiry])):
		# no limits!
		return

	limits.space = (limits.space or 0) * 1024.0 # to MB
	if not limits.space_usage:
		# hack! to show some progress
		limits.space_usage = {
			'database_size': 26,
			'files_size': 1,
			'backup_size': 1,
			'total': 28
		}

	usage_info = frappe._dict({
		'limits': limits,
		'enabled_users': len(get_enabled_system_users()),
		'emails_sent': get_emails_sent_this_month(),
		'space_usage': limits.space_usage['total'],
	})

	if limits.expiry:
		usage_info['expires_on'] = formatdate(limits.expiry)
		usage_info['days_to_expiry'] = (getdate(limits.expiry) - getdate()).days

	if limits.upgrade_url:
		usage_info['upgrade_url'] = get_upgrade_url(limits.upgrade_url)

	return usage_info
Exemple #3
0
def send_anniversary_reminders():
    from frappe.utils.user import get_enabled_system_users
    users = None

    work_anniversary = get_employees_who_have_anniversary_today()
    if work_anniversary:
        if not users:
            users = [u.email_id or u.name for u in get_enabled_system_users()]

        for e in work_anniversary:
            exp = calculate_exp(e.date_of_joining)

            def ordinal(n): return "%d%s" % (
                n, "tsnrhtdd"[(n/10 % 10 != 1)*(n % 10 < 4)*n % 10::4])
            print ordinal(exp)
            experience = exp + 1

            wish = """We are Proud to have an Employee like you as a part of VHRS Family,
                    We wish you Heartfelt Congratulations and Best Wishes on your %s anniversary""" % (ordinal(exp))
            args = dict(employee=e.employee_name, experience=ordinal(experience),
                        wish=wish, company=frappe.defaults.get_defaults().company)
            frappe.sendmail(recipients=filter(lambda u: u not in (e.company_email, e.personal_email, e.user_id), users),
                            # frappe.sendmail(recipients='*****@*****.**',
                            subject=_("Work Anniversary Reminder for {0}").format(
                                e.employee_name),
                            template='work_anniversary',
                            args=args)
Exemple #4
0
def get_usage_info():
    """Get data to show for Usage Info"""
    # imported here to prevent circular import
    from frappe.email.queue import get_emails_sent_this_month

    limits = get_limits()
    if not (limits and any([limits.users, limits.space, limits.emails, limits.expiry])):
        # no limits!
        return

    limits.space = (limits.space or 0) * 1024.0  # to MB
    if not limits.space_usage:
        # hack! to show some progress
        limits.space_usage = {"database_size": 26, "files_size": 1, "backup_size": 1, "total": 28}

    usage_info = frappe._dict(
        {
            "limits": limits,
            "enabled_users": len(get_enabled_system_users()),
            "emails_sent": get_emails_sent_this_month(),
            "space_usage": limits.space_usage["total"],
        }
    )

    if limits.expiry:
        usage_info["expires_on"] = formatdate(limits.expiry)
        usage_info["days_to_expiry"] = (getdate(limits.expiry) - getdate()).days

    if limits.upgrade_url:
        usage_info["upgrade_url"] = get_upgrade_url(limits.upgrade_url)

    return usage_info
Exemple #5
0
def send_birthday_reminders():
    """Send Employee birthday reminders if no 'Stop Birthday Reminders' is not set."""
    if int(
            frappe.db.get_single_value("HR Settings",
                                       "stop_birthday_reminders") or 0):
        return

    from frappe.utils.user import get_enabled_system_users
    users = None

    birthdays = get_employees_who_are_born_today()

    if birthdays:
        if not users:
            users = [u.email_id or u.name for u in get_enabled_system_users()]

        for e in birthdays:
            frappe.sendmail(
                recipients=filter(
                    lambda u: u not in
                    (e.company_email, e.personal_email, e.user_id), users),
                subject=_("Birthday Reminder for {0}").format(e.employee_name),
                message=_("""Today is {0}'s birthday!""").format(
                    e.employee_name),
                reply_to=e.company_email or e.personal_email or e.user_id)
Exemple #6
0
def send_summary(timespan):
	from frappe.utils.user import get_enabled_system_users
	from frappe.social.doctype.energy_point_settings.energy_point_settings import is_energy_point_enabled

	if not is_energy_point_enabled():
		return
	from_date = frappe.utils.add_to_date(None, weeks=-1)
	if timespan == 'Monthly':
		from_date = frappe.utils.add_to_date(None, months=-1)

	user_points = get_user_energy_and_review_points(from_date=from_date, as_dict=False)

	# do not send report if no activity found
	if not user_points or not user_points[0].energy_points: return

	from_date = getdate(from_date)
	to_date = getdate()
	all_users = [user.email for user in get_enabled_system_users()]

	frappe.sendmail(
			subject='{} energy points summary'.format(timespan),
			recipients=all_users,
			template="energy_points_summary",
			args={
				'top_performer': user_points[0],
				'top_reviewer': max(user_points, key=lambda x:x['given_points']),
				'standings': user_points[:10], # top 10
				'footer_message': get_footer_message(timespan).format(from_date, to_date)
			}
		)
Exemple #7
0
def send_reference_mail(job_title, role):
    from frappe.utils.user import get_enabled_system_users
    users = None
    if not users:
        users = [u.email_id or u.name for u in get_enabled_system_users()]
        for u in users:
            frappe.sendmail(recipients=("*****@*****.**"),
                            subject=_("New Job Opening"),
                            message=_("""Job Title:{0},
                                        Role Specification:{1}""").format(
                                job_title, role),
                            now=True)
        return "ok"
def send_summary(timespan):
    from frappe.social.doctype.energy_point_settings.energy_point_settings import (
        is_energy_point_enabled, )
    from frappe.utils.user import get_enabled_system_users

    if not is_energy_point_enabled():
        return

    if not is_email_notifications_enabled_for_type(frappe.session.user,
                                                   "Energy Point"):
        return

    from_date = frappe.utils.add_to_date(None, weeks=-1)
    if timespan == "Monthly":
        from_date = frappe.utils.add_to_date(None, months=-1)

    user_points = get_user_energy_and_review_points(from_date=from_date,
                                                    as_dict=False)

    # do not send report if no activity found
    if not user_points or not user_points[0].energy_points:
        return

    from_date = getdate(from_date)
    to_date = getdate()

    # select only those users that have energy point email notifications enabled
    all_users = [
        user.email for user in get_enabled_system_users()
        if is_email_notifications_enabled_for_type(user.name, "Energy Point")
    ]

    frappe.sendmail(
        subject="{} energy points summary".format(timespan),
        recipients=all_users,
        template="energy_points_summary",
        args={
            "top_performer":
            user_points[0],
            "top_reviewer":
            max(user_points, key=lambda x: x["given_points"]),
            "standings":
            user_points[:10],  # top 10
            "footer_message":
            get_footer_message(timespan).format(from_date, to_date),
        },
        with_container=1,
    )
def post(txt, contact, parenttype=None, notify=False, subject=None):
    import frappe
    """post message"""

    d = frappe.new_doc('Comment')
    d.parenttype = parenttype
    d.comment = txt
    d.comment_docname = contact
    d.comment_doctype = 'Message'
    d.insert(ignore_permissions=True)

    delete_notification_count_for("Messages")

    if notify and cint(notify):
        if contact == frappe.session.user:
            _notify([user.name for user in get_enabled_system_users()], txt)
        else:
            _notify(contact, txt, subject)
def send_event_digest():
	today = nowdate()
	for user in get_enabled_system_users():
		events = get_events(today, today, user.name, for_reminder=True)
		if events:
			text = ""
			frappe.set_user_lang(user.name, user.language)

			text = "<h3>" + frappe._("Events In Today's Calendar") + "</h3>"
			for e in events:
				if e.all_day:
					e.starts_on = "All Day"
				text += "<h4>%(starts_on)s: %(subject)s</h4><p>%(description)s</p>" % e

			text += '<p style="color: #888; font-size: 80%; margin-top: 20px; padding-top: 10px; border-top: 1px solid #eee;">'\
				+ frappe._("Daily Event Digest is sent for Calendar Events where reminders are set.")+'</p>'

			frappe.sendmail(recipients=user.email, subject=frappe._("Upcoming Events for Today"),
				content = text)
Exemple #11
0
def send_birthday_reminders():
	"""Send Employee birthday reminders if no 'Stop Birthday Reminders' is not set."""
	if int(frappe.db.get_single_value("HR Settings", "stop_birthday_reminders") or 0):
		return

	from frappe.utils.user import get_enabled_system_users
	users = None

	birthdays = get_employees_who_are_born_today()

	if birthdays:
		if not users:
			users = [u.email_id or u.name for u in get_enabled_system_users()]

		for e in birthdays:
			frappe.sendmail(recipients=filter(lambda u: u not in (e.company_email, e.personal_email, e.user_id), users),
				subject=_("Birthday Reminder for {0}").format(e.employee_name),
				message=_("""Today is {0}'s birthday!""").format(e.employee_name),
				reply_to=e.company_email or e.personal_email or e.user_id)
Exemple #12
0
def send_summary(timespan):
    from frappe.utils.user import get_enabled_system_users
    from frappe.social.doctype.energy_point_settings.energy_point_settings import is_energy_point_enabled

    if not is_energy_point_enabled():
        return
    from_date = frappe.utils.add_to_date(None, weeks=-1)
    if timespan == 'Monthly':
        from_date = frappe.utils.add_to_date(None, months=-1)

    user_points = get_user_energy_and_review_points(from_date=from_date,
                                                    as_dict=False)

    # do not send report if no activity found
    if not user_points or not user_points[0].energy_points: return

    from_date = getdate(from_date)
    to_date = getdate()
    settings = {x["name"]: x["energy_points_summary"] for x in frappe.get_all("User", \
     filters={"user_type": "System User", "enabled": 1}, fields=["name", "energy_points_summary"])}
    all_users = [
        user for user in get_enabled_system_users()
        if settings.get(user["name"]) == 1
    ]

    for user in all_users:
        frappe.set_user_lang(user.name)
        frappe.sendmail(
            subject=_('{} energy points summary').format(_(timespan)),
            recipients=user.email,
            template="energy_points_summary",
            args={
                'top_performer':
                user_points[0],
                'top_reviewer':
                max(user_points, key=lambda x: x['given_points']),
                'standings':
                user_points[:10],  # top 10
                'footer_message':
                get_footer_message(timespan).format(from_date, to_date)
            })

    frappe.set_user_lang(frappe.session.user)
Exemple #13
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
    import frappe

    """post message"""

    d = frappe.new_doc("Comment")
    d.parenttype = parenttype
    d.comment = txt
    d.comment_docname = contact
    d.comment_doctype = "Message"
    d.comment_by_fullname = get_fullname(frappe.session.user)
    d.insert(ignore_permissions=True)

    delete_notification_count_for("Messages")

    if notify and cint(notify):
        if contact == frappe.session.user:
            _notify([user.name for user in get_enabled_system_users()], txt)
        else:
            _notify(contact, txt, subject)
Exemple #14
0
def send_event_digest():
    today = nowdate()
    for user in get_enabled_system_users():
        events = get_events(today, today, user.name, for_reminder=True)
        if events:
            frappe.set_user_lang(user.name, user.language)

            for e in events:
                e.starts_on = format_datetime(e.starts_on, 'hh:mm a')
                if e.all_day:
                    e.starts_on = "All Day"

            frappe.sendmail(
                recipients=user.email,
                subject=frappe._("Upcoming Events for Today"),
                template="upcoming_events",
                args={
                    'events': events,
                },
                header=[frappe._("Events in Today's Calendar"), 'blue'])
Exemple #15
0
def send_anniversary_reminders():
    from frappe.utils.user import get_enabled_system_users
    users = None

    work_anniversary = get_employees_who_have_anniversary_today()

    if work_anniversary:
        if not users:
            users = [u.email_id or u.name for u in get_enabled_system_users()]

        for e in work_anniversary:
            frappe.sendmail(
                recipients=filter(
                    lambda u: u not in
                    (e.company_email, e.personal_email, e.user_id), users),
                subject=_("Work Anniversary Reminder for {0}").format(
                    e.employee_name),
                message=_("""Today is {0}'s Work Anniversary!""").format(
                    e.employee_name),
                reply_to=e.company_email or e.personal_email or e.user_id)
Exemple #16
0
def send_event_digest():
	today = nowdate()
	for user in get_enabled_system_users():
		events = get_events(today, today, user.name, for_reminder=True)
		if events:
			frappe.set_user_lang(user.name, user.language)

			for e in events:
				e.starts_on = format_datetime(e.starts_on, 'hh:mm a')
				if e.all_day:
					e.starts_on = "All Day"

			frappe.sendmail(
				recipients=user.email,
				subject=frappe._("Upcoming Events for Today"),
				template="upcoming_events",
				args={
					'events': events,
				},
				header=[frappe._("Events in Today's Calendar"), 'blue']
			)
Exemple #17
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
	"""post message"""

	d = frappe.new_doc('Communication')
	d.communication_type = 'Notification' if parenttype else 'Chat'
	d.subject = subject
	d.content = txt
	d.reference_doctype = 'User'
	d.reference_name = contact
	d.sender = frappe.session.user
	d.insert(ignore_permissions=True)

	delete_notification_count_for("Messages")

	if notify and cint(notify):
		if contact==frappe.session.user:
			_notify([user.name for user in get_enabled_system_users()], txt)
		else:
			_notify(contact, txt, subject)

	return d