Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
8 ตอบกลับ
40773 มุมมอง

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.

คำตอบที่ดีที่สุด

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.

คำตอบที่ดีที่สุด

You can use below code.

context = self._context

current_uid = context.get('uid')


อวตาร
ละทิ้ง

Sometimes this returns False (at least in Odoo 11)

คำตอบที่ดีที่สุด

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

ผู้เขียน

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.

คำตอบที่ดีที่สุด

Hello,

You can use below code.

context = self._context

current_uid = context.get('uid')

user = self.env['res.users'].browse(current_uid)

Hope this help you.

Best Thanks,

Ankit H Gandhi.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 25
1495
0
ม.ค. 25
3619
1
ส.ค. 23
14981
change password แก้ไขแล้ว
1
ส.ค. 23
13631
1
ก.ค. 23
10611