[FIX] mail_bot: Merge OdooBot and System
As we want that operations done by the system such as reordering rules be done by him.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="partner_odoobot" model="res.partner">
|
||||
<record id="base.partner_root" model="res.partner">
|
||||
<field name="name">OdooBot</field>
|
||||
<field name="customer" eval="False"/>
|
||||
<field name="email">OdooBot</field>
|
||||
<field name="active" eval="False"/>
|
||||
<field name="email">odoobot@example.com</field>
|
||||
<field name="image" type="base64" file="mail/static/src/img/odoobot.png"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
@@ -21,7 +21,7 @@ class MailBot(models.AbstractModel):
|
||||
:param values: msg_values of the message_post or other values needed by logic
|
||||
: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("mail_bot.partner_odoobot")
|
||||
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:
|
||||
return
|
||||
if self._is_bot_pinged(values) or self._is_bot_in_private_channel(record):
|
||||
@@ -213,11 +213,11 @@ class MailBot(models.AbstractModel):
|
||||
return False
|
||||
|
||||
def _is_bot_pinged(self, values):
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("mail_bot.partner_odoobot")
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
return (4, odoobot_id) in values.get('partner_ids', [])
|
||||
|
||||
def _is_bot_in_private_channel(self, record):
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("mail_bot.partner_odoobot")
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
if record._name == 'mail.channel' and record.channel_type == 'chat':
|
||||
return odoobot_id in record.with_context(active_test=False).channel_partner_ids.ids
|
||||
return False
|
||||
|
||||
@@ -14,7 +14,7 @@ class Channel(models.Model):
|
||||
@api.model
|
||||
def channel_fetch_listeners(self, uuid):
|
||||
""" Return the id, name and email of partners listening to the given channel """
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("mail_bot.partner_odoobot")
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
self._cr.execute("""
|
||||
SELECT P.id, P.name, P.email
|
||||
FROM mail_channel_partner CP
|
||||
@@ -27,7 +27,7 @@ class Channel(models.Model):
|
||||
def init_odoobot(self):
|
||||
if self.env.user.odoobot_state == 'not_initialized':
|
||||
partner = self.env.user.partner_id
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("mail_bot.partner_odoobot")
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
channel = self.with_context({"mail_create_nosubscribe": True}).create({
|
||||
'channel_partner_ids': [(4, partner.id), (4, odoobot_id)],
|
||||
'public': 'private',
|
||||
|
||||
@@ -8,7 +8,7 @@ class Partner(models.Model):
|
||||
def _compute_im_status(self):
|
||||
#we asume that mail_bot _compute_im_status will be executed after bus _compute_im_status
|
||||
super(Partner, self)._compute_im_status()
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("mail_bot.partner_odoobot")
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
for partner in self:
|
||||
if partner.id == odoobot_id:
|
||||
partner.im_status = 'bot'
|
||||
@@ -18,7 +18,7 @@ class Partner(models.Model):
|
||||
#add odoobot in mention suggestion when pinging in mail_thread
|
||||
[users, partners] = super(Partner, self).get_mention_suggestions(search, limit=limit)
|
||||
if len(partners) + len(users) < limit and "odoobot".startswith(search.lower()):
|
||||
odoobot = self.env.ref("mail_bot.partner_odoobot")
|
||||
odoobot = self.env.ref("base.partner_root")
|
||||
if not any([elem['id'] == odoobot.id for elem in partners]):
|
||||
if odoobot:
|
||||
partners.append({'id': odoobot.id, 'name': odoobot.name, 'email': odoobot.email})
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOdoobot, self).setUp()
|
||||
self.odoobot = self.env.ref("mail_bot.partner_odoobot")
|
||||
self.odoobot = self.env.ref("base.partner_root")
|
||||
self.message_post_default_kwargs = {
|
||||
'body': '',
|
||||
'attachment_ids': [],
|
||||
|
||||
Reference in New Issue
Block a user