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

I would like to inform a User after a specific event. Therefore I created an automatic action rule in Odoo. The action will be triggered right, but the user doesn't get a message in his inbox nor will he be notified. This is the code:

partner_id = user.partner_id.id
partner = env['res.partner'].sudo().browse(partner_id)
partner.message_post(
​body='A new email has arrived. Please check your inbox.',
​author_id=partner_id,
)

In Odoo messages, I see that the message is created. PartnerId is correct. Also some logs shows me that the action rule is working. But the user doesn't get the message in his inbox. It would be also great, that the user get's notfied with an addtional count on the 'notification' bubble on the top of the screen.

Does anyone has experience how notification and messaging are working within Odoo?

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

Hi,

Try,

user = self.env['res.users'].browse(748)  # User to send notification
display_msg = """
Hello,


Your Message Goes Here.

"""

post = self.env.user.partner_id.message_post(body=display_msg, message_type='notification', subtype='mail.mt_comment',
author_id=self.env.user.partner_id.id)

if post:
notification_ids = [(0, 0, {'res_partner_id': user.partner_id.id, 'mail_message_id': post.id}) for user in
user]
post.write({'notification_ids': notification_ids})



Hope it helps,
Kiran K

Ảnh đại diện
Huỷ bỏ
Tác giả

Hi Kiran, thanks for your reply. Sadly it is not working. I get the error 'can't adapt type 'mail.message''

Can you share the code? The issue here is that you are passing a recordset instead of an id.

Tác giả

Hi Kiran, this is the code:

user = env['res.users'].sudo().browse(sales_person)
partner = user.partner_id
partner_id = partner.id

if partner_id:
#log('User: ' + str(user) + ' ,' + 'partner: ' + str(partner) + ' ,' + 'partner_id: ' + str(partner_id))
subject = contact.name
display_msg = 'A new email has arrived. Please check your inbox.'
post = env['mail.message'].sudo().create({
'model': record._name,
'res_id': record.id,
'message_type': 'notification',
'subject': subject,
'subtype_id': env.ref('mail.mt_comment').id,
'body': display_msg,
'author_id': partner_id,
})
log(post)
if post:
notification_ids = [(0, 0, {'res_partner_id': partner_id, 'mail_message_id': post.id}) for user in user]
post.write({'notification_ids': notification_ids})

Error Message: "Error occurred while searching for contact: can't adapt type 'mail.message'"

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 23
3499
1
thg 2 24
1091
1
thg 8 24
3556
0
thg 1 24
1593
1
thg 1 24
5701