Here is the code update for the former script that works for Odoo Forum v9 using the new JS API
var get_likes_by_post = function(post_id) {
odoo.__DEBUG__.services['web.ajax'].jsonRpc('/web/dataset/call_kw', 'call', {
model: 'forum.post.vote',
method: 'search_read',
args: [[['post_id','=',post_id]], ['user_id', 'vote']],
kwargs: { context: odoo.__DEBUG__.services['web_editor.base'].get_context()}
}).then(function(result) {
function vote(x) {
this.user_name = x.user_id[1];
this.user_id = x.user_id[0];
this.vote = parseInt(x.vote);
}
res = [];
_.forEach(result, function(x){ res.push(new vote(x)); });
console.table(res, ['vote','user_id','user_name']);
})
}
Use it like the same:
get_likes_by_post(94628)
*** Update ***
Another handy script that you could find helpful to find the negative votes
var get_negative_votes = function(user_id) {
odoo.__DEBUG__.services['web.ajax'].jsonRpc('/web/dataset/call_kw', 'call', {
model: 'forum.post.vote',
method: 'search_read',
args: [[['recipient_id','=',user_id],['vote', '=', '-1']], ['user_id', 'post_id']],
kwargs: { context: odoo.__DEBUG__.services['web_editor.base'].get_context()}
}).then(function(result) {
function vote(x) {
var self = this;
this.user_name = x.user_id[1];
this.user_id = x.user_id[0];
this.post_id = x.post_id[0];
odoo.__DEBUG__.services['web.ajax'].jsonRpc('/web/dataset/call_kw', 'call', {
model: 'forum.post',
method: 'read',
args: [this.post_id, ['name', 'parent_id', 'content_link']],
kwargs: { context: odoo.__DEBUG__.services['web_editor.base'].get_context()}
}).then(function(post) {
console.log(post);
self.post_url = post.content_link;
if(post.parent_id){
odoo.__DEBUG__.services['web.ajax'].jsonRpc('/web/dataset/call_kw', 'call', {
model: 'forum.post',
method: 'read',
args: [post.parent_id[0], ['name', 'content_link']],
kwargs: { context: odoo.__DEBUG__.services['web_editor.base'].get_context()}
}).then(function(post2) {
console.log(post2);
})
}
})
}
res = [];
_.forEach(result, function(x){ res.push(new vote(x)); });
console.table(res, ['post_url','post_id','user_id','user_name']);
})
};
//call it passing the user id, like:
get_negative_votes(162916);