Skip to Content
Menu
This question has been flagged

I want to use _needaction_domain_get to display needaction count on my menuitem.

I know that _needaction_domain_get function only can be displayed on "ir.actions.act_window" model of actions, but I use "ir.actions.server" model for my menuitem's action and I can't change it because of my implementation.

Do anyone know how can I display the number of records on a server action menuitem ?


Avatar
Discard
Author Best Answer

I found the answer and I used it and it is working very well now !!

if you use "ir.actions.server" model for your action, you cant display record count on your menuitem in view. for this issue, you can override "search_read" function and implement your ir.actions.server function that you had implemented. and change the "ir.actions.server" model to "ir.actions.act_window" model. now you can use _needaction_domain_get or _needaction_count functions for your purpose.

def search_read(self, cr, uid, domain=None, fields=None, offset=0, limit=None, order=None, context=None):

        record_ids = self.search(cr, uid, domain or [], offset=offset, limit=limit, order=order, context=context)

        if not record_ids:

            return []

        if fields and fields == ['id']:

            return [{'id': id} for id in record_ids]  

        read_ctx = dict(context or {})  

        read_ctx.pop('active_test', None)  

        result = self.read(cr, uid, record_ids, fields, context=read_ctx) 

        if len(result) <= 1:

            return result

        index = dict((r['id'], r) for r in result)

        return [index[x] for x in record_ids if x in index]

Avatar
Discard
Related Posts Replies Views Activity
21
Jul 17
13601
1
Oct 16
3041
1
Sep 21
2316
2
May 17
3131
0
Jul 22
1250