Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

menu.action.context doesn't exist

By
Matthew Watkins
on 3/9/16, 5:55 PM 371 views

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?

0
Ajay Vahan
On 8/5/16, 5:24 AM

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)


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/9/16, 5:55 PM
Seen: 371 times
Last updated: 8/5/16, 5:24 AM