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

Hello all,

I want to calculate number of users in openerp. here is my code. Please let me know this code is correct or not.

Thanks in advance....

 

        user_ids = self.pool.get('res.users').search_count(cr, uid, ids, context=context)        
        use_user_count = len(user_ids)

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

You cannot pass 'ids' here, you need to pass the domain i.e. the search criteria and search_count will directly return the 'count', so no need to use 'len' function.

It should be like

domain=[]

u_count = self.pool.get('res.users').search_count(cr,uid,domain,context=context)

Here it will not count inactive users, for that you can do the following:

domain=[]

my_context=dict(self._context)

my_context.update({'active_test':False})

u_count = self.env['res.users'].with_context(my_context).search_count(domain)

Hope this helps

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

Thanks....

Tác giả

i tried 2nd method but i get this error NotImplementedError: 'update' not supported on frozendict

I have updated the post. Check it and let me know if that worked

Tác giả

I got this error "AttributeError: 'test.model' object has no attribute 'env'"

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

            rec=self.env['res.users'].search([('active','=','TRUE')])
            print len(rec)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
4229
2
thg 8 25
5422
3
thg 7 25
6719
1
thg 5 25
1033
2
thg 1 25
1782