diff --git a/addons/rating/models/__init__.py b/addons/rating/models/__init__.py index 27f56b84f11..8ef312cfec8 100644 --- a/addons/rating/models/__init__.py +++ b/addons/rating/models/__init__.py @@ -1,2 +1,5 @@ # -*- coding: utf-8 -*- + from . import rating +from . import mail_thread +from . import mail_message diff --git a/addons/rating/models/mail_message.py b/addons/rating/models/mail_message.py new file mode 100644 index 00000000000..b0190933d15 --- /dev/null +++ b/addons/rating/models/mail_message.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class MailMessage(models.Model): + _inherit = 'mail.message' + + rating_ids = fields.One2many('rating.rating', 'message_id', string='Related ratings') + rating_value = fields.Float("Rating Value", compute='_compute_rating_value', store=True) + + @api.multi + @api.depends('rating_ids', 'rating_ids.rating') + def _compute_rating_value(self): + ratings = self.env['rating.rating'].search([('message_id', 'in', self.ids), ('consumed', '=', True)], order='create_date DESC') + mapping = dict((r.message_id.id, r.rating) for r in ratings) + for message in self: + message.rating_value = mapping.get(message.id, 0.0) diff --git a/addons/rating/models/mail_thread.py b/addons/rating/models/mail_thread.py new file mode 100644 index 00000000000..89ba8badf89 --- /dev/null +++ b/addons/rating/models/mail_thread.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + @api.multi + @api.returns('self', lambda value: value.id) + def message_post(self, body='', subject=None, message_type='notification', subtype=None, parent_id=False, attachments=None, content_subtype='html', **kwargs): + rating_value = kwargs.get('rating_value') + message = super(MailThread, self).message_post(body=body, subject=subject, message_type=message_type, subtype=subtype, parent_id=parent_id, attachments=attachments, content_subtype=content_subtype, **kwargs) + if rating_value: + ir_model = self.env['ir.model'].sudo().search([('model', '=', self._name)]) + self.env['rating.rating'].create({ + 'rating': float(rating_value) if rating_value is not None else False, + 'res_model_id': ir_model.id, + 'res_id': self.id, + 'message_id': message.id, + 'consumed': True, + 'partner_id': self.env.user.partner_id.id, + }) + return message diff --git a/addons/rating/static/src/css/rating_common.css b/addons/rating/static/src/css/rating_common.css deleted file mode 100644 index ff84353a8eb..00000000000 --- a/addons/rating/static/src/css/rating_common.css +++ /dev/null @@ -1,48 +0,0 @@ -/* Star Widget */ -.o_rating_star_card{ - margin-bottom: 5px; -} - -.o_rating_star_card .stars { - display: inline-block; - color: #FACC2E; - margin-right: 15px; -} - -.o_rating_star_card .stars i { - margin-right: -3px; - text-align: center; -} - -.o_rating_star_card .stars.enabled{ - cursor: pointer; -} - -.o_rating_star_card .rate_text{ - display: inline-block; -} - - -/* Rating Card */ -.o_rating_card .progress { - position: relative; - height: 25px; - margin-bottom: 3px; -} -.o_rating_card .progress-bar { - background-color: #FACC2E; -} -.o_rating_card .progress > .progress_type { - position: absolute; - left: 0px; - font-weight: 800; - padding: 3px 10px 2px 10px; - color: rgb(120, 100, 100); - width: 100%; -} -.o_rating_card .progress > .progress_completed { - position: absolute; - right: 0px; - font-weight: 800; - padding: 3px 10px 2px; -} \ No newline at end of file diff --git a/addons/rating/static/src/js/rating_common.js b/addons/rating/static/src/js/rating_common.js deleted file mode 100644 index 623f6466c1b..00000000000 --- a/addons/rating/static/src/js/rating_common.js +++ /dev/null @@ -1,127 +0,0 @@ -odoo.define('rating.rating', function (require) { - "use strict"; - - var Widget = require('web.Widget'); - var translation = require('web.translation'); - var _t = translation._t; - - // Star Widget - var RatingStarWidget = Widget.extend({ - template: 'rating.rating_star_card', - events: { - "mousemove .stars i" : "moveOnStars", - "mouseleave .stars i" : "moveOut", - "click .stars" : "clickOnStar", - "mouseleave .stars" : "moveOutStars", - }, - init: function(parent, options){ - this._super.apply(this, arguments); - this.options = _.defaults(options || {}, { - 'rating_default_value': 0, - 'rating_disabled': 0, - }); - this.labels = { - '0': "", - '1': _t("I hate it"), - '2': _t("I don't like it"), - '3': _t("It's okay"), - '4': _t("I like it"), - '5': _t("I love it"), - }; - this.user_click = false; // user has click or not - this.set("star_value", 0); - this.on("change:star_value", this, this.changeStars); - }, - start: function(){ - this.$input = this.$('input'); - this.star_list = this.$('.stars').find('i'); - // set the default value - this.set("star_value", this.options.rating_default_value); - this.is_editable = !this.options.rating_disabled; - }, - attachTo: function(el){ - this._super.apply(this, arguments); - // set the default value and bind event - var default_value = this.$('input').data('default') || this.options['rating_default_value']; - default_value = this.roundToHalf(default_value); - this.set('star_value', default_value); - // is_editable value from DOM - this.is_editable = !this.$input.data('is_disabled') || this.options['rating_disabled']; - }, - changeStars: function(){ - var val = this.get("star_value"); - var index = Math.floor(val); - var decimal = val - index; - // reset the stars - this.star_list.removeClass('fa-star fa-star-half-o').addClass('fa-star-o'); - - this.$('.stars').find("i:lt("+index+")").removeClass('fa-star-o fa-star-half-o').addClass('fa-star'); - if(decimal){ - this.$('.stars').find("i:eq("+(index)+")").removeClass('fa-star-o fa-star fa-star-half-o').addClass('fa-star-half-o'); - } - - this.$input.val(val); - this.$('.rate_text .label').text(this.labels[index]); - }, - moveOut: function(){ - if(!this.user_click && this.is_editable){ - this.set("star_value", 0); - } - this.user_click = false; - }, - moveOnStars: function(e){ - if(this.is_editable){ - this.$('.rate_text').show(); - var index = this.$('.stars i').index(e.currentTarget); - this.set("star_value", index+1); - } - }, - clickOnStar: function(e){ - if(this.is_editable){ - this.user_click = true; - } - }, - moveOutStars: function(e){ - this.$('.rate_text').hide(); - }, - roundToHalf: function(value) { - var converted = parseFloat(value); // Make sure we have a number - var decimal = (converted - parseInt(converted, 10)); - decimal = Math.round(decimal * 10); - if(decimal == 5){ - return (parseInt(converted, 10)+0.5); - } - if((decimal < 3) || (decimal > 7)){ - return Math.round(converted); - }else{ - return (parseInt(converted, 10)+0.5); - } - }, - }); - - var page_widgets = {}; - - $(document).ready(function(){ - // Rating Card - $('[data-toggle="rating-popover"]').popover({ - html : true, - trigger: 'hover', - title: function() { - return $(this).parent().find('.rating_popover').find('.popover-title').html(); - }, - content: function() { - return $(this).parent().find('.rating_popover').find('.popover-content').html(); - } - }); - // Rating Star Widget instances - $('.o_rating_star_card').each(function(index, elem){ - page_widgets[index] = new RatingStarWidget(); - page_widgets[index].attachTo(elem); - }) - }); - - return { - RatingStarWidget: RatingStarWidget, - rating_star_widgets: page_widgets, - }; -}); \ No newline at end of file diff --git a/addons/rating/static/src/xml/rating_common.xml b/addons/rating/static/src/xml/rating_common.xml deleted file mode 100644 index fb703785ae7..00000000000 --- a/addons/rating/static/src/xml/rating_common.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - -
-
- - - - - -
-
- -
- -
-
-
diff --git a/addons/rating/views/rating_template.xml b/addons/rating/views/rating_template.xml index 79b86bfa9de..b6fa5304b54 100644 --- a/addons/rating/views/rating_template.xml +++ b/addons/rating/views/rating_template.xml @@ -1,91 +1,6 @@ - - - - - - - - - -