diff --git a/.tx/config b/.tx/config index 6d1bae6b388..d73573536ab 100644 --- a/.tx/config +++ b/.tx/config @@ -597,11 +597,6 @@ file_filter = addons/rating/i18n/.po source_file = addons/rating/i18n/rating.pot source_lang = en -[odoo-11.rating_project] -file_filter = addons/rating_project/i18n/.po -source_file = addons/rating_project/i18n/rating_project.pot -source_lang = en - [odoo-11.report_intrastat] file_filter = addons/report_intrastat/i18n/.po source_file = addons/report_intrastat/i18n/report_intrastat.pot @@ -652,11 +647,6 @@ file_filter = addons/sale_payment/i18n/.po source_file = addons/sale_payment/i18n/sale_payment.pot source_lang = en -[odoo-11.sale_service_rating] -file_filter = addons/sale_service_rating/i18n/.po -source_file = addons/sale_service_rating/i18n/sale_service_rating.pot -source_lang = en - [odoo-11.sale_stock] file_filter = addons/sale_stock/i18n/.po source_file = addons/sale_stock/i18n/sale_stock.pot @@ -892,12 +882,7 @@ file_filter = addons/website_rating/i18n/.po source_file = addons/website_rating/i18n/website_rating.pot source_lang = en -[odoo-11.website_rating_project] -file_filter = addons/website_rating_project/i18n/.po -source_file = addons/website_rating_project/i18n/website_rating_project.pot -source_lang = en - -[odoo-11.website_sale] +[odoo-master.website_sale] file_filter = addons/website_sale/i18n/.po source_file = addons/website_sale/i18n/website_sale.pot source_lang = en diff --git a/addons/project/__manifest__.py b/addons/project/__manifest__.py index d95a21d1ee7..e80837b5631 100644 --- a/addons/project/__manifest__.py +++ b/addons/project/__manifest__.py @@ -14,6 +14,7 @@ 'analytic', 'mail', 'portal', + 'rating', 'resource', 'web', 'web_tour', @@ -24,11 +25,13 @@ 'security/ir.model.access.csv', 'data/project_data.xml', 'report/project_report_views.xml', + 'views/rating_views.xml', 'views/project_views.xml', 'views/res_partner_views.xml', 'views/res_config_settings_views.xml', - 'views/project_templates.xml', + 'views/project_assets.xml', 'views/project_portal_templates.xml', + 'views/project_rating_templates.xml', 'data/project_mail_template_data.xml', 'wizard/project_task_merge_wizard_views.xml', ], diff --git a/addons/project/controllers/__init__.py b/addons/project/controllers/__init__.py index 903b755e71e..10825353c81 100644 --- a/addons/project/controllers/__init__.py +++ b/addons/project/controllers/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import portal +from . import rating diff --git a/addons/website_rating_project/controllers/main.py b/addons/project/controllers/rating.py similarity index 95% rename from addons/website_rating_project/controllers/main.py rename to addons/project/controllers/rating.py index 98c6cacc057..3343674c0e8 100644 --- a/addons/website_rating_project/controllers/main.py +++ b/addons/project/controllers/rating.py @@ -7,13 +7,13 @@ from odoo import http from odoo.http import request -class WebsiteRatingProject(http.Controller): +class RatingProject(http.Controller): @http.route(['/project/rating/'], type='http', auth="public", website=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('website_rating_project.index', values) + 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 @@ -85,7 +85,7 @@ class WebsiteRatingProject(http.Controller): if not ((project.rating_status != 'no') and project.portal_show_rating) and not user.sudo(user).has_group('project.group_project_manager'): raise NotFound() - return request.render('website_rating_project.project_rating_page', { + 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), diff --git a/addons/project/data/project_data.xml b/addons/project/data/project_data.xml index de45107ae71..a8f8be15f2b 100644 --- a/addons/project/data/project_data.xml +++ b/addons/project/data/project_data.xml @@ -17,6 +17,15 @@ True + + Project: Send rating + + code + model._send_rating_all() + days + -1 + + @@ -46,6 +55,12 @@ Stage changed + + Task Rating + project.task + + Ratings + Task Opened @@ -79,6 +94,14 @@ project_id + + Task Rating + 14 + project.project + + + project_id + diff --git a/addons/project/data/project_demo.xml b/addons/project/data/project_demo.xml index f5e53c769df..592acc33a7d 100644 --- a/addons/project/data/project_demo.xml +++ b/addons/project/data/project_demo.xml @@ -430,5 +430,51 @@ Send it ASAP, its urgent. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + stage + + + + + + + diff --git a/addons/project/data/project_mail_template_data.xml b/addons/project/data/project_mail_template_data.xml index d33aabf2cd3..808c7d570d6 100644 --- a/addons/project/data/project_mail_template_data.xml +++ b/addons/project/data/project_mail_template_data.xml @@ -109,8 +109,91 @@ + + + + Task: Rating Request + ${object.rating_get_rated_partner_id().email or '' | safe} + ${object.project_id.company_id.name}: Service Rating Request + + ${object.rating_get_partner_id().id} + + + % set access_token = object.rating_get_access_token() + + + + +
+ + + Satisfaction Survey +
+ + + + + + +
+

Hello,

+

Please take a moment to rate our services related to the task "${object.name}" + assigned to ${object.rating_get_rated_partner_id().name}.

+

We appreciate your feedback. It helps us to improve continuously.

+
+ + + + + + + +
+

+ Tell us how you feel about our service: +

+
(click on one of these smileys)
+
+ + + + + + +
+ + Satisfied + + + + Not satisfied + + + + Highly Dissatisfied + +
+
+
${(object.user_id.signature or '')| safe}
+ + + + +
+ % if object.project_id.rating_status == 'stage': +

This customer survey has been sent because your task has been moved to the stage ${object.stage_id.name}

+ % endif + % if object.project_id.rating_status == 'periodic': +

This customer survey is sent ${object.project_id.rating_status_period} as long as the task is in the ${object.stage_id.name} stage.

+ % endif +

Email automatically sent by Odoo Project for ${object.project_id.company_id.name}

+
+ +]]>
+
diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 2bb472fa2c3..1df6bbad540 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from datetime import timedelta from lxml import etree from odoo import api, fields, models, tools, SUPERUSER_ID, _ @@ -41,6 +42,15 @@ class ProjectTaskType(models.Model): help="If set an email will be sent to the customer when the task or issue reaches this step.") fold = fields.Boolean(string='Folded in Kanban', help='This stage is folded in the kanban view when there are no records in that stage to display.') + rating_template_id = fields.Many2one( + 'mail.template', + string='Rating Email Template', + domain=[('model', '=', 'project.task')], + help="If set and if the project's rating configuration is 'Rating when changing stage', then an email will be sent to the customer when the task reaches this step.") + auto_validation_kanban_state = fields.Boolean('Automatic kanban status', default=False, + help="Automatically modify the kanban state when the customer replies to the feedback for this stage.\n" + " * A good 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 Project(models.Model): @@ -214,6 +224,22 @@ class Project(models.Model): date = fields.Date(string='Expiration Date', index=True, track_visibility='onchange') subtask_project_id = fields.Many2one('project.project', string='Sub-task Project', ondelete="restrict", help="Choosing a sub-tasks project will both enable sub-tasks and set their default project (possibly the project itself)") + # rating fields + percentage_satisfaction_task = fields.Integer( + compute='_compute_percentage_satisfaction_task', string="Happy % on Task", store=True, default=-1) + percentage_satisfaction_project = fields.Integer( + compute="_compute_percentage_satisfaction_project", string="Happy % on Project", store=True, default=-1) + rating_request_deadline = fields.Datetime(compute='_compute_rating_request_deadline', store=True) + rating_status = fields.Selection([('stage', 'Rating when changing stage'), ('periodic', 'Periodical Rating'), ('no','No rating')], 'Customer(s) Ratings', help="How to get the customer's feedbacks?\n" + "- Rating when changing stage: Email will be sent when a task/issue is pulled in another stage\n" + "- Periodical Rating: Email will be sent periodically\n\n" + "Don't forget to set up the mail templates on the stages for which you want to get the customer's feedbacks.", default="no", required=True) + rating_status_period = fields.Selection([ + ('daily', 'Daily'), ('weekly', 'Weekly'), ('bimonthly', 'Twice a Month'), + ('monthly', 'Once a Month'), ('quarterly', 'Quarterly'), ('yearly', 'Yearly') + ], 'Rating Frequency') + + portal_show_rating = fields.Boolean('Rating visible publicly', copy=False, oldname='website_published') _sql_constraints = [ ('project_date_greater', 'check(date >= date_start)', 'Error! project start-date must be lower than project end-date.') @@ -224,6 +250,26 @@ class Project(models.Model): for project in self: project.portal_url = '/my/project/%s' % project.id + @api.depends('percentage_satisfaction_task') + def _compute_percentage_satisfaction_project(self): + domain = [('create_date', '>=', fields.Datetime.to_string(fields.datetime.now() - timedelta(days=30)))] + for project in self: + activity = project.tasks.rating_get_grades(domain) + project.percentage_satisfaction_project = activity['great'] * 100 / sum(activity.values()) if sum(activity.values()) else -1 + + #TODO JEM: Only one field can be kept since project only contains task + @api.depends('tasks.rating_ids.rating') + def _compute_percentage_satisfaction_task(self): + for project in self: + activity = project.tasks.rating_get_grades() + project.percentage_satisfaction_task = activity['great'] * 100 / sum(activity.values()) if sum(activity.values()) else -1 + + @api.depends('rating_status', 'rating_status_period') + def _compute_rating_request_deadline(self): + periods = {'daily': 1, 'weekly': 7, 'bimonthly': 15, 'monthly': 30, 'quarterly': 90, 'yearly': 365} + for project in self: + project.rating_request_deadline = fields.datetime.now() + timedelta(days=periods.get(project.rating_status_period, 0)) + @api.multi def map_tasks(self, new_project_id): """ copy and map tasks from old to new project """ @@ -325,6 +371,10 @@ class Project(models.Model): return groups + # --------------------------------------------------- + # Actions + # --------------------------------------------------- + @api.multi def toggle_favorite(self): favorite_projects = not_fav_projects = self.env['project.project'].sudo() @@ -354,12 +404,40 @@ class Project(models.Model): 'context': ctx } + @api.multi + def action_view_all_rating(self): + """ return the action to see all the rating of the project, and activate default filters """ + if self.portal_show_rating: + return { + 'type': 'ir.actions.act_url', + 'name': "Redirect to the Website Projcet Rating Page", + 'target': 'self', + 'url': "/project/rating/%s" % (self.id,) + } + action = self.env['ir.actions.act_window'].for_xml_id('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) + action_context['search_default_parent_res_name'] = self.name + return dict(action, context=action_context) + + # --------------------------------------------------- + # Rating business + # --------------------------------------------------- + + # This method should be called once a day by the scheduler + @api.model + def _send_rating_all(self): + projects = self.search([('rating_status', '=', 'periodic'), ('rating_request_deadline', '<=', fields.Datetime.now())]) + projects.mapped('task_ids')._send_task_rating_mail() + projects._compute_rating_request_deadline() + class Task(models.Model): _name = "project.task" _description = "Task" _date_name = "date_start" - _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin'] + _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin', 'rating.mixin'] _mail_post_access = 'read' _order = "priority desc, sequence, date_start, name, id" @@ -656,7 +734,9 @@ class Task(models.Model): vals['date_assign'] = now result = super(Task, self).write(vals) - + # rating on stage + if 'stage_id' in vals and vals.get('stage_id'): + self.filtered(lambda x: x.project_id.rating_status == 'stage')._send_task_rating_mail(force_send=True) return result def update_date_end(self, stage_id): @@ -865,6 +945,32 @@ class Task(models.Model): 'type': 'ir.actions.act_window' } + # --------------------------------------------------- + # Rating business + # --------------------------------------------------- + + def _send_task_rating_mail(self, force_send=False): + for task in self: + rating_template = task.stage_id.rating_template_id + if rating_template: + task.rating_send_request(rating_template, lang=task.partner_id.lang, force_send=force_send) + + def rating_get_partner_id(self): + res = super(Task, self).rating_get_partner_id() + if not res and self.project_id.partner_id: + return self.project_id.partner_id + return res + + @api.multi + 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 + class ProjectTags(models.Model): """ Tags of project's tasks """ diff --git a/addons/project/models/res_config_settings.py b/addons/project/models/res_config_settings.py index f008f52a5aa..ea1eb675904 100644 --- a/addons/project/models/res_config_settings.py +++ b/addons/project/models/res_config_settings.py @@ -8,6 +8,6 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' module_hr_timesheet = fields.Boolean("Timesheets") - module_rating_project = fields.Boolean(string="Rating on Tasks") module_project_forecast = fields.Boolean(string="Forecasts") group_subtask_project = fields.Boolean("Sub-tasks", implied_group="project.group_subtask_project") + group_project_rating = fields.Boolean("Use Rating on Project", implied_group='project.group_project_rating') diff --git a/addons/project/security/project_security.xml b/addons/project/security/project_security.xml index c2cfb562e56..f2f70e949f9 100644 --- a/addons/project/security/project_security.xml +++ b/addons/project/security/project_security.xml @@ -24,6 +24,11 @@ + + Use Rating on Project + + + diff --git a/addons/website_rating_project/static/src/js/website_rating_project.js b/addons/project/static/src/js/portal_rating.js similarity index 77% rename from addons/website_rating_project/static/src/js/website_rating_project.js rename to addons/project/static/src/js/portal_rating.js index 44c91980ae7..12740b9bbba 100644 --- a/addons/website_rating_project/static/src/js/website_rating_project.js +++ b/addons/project/static/src/js/portal_rating.js @@ -4,14 +4,14 @@ odoo.define('website_rating_project.rating', function (require) { var time = require('web.time'); require('web.dom_ready'); - if(!$('.o_website_rating_project').length) { - return $.Deferred().reject("DOM doesn't contain '.o_website_rating_project'"); + if(!$('.o_portal_project_rating').length) { + return $.Deferred().reject("DOM doesn't contain '.o_portal_project_rating'"); } /** * Rating popover with some informations */ - $('.o_website_rating_project .o_rating_image').popover({ + $('.o_portal_project_rating .o_rating_image').popover({ placement: 'bottom', trigger: 'hover', html: 'true', diff --git a/addons/website_rating_project/static/src/less/website_rating_project.less b/addons/project/static/src/less/portal_rating.less similarity index 95% rename from addons/website_rating_project/static/src/less/website_rating_project.less rename to addons/project/static/src/less/portal_rating.less index e95b1dbfac7..4ae3290a75b 100644 --- a/addons/website_rating_project/static/src/less/website_rating_project.less +++ b/addons/project/static/src/less/portal_rating.less @@ -1,4 +1,4 @@ -.o_website_rating_project { +.o_portal_project_rating { .thumbnail{ height: 240px; } diff --git a/addons/project/views/project_templates.xml b/addons/project/views/project_assets.xml similarity index 70% rename from addons/project/views/project_templates.xml rename to addons/project/views/project_assets.xml index 9b6d13d2582..7a2c4647984 100644 --- a/addons/project/views/project_templates.xml +++ b/addons/project/views/project_assets.xml @@ -8,6 +8,14 @@ + +