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

I want to block users in company A (id: 1) from creating partners. I have used self.env.user to get the current user (user A) but the problem is even a user's company_id is 2 (company B), it is still detected as 1 and is blocked from creating partners.

The Administrator user's current company is currently set as company A (id: 1). When I switch the Administrator user's current company to company B (id: 2), the problem above is gone and user A can now create partners .

Why is self.env.user.company_id getting the company_id of Administrator instead of user A? 

Note: Administrator and user A is logged in in different computers.

Here is the code:

    @api.model

def create(self,vals):

if self.env.user.company_id.id == int('1'):

    raise UserError("You are not allowed here")

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

first of all, instead of using the company ID to determine if the users can create partners, i'd use security rules, or at the very least, a boolean on the company. But this does not seem to be the problem here..

Is there any chance you call the create() method using sudo? could you check self.env.user.name to check if you logged in as user A?

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

I seem to have called self.sudo()._lead_create_contact.  I guess that's it. Thanks!


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 6 23
21251
3
thg 6 20
52472
1
thg 3 15
5494
1
thg 3 15
7984
1
thg 3 15
4865