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

I need to get current user in function fetch_from_channel in chat_manager.js in addon mail

I tried  to use self.session.uid. But its not working in this file.

And i need to get this without using python function

Ảnh đại diện
Huỷ bỏ

Check the context, dataset,

Câu trả lời hay nhất

var session = require('web.session');

user = session.uid


Important: js is asyncronous. Make sure, all the data about the session is uploaded to the time when you are trying to retrieve the data. E.g. console.log(session). What is kept there, when you try to get the active user?

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks, it works fine now

thanks, best.
for addition : in ver 17 it can work this way :

import { session } from "@web/session";

console.log(session.uid)

Câu trả lời hay nhất

In Odoo 12 you can get the current user ID like this

var session = require('web.session');

...
var user = session.uid
console.log('user >>>> ', user)
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

For version 17 OWL we can go this way :

import { session } from "@web/session";

console.log(session.uid)

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


var session = require('web.session');

user = session.user_id


Ảnh đại diện
Huỷ bỏ

I got result while putting session.user_id in my code.

This works fine for me. Thank you MITUL SHAH

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 17
7297
1
thg 9 16
2390
1
thg 6 23
1886
1
thg 5 23
1834
1
thg 10 22
3968