769eafb483
Flectra is Forked from Odoo v11 commit : (6135e82d73
)
20 lines
789 B
Python
20 lines
789 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=True)
|
|
|
|
@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)
|