[IMP] rating_project: simplify action to see project rating

Rating improvements :
- use parent res_model/res_id in action domain for
performance issue
- satisfaction on project kanban card redirect to
rating kanban with default filter
- UX improvements
- Clean method generatign action to rating kanban,
according to the project settings (use tasks and/or
issues).
This commit is contained in:
Jérome Maes
2017-07-10 08:46:27 +02:00
parent 145853c9c7
commit 7702bbf42c
4 changed files with 53 additions and 43 deletions
+9 -13
View File
@@ -3,8 +3,8 @@
from datetime import timedelta
from odoo import api, fields, models
from odoo.tools import pycompat
from odoo import api, fields, models, _
from odoo.tools.safe_eval import safe_eval
@@ -108,17 +108,13 @@ class Project(models.Model):
for project in self:
project.rating_request_deadline = fields.datetime.now() + timedelta(days=periods.get(project.rating_status_period, 0))
@api.multi
def action_view_task_rating(self):
""" return the action to see all the rating about the tasks of the project """
action = self.env['ir.actions.act_window'].for_xml_id('rating_project', 'rating_rating_action_view_project_rating')
action_domain = safe_eval(action['domain']) if action['domain'] else []
domain = ['&', ('res_id', 'in', self.tasks.ids), ('res_model', '=', 'project.task')]
if action_domain:
domain = ['&'] + domain + action_domain
return dict(action, domain=domain)
@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 the action to see all the rating of the project, and activate default filters """
action = self.env['ir.actions.act_window'].for_xml_id('rating_project', 'rating_rating_action_view_project_rating')
action['name'] = _('Ratings of %s') % (self.name,)
action_context = safe_eval(action['context']) if action['context'] else {}
action_context.update(self._context)
if self.use_tasks:
action_context['search_default_rating_tasks'] = 1
return dict(action, context=action_context)
+25 -6
View File
@@ -16,6 +16,10 @@
<field name="parent_res_name"/>
<filter string="Project" name="groupby_project" context="{'group_by': 'parent_res_name'}"/>
</xpath>
<xpath expr="/search" position="inside">
<filter string="Last 30 days" name="rating_last_30_days" domain="[('create_date', '>=', (context_today()-datetime.timedelta(days=30)).strftime('%Y-%m-%d'))]"/>
<separator/>
</xpath>
</field>
</record>
@@ -23,7 +27,7 @@
<field name="name">Rating</field>
<field name="res_model">rating.rating</field>
<field name="view_mode">kanban,tree,graph,pivot,form</field>
<field name="domain">[('consumed','=',True)]</field>
<field name="domain">[('consumed','=',True), ('parent_res_model','=','project.project'), ('parent_res_id','=',active_id)]</field>
<field name="search_view_id" ref="rating_rating_view_search_project"/>
<field name="help" type="html">
<p>
@@ -32,6 +36,19 @@
</field>
</record>
<record id="rating_rating_action_view_project_rating_task" model="ir.actions.act_window">
<field name="name">Ratings for tasks</field>
<field name="res_model">rating.rating</field>
<field name="view_mode">kanban,tree,graph,pivot,form</field>
<field name="domain">[('consumed','=',True), ('parent_res_model','=','project.project'), ('parent_res_id','=',active_id), ('res_model','=','project.task')]</field>
<field name="search_view_id" ref="rating_rating_view_search_project"/>
<field name="help" type="html">
<p>
There is no rating for tasks of this project at the moment.
</p>
</field>
</record>
<record id="rating_rating_action_task" model="ir.actions.act_window">
<field name="name">Customer Ratings from task</field>
<field name="res_model">rating.rating</field>
@@ -99,10 +116,10 @@
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button name="action_view_task_rating"
<button name="%(rating_rating_action_view_project_rating_task)d"
attrs="{'invisible': ['|', '|', ('rating_status', '=', 'no'), ('use_tasks','=', False), ('percentage_satisfaction_task', '=', -1)]}"
class="oe_stat_button oe_percent"
type="object"
type="action"
icon="fa-smile-o">
<field string="% On tasks" name="percentage_satisfaction_task" widget="statinfo"/>
</button>
@@ -134,12 +151,13 @@
<xpath expr="//div[contains(@class, 'o_kanban_primary_left')]" position="inside">
<div t-if="record.rating_status.raw_value != 'no'" class="mt8 text-primary" title="Percentage of happy ratings over the past 30 days. Get rating details from the More menu.">
<b>
<i class="fa fa-smile-o"/>
<t t-if="record.percentage_satisfaction_project.value == -1">
No rating yet
<i class="fa fa-smile-o"/> No rating yet
</t>
<t t-if="record.percentage_satisfaction_project.value != -1">
<t t-esc="record.percentage_satisfaction_project.value"/>%
<a name="action_view_all_rating" type="object" context="{'search_default_rating_last_30_days':1}">
<i class="fa fa-smile-o"/> <t t-esc="record.percentage_satisfaction_project.value"/>%
</a>
</t>
</b>
</div>
@@ -179,6 +197,7 @@
Customer ratings on tasks/issues. If you have no rating, change your project Settings to activate it.
</p>
</field>
<field name="context">{}</field>
</record>
<menuitem id="rating_rating_menu_project"
@@ -79,27 +79,9 @@ class Project(models.Model):
percentage_satisfaction_issue = fields.Integer(compute='_compute_percentage_satisfaction_issue', string="Happy % on Issue", store=True, default=-1)
@api.multi
def action_view_issue_rating(self):
""" return the action to see all the rating about the issues of the project """
action = self.env['ir.actions.act_window'].for_xml_id('rating_project', 'rating_rating_action_view_project_rating')
issues = self.env['project.issue'].search([('project_id', 'in', self.ids)])
action_domain = safe_eval(action['domain']) if action['domain'] else []
domain = ['&', ('res_id', 'in', issues.ids), ('res_model', '=', 'project.issue')]
if action_domain:
domain = ['&'] + domain + action_domain
return dict(action, domain=domain)
@api.multi
def action_view_all_rating(self):
action = super(Project, self).action_view_all_rating()
task_domain = action['domain']
domain = []
if self.use_tasks: # add task domain, if needed
domain = task_domain
if self.use_issues: # add issue domain if needed
issue_domain = self.action_view_issue_rating()['domain']
domain = domain + issue_domain
if self.use_tasks and self.use_issues:
domain = ['|'] + domain
return dict(action, domain=domain)
if self.use_issues: # add default filter for issue rating
action['context']['search_default_rating_issues'] = 1
return action
@@ -2,6 +2,19 @@
<odoo>
<data>
<record id="rating_rating_action_view_project_rating_issue" model="ir.actions.act_window">
<field name="name">Ratings for issues</field>
<field name="res_model">rating.rating</field>
<field name="view_mode">kanban,tree,graph,pivot,form</field>
<field name="domain">[('consumed','=',True), ('parent_res_model','=','project.project'), ('parent_res_id','=',active_id), ('res_model','=','project.issue')]</field>
<field name="search_view_id" ref="rating_project.rating_rating_view_search_project"/>
<field name="help" type="html">
<p>
There is no rating for issues of this project at the moment.
</p>
</field>
</record>
<record id="rating_rating_action_issue" model="ir.actions.act_window">
<field name="name">Customer Ratings</field>
<field name="res_model">rating.rating</field>
@@ -21,7 +34,7 @@
<field name="inherit_id" ref="rating_project.rating_rating_view_search_project" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='rating_tasks']" position="after">
<filter string="Rating for issues" domain="[('res_model', '=', 'project.issue')]" />
<filter string="Rating for issues" name="rating_issues" domain="[('res_model', '=', 'project.issue')]" />
</xpath>
</field>
</record>
@@ -79,10 +92,10 @@
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button name="action_view_issue_rating"
<button name="%(rating_rating_action_view_project_rating_issue)d"
attrs="{'invisible': ['|', '|', ('use_issues','=', False), ('rating_status', '=', 'no'), ('percentage_satisfaction_issue', '=', -1)]}"
class="oe_stat_button oe_percent"
type="object"
type="action"
icon="fa-smile-o">
<field string="% On issues" name="percentage_satisfaction_issue" widget="statinfo"/>
</button>