From 81fe7464f3e633a78d6e8a5f9961a4a3f0c2b24f Mon Sep 17 00:00:00 2001 From: Saurabh Choraria Date: Wed, 17 May 2023 13:03:13 +0000 Subject: [PATCH] [FIX] auth_signup: prevent traceback when mail template is not found When user deletes 'Settings: Unregistered User Reminder' record from 'mail.template' model and when 'Users: Notify About Unregistered Users' scheduled action is executed at that time traceback is generated on the user side as well as in the log. Applying this commit will fix this issue. sentry-4174950325 closes odoo/odoo#129461 X-original-commit: 2a77e72a27ebd2bdbf32995f34d219f51d33dacf Signed-off-by: Achraf Ben Azzouz (abz) --- addons/auth_signup/models/res_users.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/auth_signup/models/res_users.py b/addons/auth_signup/models/res_users.py index 961ff31fe61..ba62303d683 100644 --- a/addons/auth_signup/models/res_users.py +++ b/addons/auth_signup/models/res_users.py @@ -213,6 +213,10 @@ class ResUsers(models.Model): _logger.info("Password reset email sent for user <%s> to <%s>", user.login, user.email) def send_unregistered_user_reminder(self, after_days=5): + email_template = self.env.ref('auth_signup.mail_template_data_unregistered_users', raise_if_not_found=False) + if not email_template: + _logger.warning("Template 'auth_signup.mail_template_data_unregistered_users' was not found. Cannot send reminder notifications.") + return datetime_min = fields.Datetime.today() - relativedelta(days=after_days) datetime_max = datetime_min + relativedelta(hours=23, minutes=59, seconds=59) @@ -230,7 +234,7 @@ class ResUsers(models.Model): # 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 = email_template.with_context(dbname=self._cr.dbname, invited_users=invited_users[user]) template.send_mail(user, email_layout_xmlid='mail.mail_notification_light', force_send=False) @api.model