Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
9 Odpowiedzi
6421 Widoki

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)


Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć

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

Autor

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

Najlepsza odpowiedź


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.

Awatar
Odrzuć
Autor

Nice

Autor

Check my answer update for how to get negative votes info

Nice. But I suggest to use

args: [[['recipient_id','=',user_id],['vote', 'in', ['-1','0']]], ['user_id', 'post_id']],

instead of

args: [[['recipient_id','=',user_id],['vote', '=', '-1']], ['user_id', 'post_id']],
Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
3
lut 25
4598
0
lut 25
1066
1
cze 24
1886
1
maj 24
1488
0
lut 24
1252