diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 4b7c0c645e3..1d5d85e36e0 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -130,7 +130,8 @@ class mail_message(osv.Model): 'unread': fields.function(_get_unread, fnct_search=_search_unread, type='boolean', string='Unread', help='Functional field to search for unread messages linked to uid'), - 'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', 'Votes'), + 'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', string='Votes', + help='Users that voted for this message'), } def _needaction_domain_get(self, cr, uid, context=None): @@ -153,19 +154,16 @@ class mail_message(osv.Model): #------------------------------------------------------ def vote_toggle(self, cr, uid, ids, user_ids=None, context=None): - ''' - Toggles when Comment is liked or unlike. - create vote entries if current user like comment.. - ''' + ''' Toggles voting ''' if not user_ids: user_ids = [uid] for message in self.read(cr, uid, ids, ['vote_user_ids'], context=context): for user_id in user_ids: - has_voted = user_id in message['vote_user_ids'] + has_voted = user_id in message.get('vote_user_ids') if not has_voted: - self.write(cr, uid, ids, {'vote_user_ids': [(4, user_id)]}, context=context) + self.write(cr, uid, message.get('id'), {'vote_user_ids': [(4, user_id)]}, context=context) else: - self.write(cr, uid, ids, {'vote_user_ids': [(3, user_id)]}, context=context) + self.write(cr, uid, message.get('id'), {'vote_user_ids': [(3, user_id)]}, context=context) return True #------------------------------------------------------ @@ -174,11 +172,10 @@ class mail_message(osv.Model): def _message_dict_get(self, cr, uid, msg, context=None): """ Return a dict representation of the message browse record. """ - vote_pool = self.pool.get('mail.vote') has_voted = False vote_ids = self.pool.get('res.users').name_get(cr, uid, [user.id for user in msg.vote_user_ids], context=context) - for user_id in msg.vote_user_ids: - if (user_id.id == uid): + for vote in vote_ids: + if vote[0] == uid: has_voted = True break attachment_ids = [{'id': attach[0], 'name': attach[1]} for attach in self.pool.get('ir.attachment').name_get(cr, uid, [x.id for x in msg.attachment_ids], context=context)] diff --git a/addons/mail/mail_vote.py b/addons/mail/mail_vote.py index 3d69734f198..1e439fe0aeb 100644 --- a/addons/mail/mail_vote.py +++ b/addons/mail/mail_vote.py @@ -30,10 +30,10 @@ class mail_vote(osv.Model): _name = 'mail.vote' _description = 'Mail Vote' _columns = { - 'message_id': fields.many2one('mail.message', 'Message', required=True, - select=1), - 'user_id': fields.many2one('res.users', 'User', required=True, - select=1), + 'message_id': fields.many2one('mail.message', 'Message', select=1, + ondelete='cascade', required=True), + 'user_id': fields.many2one('res.users', 'User', select=1, + ondelete='cascade', required=True), } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail/static/src/img/vote.gif b/addons/mail/static/src/img/vote.gif deleted file mode 100644 index 0e6b874770e..00000000000 Binary files a/addons/mail/static/src/img/vote.gif and /dev/null differ diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2f5f95fbb62..57c777441e7 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -529,7 +529,7 @@ openerp.mail = function(session) { record.vote_user_ids.splice(idx, 1); } else { - record.vote_user_ids.push([this.session.uid, 'Current user']); + record.vote_user_ids.push([this.session.uid, 'You']); } record.has_voted = ! record.has_voted; var vote_element = session.web.qweb.render('mail.thread.message.vote', {'record': record});