[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
This commit is contained in:
Martin Trigaux
2018-09-03 11:06:59 +02:00
parent 933487eb65
commit d6a0e9db81
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -36,6 +36,6 @@ class Channel(models.Model):
'name': 'OdooBot'
})
message = _("Hello,<br/>Odoo's chat helps employees collaborate efficiently. I'm here to help you discover its features.<br/><b>Try to send me an emoji :)</b>")
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