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

I've try this: 

[('company_id','=',company_id)]

self.env.company_id 

self.env.user.company_id

But those all 3 ways are leaded to default company, but not current company.


Please help, thanks.

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

self.env.context.get('company_id')

Why not get the company in context ?

Tác giả

Derick: how did you use self.env.context.get('company_id') in domain of record rule?

Câu trả lời hay nhất
env.context['allowed_company_ids'] and env.context['allowed_company_ids'][0]


allowed_company_ids is a list of integers representing the ID of each Company:


Example 1 - 

env.context['allowed_company_ids'] = [1,2,3]
env.context['allowed_company_ids'][0] = 1

 


Example 2 - 

env.context['allowed_company_ids'] = [2,1,3]
env.context['allowed_company_ids'][0] = 2



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

Hello,

You can get current company from self.env.user.company_id. Company id will change according to the selection in the company switcher.

Thank you


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

thanks for reply, but as i check, the self.env.user.company_id is select default company instead of current company. is there something i'm missing?

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

Hello,

You have to try this domain [('company_id', 'in', company_ids)]

You can get active company ids in company_ids.

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

Sorry i've tried that, but company_ids is related from self.env.companies.ids and it showing full of Allowed Companies as the picture above, not current company.
http://i.imgur.com/W2YlCur.png

If you select multiple companies from the user then you can get those company ids in company_ids. I recently used this domain.

Tác giả

hmm, i do use multiple company, but as i check, that company_ids are return allowed companies. if i select company A, then i should only get company A in domain.

You can get allowed company ids in user.allowed_company_ids

Tác giả

thanks you but that's not what i'm asking, i just wanna know about CURRENT COMPANY.

Tác giả

matter of fact, your solution is working perfectly for my request because we should get all the allowed companies instead of current company.

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

self.env.companies

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

You can use:

self.env.company

And not:
self.env.user.company_id


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

yep it works. <3 thank you

Tác giả Câu trả lời hay nhất

As i check, if we use context to get current company, and in case we using multi company, we can only get the first company.

In that case, we should use company_ids to get all the companies of user instead.

Example:



['|',('company_id','in',company_ids),('company_id','=',False)]


Hope it's help.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 24
1565
1
thg 9 22
3096
1
thg 5 19
4072
1
thg 9 25
1971
1
thg 6 25
1998