Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3872 Lượt xem

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"




});

});

});



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 23
1795
1
thg 10 24
1837
1
thg 4 24
1907
2
thg 3 24
2495
0
thg 9 23
1511