[FIX] mail_bot: fix mail bot onboarding tour display

Before this PR, the mail bot would have answered to every incoming
messages including system notifications. Answering to system
notifications makes no sense and leads to the answer being formatted
as a notification since the mail bot copies the message type of the
message being answered.

This PR fixes the issue by preventing the mail bot from answering
anything else than comments.

task-3044856

closes odoo/odoo#104636

X-original-commit: bb76e083d5adcc955967680c46b9cf2e39402783
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
tsm-odoo
2022-10-31 18:52:59 +01:00
parent 06f92770f9
commit 87147c935f
+3 -3
View File
@@ -22,14 +22,14 @@ class MailBot(models.AbstractModel):
:param command: the name of the called command if the logic is not triggered by a message_post
"""
odoobot_id = self.env['ir.model.data']._xmlid_to_res_id("base.partner_root")
if len(record) != 1 or values.get("author_id") == odoobot_id:
if len(record) != 1 or values.get("author_id") == odoobot_id or values.get("message_type") != "comment" and not command:
return
if self._is_bot_pinged(values) or self._is_bot_in_private_channel(record):
body = values.get("body", "").replace(u'\xa0', u' ').strip().lower().strip(".!")
answer = self._get_answer(record, body, values, command)
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'))
message_type = 'comment'
subtype_id = self.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment')
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):