[IMP] rating, rating_project, rating_project_issue : add 'auto validation kanban state' option. This will modify the kanban state according customer feedback. Require some change : notify by mail the follower when rating, and better sudo usage. Also update wrong code comments.

This commit is contained in:
Jérome Maes
2015-02-12 13:29:14 +01:00
parent 392d995d1f
commit 283868bc5f
5 changed files with 57 additions and 13 deletions
+1 -1
View File
@@ -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)
+8 -10
View File
@@ -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 <br/><img src='/rating/static/src/img/rating_%s.png' style='width:20px;height:20px'/>"
% (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
+26 -1
View File
@@ -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()
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
+2 -1
View File
@@ -28,7 +28,8 @@
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='sequence']" position="after">
<field name="rating_template_id"/>
<field name="rating_template_id"/>
<field name="auto_validation_kanban_state" attrs="{'invisible': [('rating_template_id','=', False)]}"/>
</xpath>
</field>
</record>
@@ -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