diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml index a9a487232a8..79a49f69b07 100644 --- a/addons/project/views/project_views.xml +++ b/addons/project/views/project_views.xml @@ -849,13 +849,14 @@ + diff --git a/addons/rating/models/rating.py b/addons/rating/models/rating.py index 1a9eb410d6a..a10c839595d 100644 --- a/addons/rating/models/rating.py +++ b/addons/rating/models/rating.py @@ -10,6 +10,12 @@ from odoo.modules.module import get_resource_path RATING_LIMIT_SATISFIED = 4 RATING_LIMIT_OK = 3 RATING_LIMIT_MIN = 1 +RATING_TEXT = [ + ('top', 'Satisfied'), + ('ok', 'Okay'), + ('ko', 'Dissatisfied'), + ('none', 'No Rating yet'), +] class Rating(models.Model): @@ -55,11 +61,7 @@ class Rating(models.Model): partner_id = fields.Many2one('res.partner', string='Customer', help="Author of the rating") rating = fields.Float(string="Rating Value", group_operator="avg", default=0, help="Rating value: 0=Unhappy, 5=Happy") rating_image = fields.Binary('Image', compute='_compute_rating_image') - rating_text = fields.Selection([ - ('top', 'Satisfied'), - ('ok', 'Okay'), - ('ko', 'Dissatisfied'), - ('none', 'No Rating yet')], string='Rating', store=True, compute='_compute_rating_text', readonly=True) + rating_text = fields.Selection(RATING_TEXT, string='Rating', store=True, compute='_compute_rating_text', readonly=True) feedback = fields.Text('Comment', help="Reason of the rating") message_id = fields.Many2one( 'mail.message', string="Message", diff --git a/addons/rating/models/rating_mixin.py b/addons/rating/models/rating_mixin.py index 0b74c3e08f4..13cbe90e000 100644 --- a/addons/rating/models/rating_mixin.py +++ b/addons/rating/models/rating_mixin.py @@ -5,7 +5,7 @@ from collections import defaultdict from datetime import timedelta from odoo import api, fields, models, tools -from odoo.addons.rating.models.rating import RATING_LIMIT_SATISFIED, RATING_LIMIT_OK, RATING_LIMIT_MIN +from odoo.addons.rating.models.rating import RATING_LIMIT_SATISFIED, RATING_LIMIT_OK, RATING_LIMIT_MIN, RATING_TEXT from odoo.osv import expression from odoo.tools.float_utils import float_compare @@ -17,6 +17,9 @@ OPERATOR_MAPPING = { '>': operator.gt, '>=': operator.ge, } +RATING_AVG_TOP = 3.66 +RATING_AVG_OK = 2.33 +RATING_AVG_MIN = RATING_LIMIT_MIN class RatingParentMixin(models.AbstractModel): @@ -98,6 +101,8 @@ class RatingMixin(models.AbstractModel): rating_count = fields.Integer('Rating count', compute="_compute_rating_stats", compute_sudo=True) rating_avg = fields.Float("Average Rating", groups='base.group_user', compute='_compute_rating_stats', compute_sudo=True, search='_search_rating_avg') + rating_avg_text = fields.Selection(RATING_TEXT, groups='base.group_user', + compute='_compute_rating_avg_text', compute_sudo=True) rating_percentage_satisfaction = fields.Float("Rating Satisfaction", compute='_compute_rating_satisfaction', compute_sudo=True) rating_last_text = fields.Selection(string="Rating Text", groups='base.group_user', related="rating_ids.rating_text") @@ -130,6 +135,18 @@ class RatingMixin(models.AbstractModel): ] return [('id', 'in', res_ids)] + @api.depends('rating_avg') + def _compute_rating_avg_text(self): + for record in self: + if float_compare(record.rating_avg, RATING_AVG_TOP, 2) >= 0: + record.rating_avg_text = 'top' + elif float_compare(record.rating_avg, RATING_AVG_OK, 2) >= 0: + record.rating_avg_text = 'ok' + elif float_compare(record.rating_avg, RATING_AVG_MIN, 2) >= 0: + record.rating_avg_text = 'ko' + else: + record.rating_avg_text = 'none' + @api.depends('rating_ids.res_id', 'rating_ids.rating') def _compute_rating_satisfaction(self): """ Compute the rating satisfaction percentage, this is done separately from rating_count and rating_avg