[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>
This commit is contained in:
Parth Choksi
2019-07-10 15:12:02 +00:00
committed by Thibault Delavallée
parent 41334ca2a5
commit d59fd862f1
4 changed files with 90 additions and 0 deletions
+1
View File
@@ -17,6 +17,7 @@ Allow users to sign up and reset their password
],
'data': [
'data/auth_signup_data.xml',
'data/ir_cron_data.xml',
'views/res_config_settings_views.xml',
'views/res_users_views.xml',
'views/auth_signup_login_templates.xml',
@@ -197,6 +197,58 @@
<field name="user_signature" eval="False"/>
</record>
<!-- Email template for reminder of unregistered users -->
<record id="mail_template_data_unregistered_users" model="mail.template">
<field name="name">Auth Signup: Unregistered Users</field>
<field name="model_id" ref="base.model_res_users"/>
<field name="subject">Reminder for unregistered users</field>
<field name="email_from">${object.company_id.partner_id.email_formatted|safe}</field>
<field name="email_to">${object.email_formatted|safe}</field>
<field name="body_html" type="html">
<table border="0" cellpadding="0" cellspacing="0" style="background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;">
<tbody>
<!-- CONTENT -->
<tr>
<td align="center" style="min-width: 590px;">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
% set invited_users = ctx['invited_users']
<td style="text-align : left">
<span style="font-size: 20px; font-weight: bold;">
Pending Invitations
</span><br/><br/>
</td>
<tr><td valign="top" style="font-size: 13px;">
<div>
Dear ${object.name or ''},<br/> <br/>
You added the following user(s) to your database but they haven't registered yet:
<ul>
% for invited_user in invited_users:
<li>${invited_user}</li>
% endfor
</ul>
Follow up with them so they can access your database and start working with you.
<br /><br/>
Have a nice day!<br />
--<br/>The ${object.company_id.name} Team
</div>
</td></tr>
<tr><td style="text-align:center;">
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"/>
</td></tr>
</table>
</td>
</tr>
</tbody>
</table>
</td></tr>
</table>
</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="auto_delete" eval="True"/>
<field name="user_signature" eval="False"/>
</record>
<!-- Email template for new users that used a signup token -->
<record id="mail_template_user_signup_account_created" model="mail.template">
<field name="name">Auth Signup: Odoo Account Created</field>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="ir_cron_auth_signup_send_pending_user_reminder" model="ir.cron">
<field name="name">Users: Notify About Unregistered Users</field>
<field name="model_id" ref="model_res_users"/>
<field name="state">code</field>
<field name="code">model.send_unregistered_user_reminder()</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
</record>
</odoo>
+24
View File
@@ -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)])