跳至內容
選單
此問題已被標幟
2 回覆
7639 瀏覽次數

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)

頭像
捨棄
最佳答案

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

頭像
捨棄
作者

Thanks....

作者

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

作者

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

最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
7月 25
4192
2
8月 25
5395
3
7月 25
6696
1
5月 25
1007
2
1月 25
1762