Odoo Help

0

Get current user ID (no username)

By
Jesús Marco
on 3/12/18, 2:19 PM 627 views

Please, help me to obtain and visualize in my view, the ID of the current user id (numerical value) complying these conditions:

  1. Visualize the ID number of the current user, not the username. Example: "Current User: 4"

  2. Odoo version 8.

Note: I have tried: self.env.user, self.env.user.id, self._uid, self.uid and always getting the username, not the numerical value.

Thanks in advance.


How can I marked this question as solved?? I can´t edit the title of the question.

Jesús Marco
on 3/13/18, 12:20 PM
2

Niyas Raphy

--Niyas Raphy--
--Niyas Raphy--

Odoo Techno Functionalist @ Cybrosys Techno Solutions

Graduation : B-Tech in Computer Science & Engineering from Calicut University (2012 - 2016)


Feel free to contact :  niyasraphyk@gmail.com

Niyas Raphy
On 3/12/18, 11:24 PM

Hi,

Just try like this, as you have to show the Id of the employee in the field, change the Many2one field to a char field and try.

Python :

'logged_user':fields.char('Current User',  default=lambda self: self.env.uid),

XML:

<field name="logged_user"/>

Then you will get like this :




Thanks

I choose this answer as the solution because it was simple and it didn´t force me to create a compute function or something like that.

Jesús Marco
on 3/13/18, 12:09 PM
0
Eli Tehuitzil
On 3/12/18, 3:31 PM

Try self.env.uid

I tried it and get username, not ID (numerical).

On my Py file I have: 'logged_user':fields.many2one('res.users','Current User', default=lambda self: self.env.uid),

and on my view.xml: <field name="logged_user"/>

and as a result I visualize: Current User: Administrator

Jesús Marco
on 3/12/18, 3:53 PM

Another note: each time I edit my Py file, I restart the odoo service and upgrade the module I´m working on, and everytime I restart the odoo service/upgrade the module I know it accepts the changes because of the debug logs I write.

Jesús Marco
on 3/12/18, 3:55 PM

About This Community

This platform 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.

Register

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: 3/12/18, 2:19 PM
Seen: 627 times
Last updated: 3/14/18, 1:05 AM