diff --git a/foundation/erpnext_foundation/doctype/service_provider/service_provider.py b/foundation/erpnext_foundation/doctype/service_provider/service_provider.py index f26ae721..106ec511 100644 --- a/foundation/erpnext_foundation/doctype/service_provider/service_provider.py +++ b/foundation/erpnext_foundation/doctype/service_provider/service_provider.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.website.website_generator import WebsiteGenerator +from frappe.utils import get_datetime class ServiceProvider(WebsiteGenerator): _website = frappe._dict( @@ -21,4 +22,27 @@ class ServiceProvider(WebsiteGenerator): if self.member: context.membership_type = frappe.get_value('Member', self.member, 'membership_type') if context.website and not context.website.startswith('http'): - context.website = 'http://' + context.website \ No newline at end of file + context.website = 'http://' + context.website + + +def send_alert_to_inactive_service_providers(): + for service_provider in frappe.get_all("Service Provider", fields=['email', 'title']): + if get_last_login_diff(service_provider.email) == 80: + send_reminder(service_provider) + +def send_reminder(service_provider_details): + message = frappe.render_template("foundation/templates/emails/inactivity_reminder.md", service_provider_details) + frappe.sendmail(recipients=service_provider_details.email, subject="About account inactivity", message=message) + +def unpublish_service_provider(): + for service_provider in frappe.get_all("Service Provider", fields=['name', 'title']): + if get_last_login_diff(service_provider.email) == 90: + frappe.db.set_value('Service Provider', service_provider.name, 'show_in_website', 0, update_modified=False) + + +def get_last_login_diff(user): + """ + Returns difference between todays date and last login date + """ + last_login = frappe.db.get_value("User", user, ["last_login"]) + return (get_datetime() - get_datetime(last_login)).days \ No newline at end of file diff --git a/foundation/hooks.py b/foundation/hooks.py index 6741c2fd..89a496d4 100644 --- a/foundation/hooks.py +++ b/foundation/hooks.py @@ -116,23 +116,24 @@ portal_menu_items = [ # Scheduled Tasks # --------------- -# scheduler_events = { -# "all": [ -# "foundation.tasks.all" -# ], -# "daily": [ -# "foundation.tasks.daily" -# ], -# "hourly": [ -# "foundation.tasks.hourly" -# ], -# "weekly": [ -# "foundation.tasks.weekly" -# ] -# "monthly": [ -# "foundation.tasks.monthly" -# ] -# } +scheduler_events = { + # "all": [ + # "foundation.tasks.all" + # ], + "daily": [ + "erpnext_foundation.doctype.service_provider.service_provider.send_alert_to_inactive_service_providers", + "erpnext_foundation.doctype.service_provider.service_provider.unpublish_service_provider", + ], + # "hourly": [ + # "foundation.tasks.hourly" + # ], + # "weekly": [ + # "foundation.tasks.weekly" + # ] + # "monthly": [ + # "foundation.tasks.monthly" + # ] +} # Testing # ------- diff --git a/foundation/templates/emails/inactivity_reminder.md b/foundation/templates/emails/inactivity_reminder.md new file mode 100644 index 00000000..5a65c626 --- /dev/null +++ b/foundation/templates/emails/inactivity_reminder.md @@ -0,0 +1,8 @@ +Hi {{ title }}, + +This is a Service Provider listing deactivation alert, +You have not login since last 80 days, if you are not login in next 10 days +erpnext.org might removed your name from a service provider listing. + +Thanks, +ERPNext Foundation \ No newline at end of file