コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
4507 ビュー

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
3月 15
5637
0
9月 23
1365
1
7月 16
5850
1
9月 23
1605
0
6月 23
3497