From e4a4ffb974ccde1842e1b2389450718f8576ad5b Mon Sep 17 00:00:00 2001 From: "Benjamin Frantzen (bfr)" Date: Wed, 18 Dec 2019 13:45:38 +0000 Subject: [IMP] customer ratings flow improvements - Rename the 'Use Rating on Project' feature into 'Customer Ratings' - Rename the 'Set Email Template to Stages' link to 'Set a Rating Email Template on Stages' - Add an optional list view for the Stages menu - display warning if the rating_template_id field is set and if one of the selected project_ids doesn't have the rating_status field set to true - Project form view revamp - rename the '% on tasks' stat button into 'Customer Satisfaction' - Remove the 'no option' for the rating frequency field because it is required - project form : Add a 'Go to Website' stat button - Project dashboard: remove the 'Customer Ratings' menu item in more - Ratings page: the 'Last 30 days' filter include ratings from today - remove the Appointment / Helpdesk Customer Satisfaction / Live Support menu items TASK ID : 1251 --- addons/project/controllers/__init__.py | 1 - addons/project/controllers/rating.py | 96 ---------------------------------- 2 files changed, 97 deletions(-) delete mode 100644 addons/project/controllers/rating.py (limited to 'addons/project/controllers') diff --git a/addons/project/controllers/__init__.py b/addons/project/controllers/__init__.py index 10825353c81..903b755e71e 100644 --- a/addons/project/controllers/__init__.py +++ b/addons/project/controllers/__init__.py @@ -2,4 +2,3 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import portal -from . import rating diff --git a/addons/project/controllers/rating.py b/addons/project/controllers/rating.py deleted file mode 100644 index c57734e6a99..00000000000 --- a/addons/project/controllers/rating.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from werkzeug.exceptions import NotFound - -from odoo import http -from odoo.http import request - - -class RatingProject(http.Controller): - - @http.route(['/project/rating'], type='http', auth="public", website=True, sitemap=True) - def index(self, **kw): - projects = request.env['project.project'].sudo().search([('rating_status', '!=', 'no'), ('portal_show_rating', '=', True)]) - values = {'projects': projects} - return request.render('project.rating_index', values) - - def _calculate_period_partner_stats(self, project_id): - # get raw data: number of rating by rated partner, by rating value, by period - request.env.cr.execute(""" - SELECT - rated_partner_id, - rating, - COUNT(rating) as rating_count, - CASE - 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 - WHERE - parent_res_model = 'project.project' - AND parent_res_id = %s - AND res_model = 'project.task' - AND rated_partner_id IS NOT NULL - AND write_date >= current_date - interval '90' day - AND rating IN (1,5,10) - GROUP BY - rated_partner_id, rating, period - """, (project_id, )) - - raw_data = request.env.cr.dictfetchall() - - # periodical statistics - default_period_dict = {'rating_10': 0, 'rating_5': 0, 'rating_1': 0, 'total': 0} - period_statistics = { - 'days_06': dict(default_period_dict), - 'days_15': dict(default_period_dict), - 'days_30': dict(default_period_dict), - 'days_90': dict(default_period_dict), - } - for period_statistics_key in period_statistics.keys(): - for row in raw_data: - if row['period'] <= period_statistics_key: - period_statistics[period_statistics_key]['rating_%s' % (int(row['rating']),)] += row['rating_count'] - period_statistics[period_statistics_key]['total'] += row['rating_count'] - - # partner statistics - default_partner_dict = {'rating_10': 0, 'rating_5': 0, 'rating_1': 0, 'total': 0, 'rated_partner': None, 'percentage_happy': 0.0} - partner_statistics = {} - for row in raw_data: - if row['period'] <= 'days_15': - if row['rated_partner_id'] not in partner_statistics: - partner_statistics[row['rated_partner_id']] = dict(default_partner_dict) - partner_statistics[row['rated_partner_id']]['rated_partner'] = request.env['res.partner'].sudo().browse(row['rated_partner_id']) - partner_statistics[row['rated_partner_id']]['rating_%s' % (int(row['rating']),)] += row['rating_count'] - partner_statistics[row['rated_partner_id']]['total'] += row['rating_count'] - - for partner_id, stat_values in partner_statistics.items(): - stat_values['percentage_happy'] = (stat_values['rating_10'] / float(stat_values['total'])) * 100 if stat_values['total'] else 0.0 - - return { - 'partner_statistics': partner_statistics, - 'period_statistics': period_statistics, - } - - @http.route(['/project/rating/'], type='http', auth="public", website=True) - def page(self, project_id=None, **kw): - user = request.env.user - project = request.env['project.project'].sudo().browse(project_id) - # to avoid giving any access rights on projects to the public user, let's use sudo - # and check if the user should be able to view the project (project managers only if it's unpublished or has no rating) - if not ((project.rating_status != 'no') and project.portal_show_rating) and not user.with_user(user).has_group('project.group_project_manager'): - raise NotFound() - - return request.render('project.rating_project_rating_page', { - 'project': project, - 'ratings': request.env['rating.rating'].sudo().search([ - ('consumed', '=', True), - ('parent_res_model', '=', 'project.project'), - ('parent_res_id', '=', project_id) - ], order='write_date DESC', limit=50), - 'statistics': self._calculate_period_partner_stats(project_id), - }) -- cgit v1.2.3