[FIX] project, rating: use rating last update to compute satisfaction percentage

The function _compute_parent_rating_percentage_satisfaction used the creation
date of the rating to compute the percentage.
However when a client give a new rating, it updates the old one.
As a result it doesn't give the recent satisfaction percentage,
but the satisfaction percentage of recently created tickets.
In other words recently angry clients from old projects would not appear.

Similarly this method is somewhat reimplemented directly in SQL in the rating
route, which happens to be in the project controller.

opw 1921486

closes odoo/odoo#30752
This commit is contained in:
Nans Lefebvre
2019-02-01 09:01:27 +00:00
parent 220644785c
commit 9d1b07f97b
2 changed files with 6 additions and 6 deletions
+5 -5
View File
@@ -23,10 +23,10 @@ class RatingProject(http.Controller):
rating,
COUNT(rating) as rating_count,
CASE
WHEN now()::date - create_date::date BETWEEN 0 AND 6 Then 'days_06'
WHEN now()::date - create_date::date BETWEEN 0 AND 15 Then 'days_15'
WHEN now()::date - create_date::date BETWEEN 0 AND 30 Then 'days_30'
WHEN now()::date - create_date::date BETWEEN 0 AND 90 Then 'days_90'
WHEN now()::date - write_date::date BETWEEN 0 AND 6 Then 'days_06'
WHEN now()::date - write_date::date BETWEEN 0 AND 15 Then 'days_15'
WHEN now()::date - write_date::date BETWEEN 0 AND 30 Then 'days_30'
WHEN now()::date - write_date::date BETWEEN 0 AND 90 Then 'days_90'
END AS period
FROM
rating_rating
@@ -35,7 +35,7 @@ class RatingProject(http.Controller):
AND parent_res_id = %s
AND res_model = 'project.task'
AND rated_partner_id IS NOT NULL
AND create_date >= current_date - interval '90' day
AND write_date >= current_date - interval '90' day
AND rating IN (1,5,10)
GROUP BY
rated_partner_id, rating, period
+1 -1
View File
@@ -360,7 +360,7 @@ class RatingMixin(models.AbstractModel):
# build domain and fetch data
domain = [('parent_res_model', '=', parent_records._name), ('parent_res_id', 'in', parent_records.ids), ('rating', '>=', 1), ('consumed', '=', True)]
if rating_satisfaction_days:
domain += [('create_date', '>=', fields.Datetime.to_string(fields.datetime.now() - timedelta(days=rating_satisfaction_days)))]
domain += [('write_date', '>=', fields.Datetime.to_string(fields.datetime.now() - timedelta(days=rating_satisfaction_days)))]
data = self.env['rating.rating'].read_group(domain, ['parent_res_id', 'rating'], ['parent_res_id', 'rating'], lazy=False)
# get repartition of grades per parent id