Purpose of this commit is to globally improve code performance by limiting search impact by * adding limits when only first found record id used; * avoid unnecessary searches when record set can be filtered instead; * using cache when accessing ir.model; Task-2638444 PR odoo/odoo#76005 Co-Authored-By: Thibault Delavallée <tde@odoo.com> Co-Authored-By: Victor Feyens <vfe@odoo.com>
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class MailThread(models.AbstractModel):
|
|
_inherit = 'mail.thread'
|
|
|
|
@api.returns('mail.message', lambda value: value.id)
|
|
def message_post(self, **kwargs):
|
|
rating_value = kwargs.pop('rating_value', False)
|
|
rating_feedback = kwargs.pop('rating_feedback', False)
|
|
message = super(MailThread, self).message_post(**kwargs)
|
|
|
|
# create rating.rating record linked to given rating_value. Using sudo as portal users may have
|
|
# rights to create messages and therefore ratings (security should be checked beforehand)
|
|
if rating_value:
|
|
self.env['rating.rating'].sudo().create({
|
|
'rating': float(rating_value) if rating_value is not None else False,
|
|
'feedback': rating_feedback,
|
|
'res_model_id': self.env['ir.model']._get_id(self._name),
|
|
'res_id': self.id,
|
|
'message_id': message.id,
|
|
'consumed': True,
|
|
'partner_id': self.env.user.partner_id.id,
|
|
})
|
|
return message
|