Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
7653 Weergaven

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)

Avatar
Annuleer
Beste antwoord

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

Avatar
Annuleer
Auteur

Thanks....

Auteur

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

Auteur

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

Beste antwoord

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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
jul. 25
4208
2
aug. 25
5405
3
jul. 25
6702
1
mei 25
1016
2
jan. 25
1775