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.

0

How to get current user's password in POS (js file) odoo 8

By
NhuVanTran
on 5/14/15, 1:25 PM 1,529 views

Hi all,

I want to get current user's password in POS module in Odoo 8. Because default loader which loaded database didn't load user's password. So, I used fetch for do that. Unlucky, It didn't work. Can any one help me?

Here is my code :

var password = ' ';
var loaded = fetch('res.users', ['id', 'name', 'password'],[['id', '=', instance.session.uid]]).then(function(users){
     password = users[0].password;
});
alert(password);

Whole code are in a function and when I click a button, this function will be called. Where is my wrong?


Thanks


1
Yogesh
On 5/14/15, 2:59 PM

I don't know why would you need password of user but I would suggest you don't use fetch()

1. It needs server connection each time it fetches and POS is supposed to run without server connection once it is loaded
2. fetch returns async call you won't be able to return value to another function without passing a call back.

I suggest you to add password field in model 'res.users' for it be available in POS session, you can do it with inheritance like



module.PosModel.prototype.models.filter(function (m)
        { return m.model === 'res.users'; }).map(function (m) {
              return m.fields.push('password'),
         m;
});



this way password will be available in your POS session and you will not need to fetch it every time from server which would need connection to server.

then you can access it something like

this.pos.user.password;



cheers ;-)

0
NhuVanTran
On 5/14/15, 3:26 PM

Hi, I try to access as yours, but the password is empty. I also try to change user's password but I can't get it.

I can access login, signature's value or something like that in model "res.user". But I can't get value of password or new_password, I got blank in this case. The value same ""

It must not be blank, also "this.pos.user.password" might change depending on the function scope where do you want to access value, if it is saying undefined or "" ?? if it is undefined it means your field is not available to access but if it says "" then congratulations you have added 'password' field in POS, in that case try adding other field eg: 'login' and access its value, if you don't get put a breakpoint on the line where do you want to access its value and debug it. good luck :)

Yogesh
on 5/14/15, 11:38 PM
Hi Yogesh,

I can access login, signature's value or something like that in model "res.user". But I can't get value of password or new_password, I got blank in this case.

2015-05-15 10:38 GMT+07:00 Yogesh <yogeshkushwaha4-gmail-com@mail.odoo.com>:

It must not be blank, also "this.pos.user.password" might change depending on the function scope where do you want to access value, if it is saying undefined or "" ?? if it is undefined it means your field is not available to access but if it says "" then congratulations you have added 'password' field in POS, in that case try adding other field eg: 'login' and access its value, if you don't get put a breakpoint on the line where do you want to access its value and debug it. good luck :)

--
Yogesh
Sent by Odoo S.A. using Odoo about Forum Post False



--
Trần Như Văn
MSSV: 51104177
K11 Bách Khoa Tp.HCM
Khoa: Khoa học và Kĩ thuật máy tính
NhuVanTran
on 5/14/15, 11:48 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: 5/14/15, 1:25 PM
Seen: 1529 times
Last updated: 5/15/15, 10:34 AM