Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
609 Lượt xem

I want an email to automatically appear in the chatter of a module after it was sent. I create the email by overriding 

def _send_mail(self, answer):

res = super()._send_mail(answer)

email_values = {

"auto_delete": False,

"model": "survey.survey",

"res_id": self.survey_id.id,

}


res.update(email_values)

return res

How can I achieve the desired result? After the email was sent, it doesn't appear in the chatter of the survey. Thanks in advance!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hii,

You're overriding _send_mail() and returning res, which may be an email template or dict of values, but you're not actually calling message_post, nor guaranteeing the email is sent with the right linkage to log in the chatter.

Here’s how to ensure the email appears in the chatter of the related survey.survey record:

from odoo import models class YourModel(models.Model): _inherit = 'your.model' def _send_mail(self, answer): res = super()._send_mail(answer) survey = self.survey_id # Prepare email values email_values = { 'auto_delete': False, 'model': 'survey.survey', 'res_id': survey.id, } # If res is a mail.template: if isinstance(res, dict): res.update(email_values) elif hasattr(res, 'write'): res.write(email_values) # Optional: Post a message to chatter manually (if not posted automatically) survey.message_post( body="An email was sent to the user.", message_type="notification", subtype_xmlid="mail.mt_note", ) return res

i hope it is use full

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 24
1705
3
thg 10 18
7682
0
thg 12 16
3969
2
thg 2 25
3114
2
thg 2 25
1589