From c3fe38362c8edc26c720698601d0ffa2d971d671 Mon Sep 17 00:00:00 2001 From: duongnguyen-viindoo Date: Fri, 23 Feb 2024 10:06:07 +0700 Subject: [PATCH] [FIX] mail: user_id field of model might not have type many2one -Step to reproduce: any custom model that inherit from mail.thread then define a field user_id but with type is char and boom error happen at method '_message_get_suggested_recipients' because it always expect 'user_id' to be a many2one field closes odoo/odoo#157942 -solution: need to check the type of 'user_id' also X-original-commit: 4aaab353da1c1ddde63f2aa1232394c0b4dd6f68 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_thread.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 180d6667c71..c67313a477f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1838,7 +1838,8 @@ class MailThread(models.AbstractModel): """ Returns suggested recipients for ids. Those are a list of tuple (partner_id, partner_name, reason, default_create_value), to be managed by Chatter. """ result = dict((res_id, []) for res_id in self.ids) - if 'user_id' in self._fields: + user_field = self._fields.get('user_id') + if user_field and user_field.type == 'many2one' and user_field.comodel_name == 'res.users': for obj in self.sudo(): # SUPERUSER because of a read on res.users that would crash otherwise if not obj.user_id or not obj.user_id.partner_id: continue