From c5b77ed311babe9dd8e41a57010a22c5e870d353 Mon Sep 17 00:00:00 2001 From: Vishal Date: Mon, 16 Oct 2017 17:53:09 +0530 Subject: [PATCH 1/4] [new] Service Provier Deactivation Alert --- .../service_provider/service_provider.py | 26 +++++++++++++- foundation/hooks.py | 35 ++++++++++--------- .../templates/emails/inactivity_reminder.md | 8 +++++ 3 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 foundation/templates/emails/inactivity_reminder.md 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 From bd0e3039de1666436afc3ac28ba2d7c2d6dd9dd5 Mon Sep 17 00:00:00 2001 From: Vishal Date: Mon, 16 Oct 2017 20:09:29 +0530 Subject: [PATCH 2/4] [fix] Typo in Remainder Message --- foundation/templates/emails/inactivity_reminder.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/foundation/templates/emails/inactivity_reminder.md b/foundation/templates/emails/inactivity_reminder.md index 5a65c626..cf019679 100644 --- a/foundation/templates/emails/inactivity_reminder.md +++ b/foundation/templates/emails/inactivity_reminder.md @@ -1,8 +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. +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 \ No newline at end of file From 42142fbb1c212f533166dbb560ecdfe72e0e5746 Mon Sep 17 00:00:00 2001 From: Vishal Date: Wed, 25 Oct 2017 13:49:28 +0530 Subject: [PATCH 3/4] [fix] Update scheduler path in hooks.py --- foundation/hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/foundation/hooks.py b/foundation/hooks.py index 89a496d4..73dc49b4 100644 --- a/foundation/hooks.py +++ b/foundation/hooks.py @@ -121,8 +121,8 @@ scheduler_events = { # "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", + "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.tasks.hourly" From 8f701dd808a58e2212fa59fce632adf4ffe8bcce Mon Sep 17 00:00:00 2001 From: Vishal Date: Wed, 25 Oct 2017 16:28:19 +0530 Subject: [PATCH 4/4] [new] If disabled service provider login then automatically enabled in listing --- .../doctype/service_provider/service_provider.py | 12 +++++++++++- foundation/hooks.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/foundation/erpnext_foundation/doctype/service_provider/service_provider.py b/foundation/erpnext_foundation/doctype/service_provider/service_provider.py index 106ec511..280c983e 100644 --- a/foundation/erpnext_foundation/doctype/service_provider/service_provider.py +++ b/foundation/erpnext_foundation/doctype/service_provider/service_provider.py @@ -35,14 +35,24 @@ def send_reminder(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']): + 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 \ No newline at end of file diff --git a/foundation/hooks.py b/foundation/hooks.py index 73dc49b4..bb3156d0 100644 --- a/foundation/hooks.py +++ b/foundation/hooks.py @@ -123,6 +123,7 @@ scheduler_events = { "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", + "foundation.erpnext_foundation.doctype.service_provider.service_provider.publish_service_provider", ], # "hourly": [ # "foundation.tasks.hourly"