تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
23148 أدوات العرض

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

الصورة الرمزية
إهمال

Check the context, dataset,

أفضل إجابة

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?

الصورة الرمزية
إهمال
الكاتب

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)

أفضل إجابة

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)
الصورة الرمزية
إهمال
أفضل إجابة

For version 17 OWL we can go this way :

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

console.log(session.uid)

الصورة الرمزية
إهمال
أفضل إجابة


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

user = session.user_id


الصورة الرمزية
إهمال

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

This works fine for me. Thank you MITUL SHAH

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 17
7323
1
سبتمبر 16
2395
1
يونيو 23
1921
1
مايو 23
1865
1
أكتوبر 22
4016