summaryrefslogtreecommitdiff
path: root/addons/auth_signup/models
diff options
context:
space:
mode:
authorParth Choksi <pch@odoo.com>2019-02-21 05:05:40 +0000
committerThibault Delavallée <tde@odoo.com>2019-07-10 15:12:02 +0000
commitd59fd862f1e8dc2663c360194e4e9f1bbf3d7230 (patch)
tree9d445b9923a6026c5ea12fb21a168cdfd11eb454 /addons/auth_signup/models
parent41334ca2a5510c934d94da5b9501c8cf4cd38fb3 (diff)
[IMP] auth_signup : send a reminder for pending users
Purpose of this commit is to send a mail template to the user who invited other user(s) in Odoo. It informs the user about the details of user(s) who have been invited by him but have still not registered after the given days of creation (default set to -> 5days) task-1912449 Closes #31582 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/auth_signup/models')
-rw-r--r--addons/auth_signup/models/res_users.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/addons/auth_signup/models/res_users.py b/addons/auth_signup/models/res_users.py
index f7c35761987..559f92f9fb5 100644
--- a/addons/auth_signup/models/res_users.py
+++ b/addons/auth_signup/models/res_users.py
@@ -4,6 +4,8 @@
import logging
from ast import literal_eval
+from collections import defaultdict
+from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import UserError
@@ -201,6 +203,28 @@ class ResUsers(models.Model):
template.with_context(lang=user.lang).send_mail(user.id, force_send=True, raise_exception=True)
_logger.info("Password reset email sent for user <%s> to <%s>", user.login, user.email)
+ @api.multi
+ def send_unregistered_user_reminder(self, after_days=5):
+ datetime_min = fields.Datetime.today() - relativedelta(days=after_days)
+ datetime_max = datetime_min + relativedelta(hours=23, minutes=59, seconds=59)
+
+ res_users_with_details = self.env['res.users'].search_read([
+ ('share', '=', False),
+ ('create_uid.email', '!=', False),
+ ('create_date', '>=', datetime_min),
+ ('create_date', '<=', datetime_max),
+ ('log_ids', '=', False)], ['create_uid', 'name', 'login'])
+
+ # group by invited by
+ invited_users = defaultdict(list)
+ for user in res_users_with_details:
+ invited_users[user.get('create_uid')[0]].append("%s (%s)" % (user.get('name'), user.get('login')))
+
+ # For sending mail to all the invitors about their invited users
+ for user in invited_users:
+ template = self.env.ref('auth_signup.mail_template_data_unregistered_users').with_context(dbname=self._cr.dbname, invited_users=invited_users[user])
+ template.send_mail(user, notif_layout='mail.mail_notification_light', force_send=False)
+
@api.model
def web_dashboard_create_users(self, emails):
inactive_users = self.search([('state', '=', 'new'), '|', ('login', 'in', emails), ('email', 'in', emails)])