diff --git a/addons/rating/controllers/main.py b/addons/rating/controllers/main.py
index f2ab1ddc2db..e89001d1751 100644
--- a/addons/rating/controllers/main.py
+++ b/addons/rating/controllers/main.py
@@ -14,7 +14,7 @@ class Rating(http.Controller):
if rating:
is_rated = bool(rating.rating != -1)
if not is_rated:
- request.env['rating.rating'].sudo().apply_rating(rate, token=token)
+ request.env['rating.rating'].apply_rating(rate, token=token)
# redirect to the form view if logged person
if request.session.uid and not is_rated:
record = request.env[rating.res_model].browse(rating.res_id)
diff --git a/addons/rating/models/rating.py b/addons/rating/models/rating.py
index 401df694a1c..dab705fc9fa 100644
--- a/addons/rating/models/rating.py
+++ b/addons/rating/models/rating.py
@@ -36,11 +36,12 @@ class Rating(models.Model):
def apply_rating(self, rate, res_model=None, res_id=None, token=None):
""" apply a rating for given res_model/res_id or token. If the res_model is a mail.thread
object, a message will be posted in the chatter.
- :param float rating : the rating value to apply
- :param list res_id : id of the rated object.
- :param string res_model : name of model.
- :param string token : access token
- :return the rating record
+ :param rate : the rating value to apply
+ :type rate : float
+ :param res_id : id of the rated object.
+ :param res_model : name of model.
+ :param token : access token
+ :returns rating.rating record
"""
domain = [('access_token', '=', token)] if token else [('res_model', '=', res_model), ('res_id', '=', res_id)]
rating = self.search(domain, limit=1)
@@ -48,9 +49,10 @@ class Rating(models.Model):
rating.write({'rating' : rate})
if hasattr(self.env[rating.res_model], 'message_post'):
record = self.env[rating.res_model].sudo().browse(rating.res_id)
- record.message_post(
+ record.sudo().message_post(
body="%s %s
"
% (rating.sudo().partner_id.name, _('rated it'), rate),
+ subtype='mail.mt_comment',
author_id=rating.partner_id and rating.partner_id.id or None # None will set the default author in mail_thread.py
)
return rating
@@ -119,8 +121,6 @@ class RatingMixin(models.AbstractModel):
@api.multi
def rating_get_stats(self):
""" get the repatition of rating grade for the given res_ids.
- :param list res_ids : optional list of ids. If not given, this will take the ids of the current recordset.
- :param string res_model : optional name of model. If not given, the one of the current recordset will be used.
:return dictionnary where the key is the rating value (the note), and the value, the number of object (res_model, res_id) having the value
"""
data = self.env['rating.rating'].read_group([('res_model', '=', self._name), ('res_id', 'in', self.ids), ('rating', '>=', 0)], ['rating'], ['rating', 'res_id'])
@@ -132,8 +132,6 @@ class RatingMixin(models.AbstractModel):
@api.multi
def rating_get_grades(self):
""" get the repatition of rating grade for the given res_ids.
- :param list res_ids : optional list of ids. If not given, this will take the ids of the current recordset.
- :param string res_model : optional name of model. If not given, the one of the current recordset will be used.
:return dictionnary where the key is the grade (great, okay, bad), and the value, the number of object (res_model, res_id) having the grade
the grade are compute as 0-30% : Bad
31-69%: Okay
diff --git a/addons/rating_project/models/project.py b/addons/rating_project/models/project.py
index 78181fd1cb8..e1f24ce6381 100644
--- a/addons/rating_project/models/project.py
+++ b/addons/rating_project/models/project.py
@@ -11,6 +11,10 @@ class ProjectTaskType(models.Model):
string='Rating Email Template',
domain=[('model', '=', 'rating.rating')],
help="Select an email template. An email will be sent to the customer when the task reach this step.")
+ auto_validation_kanban_state = fields.Boolean('Auto Kanban state validation', default=False,
+ help="Automatically modify the kanban state when the customer reply to the feedback for this stage.\n"
+ " * A great feedback from the customer will update the kanban state to 'ready for the new stage' (green bullet).\n"
+ " * A medium or a bad feedback will set the kanban state to 'blocked' (red bullet).\n")
class Task(models.Model):
@@ -67,4 +71,25 @@ class Project(models.Model):
@api.multi
def action_view_all_rating(self):
""" return the action to see all the rating about the all sort of activity of the project (tasks, issues, ...) """
- return self.action_view_task_rating()
\ No newline at end of file
+ return self.action_view_task_rating()
+
+
+
+class Rating(models.Model):
+
+ _inherit = "rating.rating"
+
+ @api.model
+ def apply_rating(self, rate, res_model=None, res_id=None, token=None):
+ """ check if the auto_validation_kanban_state is activated. If so, apply the modification of the
+ kanban state according to the given rating.
+ """
+ rating = super(Rating, self).apply_rating(rate, res_model, res_id, token)
+ if rating.res_model == 'project.task':
+ task = self.env[rating.res_model].sudo().browse(rating.res_id)
+ if task.stage_id.auto_validation_kanban_state:
+ if rating.rating > 5:
+ task.write({'kanban_state' : 'done'})
+ else:
+ task.write({'kanban_state' : 'blocked'})
+ return rating
diff --git a/addons/rating_project/views/project_view.xml b/addons/rating_project/views/project_view.xml
index 66a913f2de4..7cc2993fccf 100644
--- a/addons/rating_project/views/project_view.xml
+++ b/addons/rating_project/views/project_view.xml
@@ -28,7 +28,8 @@
-
+
+
diff --git a/addons/rating_project_issue/models/project_issue.py b/addons/rating_project_issue/models/project_issue.py
index 526c976b5cb..3b4506d9172 100644
--- a/addons/rating_project_issue/models/project_issue.py
+++ b/addons/rating_project_issue/models/project_issue.py
@@ -94,3 +94,23 @@ class Project(models.Model):
domain = [('rating', '!=', -1)] + domain # prepend the condition to avoid empty rating
return dict(action, domain=domain)
+
+
+class Rating(models.Model):
+
+ _inherit = "rating.rating"
+
+ @api.model
+ def apply_rating(self, rate, res_model=None, res_id=None, token=None):
+ """ check if the auto_validation_kanban_state is activated. If so, apply the modification of the
+ kanban state according to the given rating.
+ """
+ rating = super(Rating, self).apply_rating(rate, res_model, res_id, token)
+ if rating.res_model == 'project.issue':
+ issue = self.env[rating.res_model].sudo().browse(rating.res_id)
+ if issue.stage_id.auto_validation_kanban_state:
+ if rating.rating > 5:
+ issue.write({'kanban_state' : 'done'})
+ else:
+ issue.write({'kanban_state' : 'blocked'})
+ return rating