Merge pull request #75 from erpnext/service_provider_remainder

[new] Service Provider Deactivation Alert
This commit is contained in:
Vishal Dhayagude
2017-10-25 16:30:33 +05:30
committed by GitHub
3 changed files with 62 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(
@@ -21,4 +22,37 @@ class ServiceProvider(WebsiteGenerator):
if self.member: if self.member:
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=['email', '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 publish_service_provider():
"""
If Service provider is unpublished and login then automatically enabled name in service provider listing
"""
for service_provider in frappe.get_all("Service Provider", fields=['email','name', 'title', 'show_in_website']):
if get_last_login_diff(service_provider.email) == 0 and service_provider.show_in_website == 0:
frappe.db.set_value('Service Provider', service_provider.name, 'show_in_website', 1, 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"])
for x in xrange(1,10):
print((get_datetime() - get_datetime(last_login)).days, user)
return (get_datetime() - get_datetime(last_login)).days

View File

@@ -116,23 +116,25 @@ portal_menu_items = [
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------
# scheduler_events = { scheduler_events = {
# "all": [ # "all": [
# "foundation.tasks.all" # "foundation.tasks.all"
# ], # ],
# "daily": [ "daily": [
# "foundation.tasks.daily" "foundation.erpnext_foundation.doctype.service_provider.service_provider.send_alert_to_inactive_service_providers",
# ], "foundation.erpnext_foundation.doctype.service_provider.service_provider.unpublish_service_provider",
# "hourly": [ "foundation.erpnext_foundation.doctype.service_provider.service_provider.publish_service_provider",
# "foundation.tasks.hourly" ],
# ], # "hourly": [
# "weekly": [ # "foundation.tasks.hourly"
# "foundation.tasks.weekly" # ],
# ] # "weekly": [
# "monthly": [ # "foundation.tasks.weekly"
# "foundation.tasks.monthly" # ]
# ] # "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 will be removed your name from a service provider listing.
Thanks,
ERPNext Foundation