Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
4548 Vistas

I am trying to follow the instructions in this post: https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-display-needaction-count-only-in-one-menu-90925

If I code it in new api, I receive the error: AttributeError: 'ir.actions.server' object has no attribute 'context'

If I code it in old api, I receive the error: act_ctx = dict(context, **menu.action.context) TypeError: type object argument after ** must be a mapping, not unicode

This leads me to believe that context does not exist for menu.action. What am I doing wrong?

Avatar
Descartar
Mejor respuesta

Hi Matthew, even i was facing the same issue.

In post :

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-display-needaction-count-only-in-one-menu-90925

they have inherited ir.ui.menu class and override get_needaction_get() by adding these extra lines.

if menu.action.context:
    act_ctx = dict(context, **menu.action.context)
else:
    act_ctx = context
res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=act_ctx)


what is happening is menu.action.context is a unicode and in the dict() we are passing these unicode instead of dictionary. Thats why its throwing

Error: object argument after ** must be a mapping, not unicode


Solution is to just convert that unicode to dictionary.

import ast

ast.literal_eval(menu.action.context)


Here is the fix what i did:

try:
     menu_action_context = ast.literal_eval(menu.action.context)
except:
     menu_action_context = {}

if menu_action_context:
    act_ctx = dict(context, **menu_action_context)
else:
    act_ctx = context
res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=act_ctx)


Avatar
Descartar