From d6a0e9db819ea279fabdaa427dca81247fa9608c Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 27 Aug 2018 10:28:48 +0200 Subject: [PATCH] [FIX] mail_bot: do not crash on user with no email When creating a new user, the linked partner may not yet have an email address (not mandatory field). When logging in for the first time, after some time an error comes up "Unable to post message, please configure the sender's email address." While the user should set up an email, this popup coming from no specific action is confusing. With this patch, the message will be posted as the system (which has an email) The user will be warned of having no email when trying to reply. Closes #26601 --- addons/mail_bot/models/mail_bot.py | 2 +- addons/mail_bot/models/mail_channel.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail_bot/models/mail_bot.py b/addons/mail_bot/models/mail_bot.py index 0d311922cc1..6c340193809 100644 --- a/addons/mail_bot/models/mail_bot.py +++ b/addons/mail_bot/models/mail_bot.py @@ -29,7 +29,7 @@ class MailBot(models.AbstractModel): if answer: message_type = values.get('message_type', 'comment') subtype_id = values.get('subtype_id', self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment')) - record.with_context({"mail_create_nosubscribe": True}).message_post(body=answer, author_id=odoobot_id, message_type=message_type, subtype_id=subtype_id) + record.with_context({"mail_create_nosubscribe": True}).sudo().message_post(body=answer, author_id=odoobot_id, message_type=message_type, subtype_id=subtype_id) def _get_answer(self, record, body, values, command=False): # onboarding diff --git a/addons/mail_bot/models/mail_channel.py b/addons/mail_bot/models/mail_channel.py index 80e55fbacae..ded27db6f5e 100644 --- a/addons/mail_bot/models/mail_channel.py +++ b/addons/mail_bot/models/mail_channel.py @@ -36,6 +36,6 @@ class Channel(models.Model): 'name': 'OdooBot' }) message = _("Hello,
Odoo's chat helps employees collaborate efficiently. I'm here to help you discover its features.
Try to send me an emoji :)") - channel.message_post(body=message, author_id=odoobot_id, message_type="comment", subtype="mail.mt_comment") + channel.sudo().message_post(body=message, author_id=odoobot_id, message_type="comment", subtype="mail.mt_comment") self.env.user.odoobot_state = 'onboarding_emoji' return channel