[FIX]: replace vote_user_ids inplace of vote_ids.

write or update vote_ids

bzr revid: atp@tinyerp.com-20120907121028-oyklpcccxb0ewv21
This commit is contained in:
Atul Patel (OpenERP)
2012-09-07 17:40:28 +05:30
parent 07f4c3f166
commit e82782e1f6
3 changed files with 25 additions and 19 deletions
+14 -5
View File
@@ -124,7 +124,7 @@ 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_ids': fields.one2many('mail.vote', 'msg_id', 'Votes'),
'vote_user_ids': fields.many2many('mail.vote', 'message_vote_rel', 'message_id', 'vote_id', 'Votes'),
}
@@ -154,13 +154,14 @@ class mail_message(osv.Model):
vote_pool = self.pool.get('mail.vote')
new_vote_id = False
for message in self.browse(cr, uid, ids, context):
voters_ids = [x.id for x in message.vote_ids if x.user_id.id == uid]
voters_ids = [x.id for x in message.vote_user_ids if x.user_id.id == uid]
if not voters_ids:
new_vote_id = vote_pool.create(cr, uid, {'msg_id': message.id, 'user_id': uid}, context=context)
else:
self.write(cr, uid, ids, {'vote_user_ids': [(4, new_vote_id)]}, context=context)
else:
self.write(cr, uid, ids, {'vote_user_ids': [(3, voters_ids[0])]}, context=context)
vote_pool.unlink(cr, uid, voters_ids, context=context)
return True
return True
#------------------------------------------------------
# Message loading for web interface
@@ -168,7 +169,13 @@ 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')
attachment_ids = self.pool.get('ir.attachment').name_get(cr, uid, [x.id for x in msg.attachment_ids], context=context)
vote_ids = vote_pool.name_get(cr, uid, [x.id for x in msg.vote_user_ids], context=context)
has_voted = False;
for vote in msg.vote_user_ids:
if (uid == vote.user_id.id):
has_voted = True;
author_id = self.pool.get('res.partner').name_get(cr, uid, [msg.author_id.id], context=context)[0]
author_user_id = self.pool.get('res.users').name_get(cr, uid, [msg.author_id.user_ids[0].id], context=context)[0]
partner_ids = self.pool.get('res.partner').name_get(cr, uid, [x.id for x in msg.partner_ids], context=context)
@@ -186,6 +193,8 @@ class mail_message(osv.Model):
'author_user_id': author_user_id,
'partner_ids': partner_ids,
'child_ids': [],
'vote_user_ids': vote_ids,
'has_voted': has_voted
}
def message_read_tree_flatten(self, cr, uid, messages, current_level, level, context=None):
+9 -12
View File
@@ -289,19 +289,16 @@ openerp.mail = function(session) {
render_vote: function(message_id){
var self = this;
var mail_vote = new session.web.DataSetSearch(self, 'mail.vote', self.session.context, [['msg_id','=',parseInt(message_id)]]);
mail_vote.read_slice(['user_id']).then(function(result){
vote_count = result.length;
is_vote_liked = false;
_.each(result, function(vote){
if (self.session.uid == vote.user_id[0]){
is_vote_liked = true;
}
});
this.ds_message.call('message_read', [[parseInt(message_id)]]).then(function(result){
vote_count = 0;
if (result[0].vote_user_ids){length
vote_count = result[0].vote_user_ids.length;
}
parent_element = self.find_parent_element(".oe_mail_msg_vote", message_id);
vote_element = session.web.qweb.render('VoteDisplay', {'msg_id': message_id, 'vote_count': vote_count, 'is_vote_liked': is_vote_liked});
vote_element = session.web.qweb.render('VoteDisplay', {'msg_id': message_id, 'vote_count': vote_count, 'has_voted': result[0].has_voted});
$(parent_element).html(vote_element);
self.add_vote_event($(parent_element));
});
},
@@ -446,8 +443,6 @@ openerp.mail = function(session) {
var self = this;
var _expendable = false;
_(records).each(function (record) {
//Render Votes.
self.render_vote(record.id);
if (record.type == 'expandable') {
_expendable = true;
self.update_fetch_more(true);
@@ -484,6 +479,8 @@ openerp.mail = function(session) {
* - record.is_author: is the current user the author of the record */
display_record: function (record) {
// formatting and additional fields
//Render Votes.
this.render_vote(record.id);
record.date = session.web.format_value(record.date, {type:"datetime"});
record.timerelative = $.timeago(record.date);
if (record.type == 'email') {
+2 -2
View File
@@ -98,12 +98,12 @@
<span class="oe_left oe_mail_vote_string">Votes :<t t-esc="vote_count"/></span>
</t>
<li>
<t t-if="!is_vote_liked">
<t t-if="!has_voted">
<button class="oe_mail_msg_vote_like" t-att-data-id="msg_id" title="Click to Vote.">
<span>+1</span>
</button>
</t>
<t t-if="is_vote_liked">
<t t-if="has_voted">
<button class="oe_mail_msg_vote_like" t-att-data-id="msg_id" title="Click to Unvote." style="background:#DC5F59; padding:1px">
<span>-1</span>
</button>