summaryrefslogtreecommitdiff
path: root/addons/project
diff options
context:
space:
mode:
authorRomainLibert <rli@odoo.com>2018-01-22 12:08:56 +0100
committerRomainLibert <rli@odoo.com>2018-02-23 16:13:03 +0100
commit12b580c953a762e40fb4a07a3fe5be3d119fa406 (patch)
treecf0477aa42c68e7149eb6fdbde60a0f37db25a5c /addons/project
parentffbee8882e6b1a4145630253432dccd675233d10 (diff)
[IMP] rating: Parent document name update
For objects inherting from rating.mixin, when their parent model change (e.i.: task from a project to another), the "Parent document name" does not change. The rating is still considered belonging to the old parent object (rating stat of project is not correct). Change the rating API. In rating mixin, instead of having 2 methods returning parent id and parent model (rating_get_parent_id and rating_get_parent_model_name), we should have one method returning the 'parent relation field' (inevitably m2o field). Then we can deduce its parent_res_id/parent_res_model, and check this parent field is in values of write to trigger the recompute of parent_res_name. Also, add "ondelete=cascade" on parent_res_model_id Impacted modules: project, rating, helpdesk, livechat
Diffstat (limited to 'addons/project')
-rw-r--r--addons/project/models/project.py7
-rw-r--r--addons/project/tests/test_project_flow.py72
2 files changed, 74 insertions, 5 deletions
diff --git a/addons/project/models/project.py b/addons/project/models/project.py
index ff9181938bc..4f43b0ae616 100644
--- a/addons/project/models/project.py
+++ b/addons/project/models/project.py
@@ -1044,11 +1044,8 @@ class Task(models.Model):
def rating_apply(self, rate, token=None, feedback=None, subtype=None):
return super(Task, self).rating_apply(rate, token=token, feedback=feedback, subtype="project.mt_task_rating")
- def rating_get_parent_model_name(self, vals):
- return 'project.project'
-
- def rating_get_parent_id(self):
- return self.project_id.id
+ def rating_get_parent(self):
+ return 'project_id'
class ProjectTags(models.Model):
diff --git a/addons/project/tests/test_project_flow.py b/addons/project/tests/test_project_flow.py
index 6a7c426f492..c814c0d68cf 100644
--- a/addons/project/tests/test_project_flow.py
+++ b/addons/project/tests/test_project_flow.py
@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+import base64
+
from .test_project_base import TestProjectBase
from odoo.tools import mute_logger
+from odoo.modules.module import get_resource_path
EMAIL_TPL = """Return-Path: <whatever-2a840@postmaster.twitter.com>
@@ -117,3 +120,72 @@ class TestProjectFlow(TestProjectBase):
})
self.assertEqual(parent_task.partner_id, child_task.partner_id, "Subtask partner should not change when changing project")
+
+ def test_rating(self):
+ """Check if rating works correctly even when task is changed from project A to project B"""
+ Task = self.env['project.task'].with_context({'tracking_disable': True})
+ first_task = Task.create({
+ 'name': 'first task',
+ 'user_id': self.user_projectuser.id,
+ 'project_id': self.project_pigs.id,
+ 'partner_id': self.partner_2.id,
+ })
+
+ self.assertEqual(first_task.rating_count, 0, "Task should have no rating associated with it")
+
+ Rating = self.env['rating.rating']
+ rating_good = Rating.create({
+ 'res_model_id': self.env['ir.model']._get('project.task').id,
+ 'res_id': first_task.id,
+ 'parent_res_model_id': self.env['ir.model']._get('project.project').id,
+ 'parent_res_id': self.project_pigs.id,
+ 'rated_partner_id': self.partner_2.id,
+ 'partner_id': self.partner_2.id,
+ 'rating': 10,
+ 'consumed': False,
+ })
+
+ rating_bad = Rating.create({
+ 'res_model_id': self.env['ir.model']._get('project.task').id,
+ 'res_id': first_task.id,
+ 'parent_res_model_id': self.env['ir.model']._get('project.project').id,
+ 'parent_res_id': self.project_pigs.id,
+ 'rated_partner_id': self.partner_2.id,
+ 'partner_id': self.partner_2.id,
+ 'rating': 5,
+ 'consumed': True,
+ })
+
+ # We need to invalidate cache since it is not done automatically by the ORM
+ # Our One2Many is linked to a res_id (int) for which the orm doesn't create an inverse
+ first_task.invalidate_cache()
+
+ self.assertEqual(rating_good.rating_text, 'satisfied')
+ self.assertEqual(rating_bad.rating_text, 'not_satisfied')
+ self.assertEqual(first_task.rating_count, 1, "Task should have only one rating associated, since one is not consumed")
+ self.assertEqual(rating_good.parent_res_id, self.project_pigs.id)
+ self.assertEqual(self.project_goats.percentage_satisfaction_task, -1)
+ self.assertEqual(self.project_pigs.percentage_satisfaction_task, -1)
+
+ # Consuming rating_good
+ first_task.rating_apply(10, rating_good.access_token)
+
+ # We need to invalidate cache since it is not done automatically by the ORM
+ # Our One2Many is linked to a res_id (int) for which the orm doesn't create an inverse
+ first_task.invalidate_cache()
+
+ self.assertEqual(first_task.rating_count, 2, "Task should have two ratings associated with it")
+ self.assertEqual(rating_good.parent_res_id, self.project_pigs.id)
+ self.assertEqual(self.project_goats.percentage_satisfaction_task, -1)
+ self.assertEqual(self.project_pigs.percentage_satisfaction_task, 50)
+
+ # We change the task from project_pigs to project_goats, ratings should be associated with the new project
+ first_task.project_id = self.project_goats.id
+
+ # We need to invalidate cache since it is not done automatically by the ORM
+ # Our One2Many is linked to a res_id (int) for which the orm doesn't create an inverse
+ first_task.invalidate_cache()
+
+ self.assertEqual(rating_good.parent_res_id, self.project_goats.id)
+ self.assertEqual(self.project_goats.percentage_satisfaction_task, 50)
+ self.assertEqual(self.project_pigs.percentage_satisfaction_task, -1)