Skip to content
Permalink
Browse files

[IMP] auth_signup : Send a reminder to the user who added another use…

…r in Odoo

Purpose of the task is to sent a mail template to the user who added another user(s) in Odoo.
It informs user about the details of users who have been invited by him
but have not registered after 5 days of creation.

Task ID : 1912449
Closes #31582
  • Loading branch information...
pch-odoo committed Feb 21, 2019
1 parent 6af61e8 commit ce5d8a5506dbdf3402592490ffae3310b319c4f1
@@ -17,6 +17,7 @@
],
'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',
@@ -195,6 +195,98 @@
<field name="user_signature" eval="False"/>
</record>

<!-- Email template for reminder of unregistered users -->
<record id="unregistered_user_reminder" 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.name|safe}" &lt;${object.company_id.email or user.email|safe}&gt;</field>
<field name="email_to">${object.email|safe}</field>
<field name="body_html" type="html">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; 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>
<!-- HEADER -->
<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;">
<tr><td valign="middle">
<span style="font-size: 10px;">Database: ${'dbname' in ctx and ctx['dbname'] or ''}</span><br/>
<span style="font-size: 20px; font-weight: bold;">
Pending invitations
</span>
</td><td valign="middle" align="right">
<img src="/logo.png?company=${object.company_id.id}" style="padding: 0px; margin: 0px; height: auto; width: 80px;" alt="${object.company_id.name}"/>
</td></tr>
<tr><td colspan="2" 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>
<!-- 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']
<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>
<!-- FOOTER -->
<tr>
<td align="center" style="min-width: 590px;">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; font-size: 11px; padding: 0px 8px 0px 8px; border-collapse:separate;">
<tr><td valign="middle" align="left">
${object.company_id.name}
</td></tr>
<tr><td valign="middle" align="left" style="opacity: 0.7;">
${object.company_id.phone}
% if object.company_id.email
| <a href="'mailto:%s' % ${object.company_id.email}" style="text-decoration:none; color: #454748;">${object.company_id.email}</a>
% endif
% if object.company_id.website
| <a href="'%s' % ${object.company_id.website}" style="text-decoration:none; color: #454748;">${object.company_id.website}</a>
% endif
</td></tr>
</table>
</td>
</tr>
</tbody>
</table>
</td></tr>
<!-- POWERED BY -->
<tr><td align="center" style="min-width: 590px;">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: #F1F1F1; color: #454748; padding: 8px; border-collapse:separate;">
<tr><td style="text-align: center; font-size: 13px;">
Powered by <a target="_blank" href="https://www.odoo.com?utm_source=db&amp;utm_medium=portalinvite" style="color: #875A7B;">Odoo</a>
</td></tr>
</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>
@@ -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">Mail: 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(after_days=5)</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>
@@ -8,8 +8,10 @@
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.osv import expression
from odoo.tools import date_utils
from odoo.tools.misc import ustr

from collections import defaultdict
from odoo.addons.base.models.ir_mail_server import MailDeliveryException
from odoo.addons.auth_signup.models.res_partner import SignupError, now

@@ -201,6 +203,28 @@ def action_reset_password(self):
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 = date_utils.start_of(date_utils.subtract(fields.Datetime.today(), days=after_days), 'day')
datetime_max = date_utils.end_of(date_utils.subtract(fields.Datetime.today(), days=after_days), 'day')

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.unregistered_user_reminder').with_context(dbname=self._cr.dbname, invited_users=invited_users[user])
template.send_mail(user, force_send=True)

@api.model
def web_dashboard_create_users(self, emails):
inactive_users = self.search([('state', '=', 'new'), '|', ('login', 'in', emails), ('email', 'in', emails)])

0 comments on commit ce5d8a5

Please sign in to comment.
You can’t perform that action at this time.