Search code examples
pythonodoomessage

How to set 'email' in author_id inherit mail.thread on Odoo


I inherit mail.thread on Odoo12

_inherit = ['mail.thread', 'mail.activity.mixin']

and publish a message:

msg = 'message test.'
self.message_post(body=msg, email_from='Otro <[email protected]>', subtype='mail.mt_comment',)

image

These messages are added with the administrator user. How can I place the mail of the external user who sends the message in the field author_id?


Solution

  • Try out self.message_post(body=msg, email_from='Otro <[email protected]>', subtype='mail.mt_comment', author_id=False)

    author_id=False will tell Odoo to use the email_from as author.

    I've found that "trick" here:

        author_id = kwargs.get('author_id')
        if author_id is None:  # keep False values
            author_id = self.env['mail.message']._get_default_author().id
    

    The semi-valuable comment # keep False values solved the big secret ;-)

    With None the user of the current environment would be used.