Commit f727e9d9b6 made the rating field
of mail.message non-stored for performance reasons.
When the rating is activated on the website, it adds the possibility to filter
product reviews by rating (1 to 5 stars).
It does so by searching the messages that have a given rating value.
However the osv complains that you can't search on a non-stored field.
As a result, instead of displaying messages filtered by ratings,
it would always display all of them.
We add a search='_search_rating_value' on the field to allow that field to be
searched anyway.
opw 1931038
closes odoo/odoo#30499
24 lines
950 B
Python
24 lines
950 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class MailMessage(models.Model):
|
|
_inherit = 'mail.message'
|
|
|
|
rating_ids = fields.One2many('rating.rating', 'message_id', string='Related ratings')
|
|
rating_value = fields.Float("Rating Value", compute='_compute_rating_value', store=False, search='_search_rating_value')
|
|
|
|
@api.multi
|
|
@api.depends('rating_ids', 'rating_ids.rating')
|
|
def _compute_rating_value(self):
|
|
ratings = self.env['rating.rating'].search([('message_id', 'in', self.ids), ('consumed', '=', True)], order='create_date DESC')
|
|
mapping = dict((r.message_id.id, r.rating) for r in ratings)
|
|
for message in self:
|
|
message.rating_value = mapping.get(message.id, 0.0)
|
|
|
|
@api.multi
|
|
def _search_rating_value(self, operator, operand):
|
|
return [('rating_ids.rating', operator, operand)]
|