Odoo Help

7
8
Avatar

Axel Mendoza

--Axel Mendoza--
13233
| 7 8 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 and 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
Avatar

Temur

--Temur--

3167
| 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

About This Community

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

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 12/16/15, 5:17 PM
Seen: 1984 times
Last updated: 8/19/17, 3:38 AM