Search code examples
pythonpython-3.xxmlodooodoo-16

Odoo 16 MailThread._message_auto_subscribe_notify() missing 1 required positional argument: 'template'


In Odoo 16, Mail Thread notify called in a custom module.

if approver.user_id:
   self._message_auto_subscribe_notify([approver.user_id.partner_id.id])

But throwing an error,

enter image description here

What will be second argument for template and example of template code?


Solution

  • The second argument should be a notification template external ID as mentioned in the function documentation

    def _message_auto_subscribe_notify(self, partner_ids, template):
        """ Notify new followers, using a template to render the content of the
        notification message. Notifications pushed are done using the standard
        notification mechanism in mail.thread. It is either inbox either email
        depending on the partner state: no user (email, customer), share user
        (email, customer) or classic user (notification_type)
    
        :param partner_ids: IDs of partner to notify;
        :param template: XML ID of template used for the notification;
        """
    

    As an example, check message_user_assigned template

    <!-- Discuss utility templates for notifications -->
    <template id="message_user_assigned">
        <span>Dear<t t-esc="object.user_id.sudo().name"/>,
        </span>
        <br/>
        <br/>
        <span style="margin-top: 8px;">You have been assigned to the
            <t t-esc="model_description or 'document'"/>
            <t t-esc="object.display_name"/>.
        </span>
        <br/>
    </template>