'Question on How @ and # String Trigger Works in Odoo Chatter?

Hope you guys doin well,

I'm curious about how can a certain string like @ and # can trigger a popup of a user and channels in Odoo Chatter & Discuss. This chatter has mail.thread Models related to it but i can't seem to understand how is it possible to create my own custom trigger in chatter?

Is it belong to certain views and not in models? Any help will be appreciated!



Solution 1:[1]

There is another way, and that is using the / or "command" popup. You can add your own item in the popup list and trigger any actions when a user selects your item from the popup.

  1. Inherit from mail.channel
class MailChannel(models.Model):
    _inherit = 'mail.channel'
  1. Add a new method that starts with _define_command_XXXXX. This registers the item in the popup.
def _define_command_sample(self):
    return {'help': _('Here is some sample help')}
  1. Add a new method that starts with _execute_command_XXXXX. This method is executed when the user uses your command.
def _execute_command_sample(self, **kwargs):
    # Send a "temporary" message to the user
    self._send_transient_message(self.env.user.partner_id, f"Hello! You just successfully used the /sample command. You typed {kwargs['body']}.")

Reference: Github where Odoo defines the /lead command

PS: The above is for Odoo V12.0 - V14.0. Odoo V15.0 works a bit different, but you can check this and this for how to do it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 adekock11