Skip to Content
Menu
This question has been flagged
2 Replies
2751 Views

i'm building an API with Odoo xmlrpc with NodeJs and i made a function to check if the login already exists in the database but it always returns undefined ?? please help 

The code :

function user_exist(email){
        odoo.connect(function (err) {
                if (err) { return console.log(err); }
                console.log('Connected to Odoo server.');
                var inParams = [];
                inParams. push([['active', '=', true]]);
                var params = [];
                params.push(inParams);


// 4- Read

                odoo.execute_kw('res.users', 'search', params , function (err, value) {
                        if (err) { return console.log(err); }
                        var inParams = [];
                        inParams.push(value); //ids
                        inParams.push(['login']);
                        var params = [];
                        params.push(inParams);

                        odoo.execute_kw('res.users', 'read', params, function (err2, value) {
                                if (err2) { return console.log(err2); }
                                for (let i = 0; i < value.length; i++) {
                                        if (email == value[i].login){
                                                return "User exist"
}

}
                                return "user doesn't exist"




});

});

});



Avatar
Discard
Author Best Answer

i'm not having a problem in getting the full list, but the return value isn't the boolean value, it's as if there is no return at all, but if i console.log(value) i do get the full list, i guess i'll need an async function for that maybe , but thanks anyways.

Avatar
Discard
Best Answer

I once did that with python but with a different approach.

def print_user(current_user):
a = current_user.copy()
user_to_print = {}
for key, value in a.items():
if 'image' not in key:
user_to_print[key] = value

existing_users = []
list_of_users = models.execute_kw(db, uid, password, 'res.user', 'search_read', [[]])

for user in list_of_users:
print_user(user)
existing_users.append((user['id'], user['name'], user['login']))

That way you get the full list, otherwise check the model "res.user" for other ways.

Hope that helps.

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 23
1067
1
Oct 24
266
1
Apr 24
508
2
Mar 24
734
0
Sep 23
575