Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
4517 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 15
5639
0
sep. 23
1368
1
jul. 16
5860
1
sep. 23
1611
0
jun. 23
3504