Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

7

How to know who vote for your questions or answers in Odoo Forum v9 (script update)

By
Axel Mendoza
on 12/16/15, 5:17 PM 856 views

In the old forum version there are some scripts like the posted on this question by @Temur

https://www.odoo.com/forum/help-1/question/how-to-import-odoo-module-87139#answer_92013

That allow you to see the votes of your answer or questions in the Odoo Forum by copy and pasting the JS function in the browser JS console and call the function passing the Post ID.

How to do the same for the new version of Odoo Forum in v9 using the new JS API?

For references here is one of the codes that do the trick

var get_likes_by_post = function(post_id) {
    openerp.jsonRpc('/web/dataset/call_kw', 'call', {
        model: 'forum.post.vote',
        method: 'search_read',
        args: [[['post_id','=',post_id]], ['user_id', 'vote']],
        kwargs: { context: openerp.website.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:

get_likes_by_post(87139)


6

Axel Mendoza

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/16/15, 5:20 PM

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);

Thank you very much for all your valuable contributions, keep up posting!

Ermin Trevisan
on 12/17/15, 2:43 AM

Thanks for appreciate this, it really helps to keep going on

Axel Mendoza
on 12/17/15, 3:01 AM
5

Temur

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 12/17/15, 9:20 AM


And here is one more snippet:


 var get_likes_by_user = function(user_id, separate_posts){

separate_posts = typeof separate_posts !== 'undefined' ? separate_posts : false;

odoo.__DEBUG__.services['web.ajax'].jsonRpc('/web/dataset/call_kw', 'call', {

model: 'forum.post.vote',

method: 'search_read',

args: [[['recipient_id','=',user_id]], ['post_id', 'vote', 'user_id']],

kwargs: { context: odoo.__DEBUG__.services['web_editor.base'].get_context()}

}).then(function(results) {

//_.each(results, function(result) { console.log('Post: ' + result.post_id[0] + ' | ' + result.vote + " by " + result.user_id[1]) });

function vote(x) {

this.user_name = x.user_id[1];

this.user_id = x.user_id[0];

this.vote = parseInt(x.vote);

this.post_id = x.post_id[0];

this.post = x.post_id;

}

res = [];

_.forEach(results, function(x){ res.push(new vote(x)); });

res.sort(function(a,b){

if (a.post_id == b.post_id)

return 0;

if (a.post_id < b.post_id)

return -1;

else

return 1;

});

if (separate_posts){

while(res.length){

post_votes = [];

last_post_id = res[0].post_id;

while (res.length && res[0].post_id == last_post_id) {

post_votes.push(res.shift());

}

console.log('\n\nPost: ' + post_votes[0].post);

console.table(post_votes, ['vote','user_id','user_name']);

}}

else {

console.table(res, ['post_id','vote','user_id','user_name']);

}

})

}


Examples:

get_likes_by_user(342190)
OR

get_likes_by_user(342190, 1)
- here second parameter is for separate posts...

Note: originally above snippets were posted somewhere on this forum, I've slightly modified the original but I would like to credit its author and/or provide link to the original post but I do not remember the exact thread it was posted in, if someone does, feel free to add link here.

Nice

Axel Mendoza
on 12/17/15, 12:34 PM

Check my answer update for how to get negative votes info

Axel Mendoza
on 12/22/15, 1:18 AM

Nice. But I suggest to use

args: [[['recipient_id','=',user_id],['vote', 'in', ['-1','0']]], ['user_id', 'post_id']],
Temur
on 12/22/15, 7:03 AM

instead of

args: [[['recipient_id','=',user_id],['vote', '=', '-1']], ['user_id', 'post_id']],
Temur
on 12/22/15, 7:06 AM

what is the meaning of 0 value of vote in that domain?

Axel Mendoza
on 12/23/15, 12:46 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/16/15, 5:17 PM
Seen: 856 times
Last updated: 6/30/16, 4:29 PM