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

I am trying to send notification to user A then user B Approves a task. (but using the odoobot user)

notification_ids = [(0,0,{'res_partner_id':user_id.partner_id.id,'notification_type':'inbox'})]
self.sudo().message_post(subject=summary,body=summary_link,message_type='notification, subtype_xmlid='mail.mt_comment', author_id=odoo_bot_id.partner_id.id, notification_ids=notification_ids)

it was working but now i am going this:

ValueError: Posting a message should be done on a business document. Use message_notify to send a notification to an user.

if self._name == 'mail.thread' or not self.id or message_type == 'user_notification':
            raise ValueError(_('Posting a message should be done on a business document. Use message_notify to send a notification to an user.'))

what does not self.id mean

according to this I should use

message_notify_ids = [user_id.partner_id.id]
record.sudo().message_notify(partner_ids=message_notify_ids, parent_id=odoo_bot_id.partner_id.id, author_id=odoo_bot_id.partner_id.id,  body=summary_link, subject=summary)

this shows the popup notification but does not show in the index so the user can navigate to the task


stackoverflow

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

When I logged self.id I got NewId_26404 which is a temp id since the function was run in a compute.

Fix

record = record if isinstance(record.id,int) else record._origin

Note: discarding the changes did send the notification in my case, so it maybe better to add it in write function

I am open to suggestions if there is a better solution thank.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 23
2583
2
thg 8 23
2276
2
thg 8 23
6624
1
thg 12 23
4011
1
thg 7 23
2874