[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) <tde@openerp.com>
This commit is contained in:
duongnguyen-viindoo
2024-03-17 00:35:02 +00:00
committed by Thibault Delavallée
parent c4bc200b47
commit c3fe38362c
+2 -1
View File
@@ -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