From 1ae732c21fe30676be065a6bbee35a07fe32467f Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Thu, 2 Dec 2021 14:29:18 +0100 Subject: [PATCH] [IMP] project: use the rating average instead of customer satisfaction Before this commit, we use the `rating_percentage_satisfaction` field to display the customer satisfaction of the project. The problem is this field is not really a rating average. This field returns the percentage of satisfied ratings over the total number of ratings. This commit changes the using of `rating_percentage_satisfaction` field by the `rating_avg` to only use the rating average to really know if globally the customers are happy of a project or not. task-2671848 Closes #81027 --- addons/project/models/project.py | 6 +-- addons/project/views/project_views.xml | 66 ++++++++------------------ addons/rating/models/rating_mixin.py | 5 +- 3 files changed, 27 insertions(+), 50 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 04ac85b7c88..f1112f94e00 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -739,11 +739,11 @@ class Project(models.Model): if self.user_has_groups('project.group_project_rating'): buttons.append({ 'icon': 'smile-o', - 'text': _('Customer Satisfaction'), - 'number': '%s %%' % (self.rating_percentage_satisfaction), + 'text': _('Satisfaction'), + 'number': f'{self.rating_avg_percentage} %', 'action_type': 'object', 'action': 'action_view_all_rating', - 'show': self.rating_active and self.rating_percentage_satisfaction > -1, + 'show': self.rating_active and self.rating_count > 0, 'sequence': 15, }) if self.user_has_groups('project.group_project_manager'): diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml index 46e8a77ffc3..a9a487232a8 100644 --- a/addons/project/views/project_views.xml +++ b/addons/project/views/project_views.xml @@ -319,33 +319,14 @@ - - - - - diff --git a/addons/rating/models/rating_mixin.py b/addons/rating/models/rating_mixin.py index f6ef3ce06b5..0b74c3e08f4 100644 --- a/addons/rating/models/rating_mixin.py +++ b/addons/rating/models/rating_mixin.py @@ -35,6 +35,8 @@ class RatingParentMixin(models.AbstractModel): rating_count = fields.Integer(string='# Ratings', compute="_compute_rating_percentage_satisfaction", compute_sudo=True) rating_avg = fields.Float('Average Rating', groups='base.group_user', compute='_compute_rating_percentage_satisfaction', compute_sudo=True, search='_search_rating_avg') + rating_avg_percentage = fields.Float('Average Rating (%)', groups='base.group_user', + compute='_compute_rating_percentage_satisfaction', compute_sudo=True) rating_last_value = fields.Float('Rating Last Value', groups='base.group_user', related='rating_ids.rating') @api.depends('rating_ids.rating', 'rating_ids.consumed') @@ -67,6 +69,7 @@ class RatingParentMixin(models.AbstractModel): record.rating_count = rating_count record.rating_percentage_satisfaction = repartition['great'] * 100 / rating_count if rating_count else -1 record.rating_avg = rating_scores_per_parent[record.id] / rating_count if rating_count else 0 + record.rating_avg_percentage = record.rating_avg / 5 def _search_rating_avg(self, operator, value): if operator not in OPERATOR_MAPPING: @@ -93,7 +96,7 @@ class RatingMixin(models.AbstractModel): rating_last_feedback = fields.Text('Rating Last Feedback', groups='base.group_user', related='rating_ids.feedback') rating_last_image = fields.Binary('Rating Last Image', groups='base.group_user', related='rating_ids.rating_image') rating_count = fields.Integer('Rating count', compute="_compute_rating_stats", compute_sudo=True) - rating_avg = fields.Float("Average Rating", + rating_avg = fields.Float("Average Rating", groups='base.group_user', compute='_compute_rating_stats', compute_sudo=True, search='_search_rating_avg') 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")