Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
4513 Переглядів

Hi all,

Programatically we are sending a mail message, however when we send the message it does not show up in the record's chatter / history?

.send_mail(item.id, force_send=True, raise_exception=True)

With the above I would expect this mail message to be in the item.id's chatter. However it does not show up. I have also tried the below with no success:

.send_mail(item.id, force_send=True, raise_exception=True, email_values={'model': 'stock.picking', 'res_id': item.id})

Thanks for any help!

Аватар
Відмінити
Автор Найкраща відповідь

I resolved this by posting the message myself through code - add this below where you are sending the mail template.

item.with_context(force_send=True).message_post_with_template(YOURTEMPLATEID, email_layout_xmlid='mail.mail_notification_light')

Аватар
Відмінити
Найкраща відповідь

I can not make the sample code provided to work on my end but I found a work around which might be helpful for others who like me just use Server Actions in Odoo Online. The following code will sent the email, then retreive the email sent and post it in the chatter so that it would post the completed template. 


If someone has a better way please let us know 

for applicant in records:

    email_template = env['mail.template'].browse(68)

    if email_template:

        # Send the email

        res = email_template.send_mail(applicant.id, force_send=False)

        # Extract the generated email body from mail.mail

        mail_record = env['mail.mail'].search([

            ('mail_message_id', '=', res)

        ], order="id desc", limit=1)


        if mail_record and mail_record.body_html:

            # Post the rendered email content in the chatter

            applicant.message_post(body="test" + mail_record.body_html)

Аватар
Відмінити
Найкраща відповідь

Hi,

In odoo there is a default function to post messages in chatter. Here is a demo for message_post().You can use this code inside your function.

def your_func(self):
body = 'Your text goes here'
self.message_post(body=body, subject='Your Subject')

Hope it helps

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
бер. 15
5639
0
вер. 23
1367
1
лип. 16
5858
1
вер. 23
1610
0
черв. 23
3503