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

I am trying to display a dashboard based on the company that is selected currently in the UI. But no matter the company I select un UI, dashboard is being displayed for the company that is set as Default Company for the user. I checked for the value of request.env.company in controller method and it always returns the company which is set as Default company for that user. So my doubt is what does request.env.company returns? Is it not the company that is currently selected in UI? Any help is appreciated.

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

Tuve un problema parecido, en mi caso los 'records' obtenidos no correspondian a la compañia actual.

La manera que escogía la compañia era mediante @route por ejemplo:

@route(["/my/companies/<model('res.company'):sede>"], auth="public", website=True,)

y dentro del método

request.env.company = sede

my_records = request.env["my.model"].with_company(sede)

con ello podia obtener los 'records' correctos.

Espero te pueda ayudar .

Saludos.

PD: my odoo version: 15

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

Hi,


In Odoo, self.env.company refers to the currently active company context within the user interface. To retrieve a list of company IDs currently selected or allowed for the user, use self._context.get('allowed_company_ids'). For obtaining the company of the currently logged-in user, it's recommended to access self.env.user.company_id directly.


Hope it helps

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

When you say 'currently active company context' is it the one displayed under the section 'Companies' in 'General Settings'?
I am using Odoo 17.

الكاتب

Also for reference, I am trying to fetch the current selected company through request object in controller method.

أفضل إجابة


Hello Varun Karanth,

Hope you are doing well.


For 'request.env.company',  It is depend on which company is select on website.

I have attached a image for that where you can see 'YourCompany' is selected on 'My Website 2'.

So, Whenever I am on website 'My Website 2' and call any controller, It will give me 'YourCompany' company in request.env.company.


This will behave same if I create new website and new company and configure the same as shown below image.


I Hope this information proves helpful to you.

Thanks & Regards,

Email:   odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari 

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

The dashboard is in backend right, if that so why not using self.env.company ?

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

Yes values to be displayed are coming from back-end. Will using self.env.company work in controller method?

الكاتب

To clarify, I am using chart.js to render the graph based on data sent from the backend through controller method(using rpc in javascript code to call controller method).

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
فبراير 18
4821
1
نوفمبر 22
3236
2
أغسطس 25
2757
2
يونيو 25
1234
3
يونيو 25
2668