[new] Service Provier Deactivation Alert

This commit is contained in:
Vishal
2017-10-16 17:53:09 +05:30
parent 3a26e551a9
commit c5b77ed311
3 changed files with 51 additions and 18 deletions

View File

@@ -5,6 +5,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.website.website_generator import WebsiteGenerator from frappe.website.website_generator import WebsiteGenerator
from frappe.utils import get_datetime
class ServiceProvider(WebsiteGenerator): class ServiceProvider(WebsiteGenerator):
_website = frappe._dict( _website = frappe._dict(
@@ -22,3 +23,26 @@ class ServiceProvider(WebsiteGenerator):
context.membership_type = frappe.get_value('Member', self.member, 'membership_type') context.membership_type = frappe.get_value('Member', self.member, 'membership_type')
if context.website and not context.website.startswith('http'): if context.website and not context.website.startswith('http'):
context.website = 'http://' + context.website 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

View File

@@ -116,13 +116,14 @@ portal_menu_items = [
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------
# scheduler_events = { scheduler_events = {
# "all": [ # "all": [
# "foundation.tasks.all" # "foundation.tasks.all"
# ], # ],
# "daily": [ "daily": [
# "foundation.tasks.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": [ # "hourly": [
# "foundation.tasks.hourly" # "foundation.tasks.hourly"
# ], # ],
@@ -132,7 +133,7 @@ portal_menu_items = [
# "monthly": [ # "monthly": [
# "foundation.tasks.monthly" # "foundation.tasks.monthly"
# ] # ]
# } }
# Testing # Testing
# ------- # -------

View File

@@ -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