Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
3 Respostas
4509 Visualizações

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!

Avatar
Cancelar
Autor Melhor resposta

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')

Avatar
Cancelar
Melhor resposta

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)

Avatar
Cancelar
Melhor resposta

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

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
mar. 15
5637
0
set. 23
1365
1
jul. 16
5854
1
set. 23
1606
0
jun. 23
3498