Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How to display needaction count only in one menu ?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
menuitemneedaction8.0
21 Respostes
15581 Vistes
Avatar
Emanuel Cino

I have several menus pointing to a same object. I would like to display a needaction count in the menuitem, but so far I was only able to display the same count in all menuitems pointing to my object.

Is it possible to have a different counts for the same object but different menuitems ? Or at least, is it possible to show the count in only one menuitem and hide it in the others ?

1
Avatar
Descartar
Avatar
Axel Mendoza
Best Answer

Check how it is done in quotations/sale order as example

Edited

===========================================

When you put your model to inherit from the model ir.needaction_mixin, it's because you wanna indicate that there are some records that need an action and to indicate who are those records you need to override the method _needaction_domain_get to return a domain that will be used in combination with the menu action domain to filter the model records to display the count result. In the case of the sale.order it inherit from mail.thread that implements the _needaction_domain_get to display unread messages in the records.

For your case you just need to define a different domain for every menu action for the same object and of course the method _needaction_domain_get that build the domain for select the record count that need an action.

If your requirement it's not based on the domain of the menu action? that affects also your records universe in that menu, then you can go ok by specifying some different value in the context of the menus actions and use the value to build the domain in the method _needaction_domain_get based on the value of the context, something like this:

def _needaction_domain_get(self, cr, uid, context=None):
    if context.get('count_action') == 'menu1':
        return [('active_code','=','1')]
    elif context.get('count_action') == 'menu2':
        return [('active_code','=','2')]
    #else not need for menu3
    return [('active_code','=','3')]

then for the 3 menus you need to put the count_action key with the respective value.

================================================================

How to receive the action context in the _needaction_domain_get? You need to override the get_needaction_data of ir.ui.view to do that by simply copy the original code and changing the right lines, there is no other way. I highlights the changes:

class ir_ui_menu(osv.osv):
_inherit = 'ir.ui.menu'


def get_needaction_data(self, cr, uid, ids, context=None):
""" Return for each menu entry of ids :
- if it uses the needaction mechanism (needaction_enabled)
- the needaction counter of the related action, taking into account
the action domain
"""
if context is None:
context = {}
res = {}
menu_ids = set()
for menu in self.browse(cr, uid, ids, context=context):
menu_ids.add(menu.id)
ctx = None
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.context:
try:
# use magical UnquoteEvalContext to ignore undefined client-side variables such as `active_id`
eval_ctx = tools.UnquoteEvalContext(**context)
ctx = eval(menu.action.context, locals_dict=eval_ctx, nocopy=True) or None
except Exception:
# if the eval still fails for some reason, we'll simply skip this menu
pass
menu_ref = ctx and ctx.get('needaction_menu_ref')
if menu_ref:
if not isinstance(menu_ref, list):
menu_ref = [menu_ref]
model_data_obj = self.pool.get('ir.model.data')
for menu_data in menu_ref:
try:
model, id = model_data_obj.get_object_reference(cr, uid, menu_data.split('.')[0], menu_data.split('.')[1])
if (model == 'ir.ui.menu'):
menu_ids.add(id)
except Exception:
pass

menu_ids = list(menu_ids)

for menu in self.browse(cr, uid, menu_ids, context=context):
res[menu.id] = {
'needaction_enabled': False,
'needaction_counter': False,
}
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.res_model:
if menu.action.res_model in self.pool:
obj = self.pool[menu.action.res_model]
if obj._needaction:
if menu.action.type == 'ir.actions.act_window':
dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or []
else:
dom = eval(menu.action.params_store or '{}', {'uid': uid}).get('domain')
res[menu.id]['needaction_enabled'] = obj._needaction
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)
return res


 

4
Avatar
Descartar
Emanuel Cino
Autor

Thank you, can you at least point me where to look at ? The only thing I can see in sale module is that sale_order inherits from "ir.needaction_mixin"

Axel Mendoza

yes, let me explain a little more

Axel Mendoza

my answer is edited with the explanation

Emanuel Cino
Autor

I tried with the context, but the context defined in the action is not passed to _needaction_domain_get method. I am using version 8 just in case.

Axel Mendoza

Sorry for the delay to respond, you are right, let me complete the answer one more time to allow you to receive the action context.

Axel Mendoza

My first answer was updated to add the needed extension. Odoo forum have the behavior of not notify me about some comments or updates

Emanuel Cino
Autor

Thanks to your answer I was able to make it !! However I didn't have to copy paste the whole method. In version, all I needed to do was this : ``` @api.multi def get_needaction_data(self): res = dict() for menu in self: if menu.action and menu.action.context: new_context = dict() try: new_context = ast.literal_eval(menu.action.context) new_context.update(self.env.context) except: new_context = self.env.context res.update( super(IrUiMenu, menu.with_context(new_context)).get_needaction_data()) return res ```

Emanuel Cino
Autor

Oh this doesn't format well the code in the comments... I will just post it underneath but I accepted your answer. Thanks again !

Avatar
Pawan
Best Answer

Emanuel, in order to show counts in each menu of same object, you can proceed in th eorder below.

'needaction_menu_ref': ['list_of_other_menu_ids_of_same_object']

to your respective Menu's action's context in xml file....

suppose on menu with id 'a' you will have :

'needaction_menu_ref': ['b', 'c']

suppose on menu with id 'b' you will have :

'needaction_menu_ref': ['a', 'c']

and so on...... then add this function to your object inheriting"ir.needaction_mixin":

@api.model

def _needaction_domain_get(self):

    return[('active', '=', True)] # you can modify as per your requirement.....

and you can also refer to similar post: https://www.odoo.com/forum/help-1/question/how-can-i-count-records-in-domain-and-display-it-in-line-with-menu-89943#answer-89945

Hope this helps you.......

2
Avatar
Descartar
Emanuel Cino
Autor

Hey, this is exactly what I don't want to do. I want count in only one menu, or different counts for different menus (but all for same object). I hope it's clearer

Pawan

hi,
your statement:different counts for different menus (but all for same object)
My statement:in order to show counts in each menu of same object i can't get where i misunderstood you...., i gave you the solution to get the [different]counts on different(each n every) menus of same object(but all for same object). Please clear me if i am wrong...
thanks

Pawan

however, apart from all these, you need to provide domain(like for states, [('state', '=', 'draft)] in one menu and so on....) in every actions for the data you want to see in each menu...

Emanuel Cino
Autor

Ok, I thought when reading your answer your solution was to display count on all menus (same count). I will try

Emanuel Cino
Autor

Hi again, I tried but it doesn't work. In fact I have the same domain for different menus (I display the same items but with different views) and I would like to be able to specify different needactions for these menus. There should be a way of returning a different domain in method _needaction_domain_get depending on which action called it. In that sense, Axel Mendoza's answer was close to what I need, unfortunately the context is not passed in _needaction_domain_get method. Do you have any other idea how to achieve this ?

Pawan

the domain which you will pass in the "domain" property of your action, you can get it in your _needaction_domain_get by calling its SUPER function, then you can use it as either to return same value or manipluate it(applying your "If's") as per your wish..... or next thing if you are on odoo 8 , you can browse context using "self.context", for Axel's method.....

Emanuel Cino
Autor

I tried again but calling SUPER inside _needaction returns always [('message_unread', '=', True)] no matter in which action I am. And again, the context inside the method (using self.env.context) does not contain the values I add in the xml action context field. It only contains basic values (language, user, timezone).

Pawan

OK, so for your requirement you can override "_needaction_count()" method, and there you will get the domain passed in your action, which you can use as u want....
def _needaction_count(self, cr, uid, domain=None, context=None):
""" Get the number of actions uid has to perform. """
print domain, res, 'YOUR DOMAIN and TOTAL ROCORD ITEMS (for your manipulations) '
res = super(crm_lead, self)._needaction_count(cr, uid, domain, context)
return res

Emanuel Cino
Autor

_needaction_count gets neither the context... however Axel Mendoza solved the issue.

Avatar
Emanuel Cino
Autor Best Answer

My final code in model ir_ui_menu (inherited) :

@api.multi

def get_needaction_data(self):
res = dict()
for menu in self:
if menu.action and menu.action.context:
new_context = dict()
try:
new_context = ast.literal_eval(menu.action.context)
new_context.update(self.env.context)
except:
new_context = self.env.context
res.update(
super(IrUiMenu,
menu.with_context(new_context)).get_needaction_data())
return res


In my view's action:

<record model="ir.actions.act_window" id="action_follow_sds">

     <field name="context">{'count_menu': 'menu_follow_sds'}</field>
</record>

In my model :

@api.model

def _needaction_domain_get(self):
if self.env.context.get('count_menu') == 'menu_follow_sds':
return [('sds_state', '=', 'sub_waiting')]
return False
1
Avatar
Descartar
Avatar
Marco Costella
Best Answer

Hello,

I had the same problem (openerp v7) and i found this post. I like no one of the proposed solution so i read the code and i found this:

res[menu.id]['needaction_enabled'] = obj._needaction_needaction
res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=context)

You can inherit the function _needaction_count in your object and set the results has you prefer:

def _needaction_count(self, cr, uid, dom, context=None):
context = context or {}
if (dom):
res = len(self.search(cr, uid, dom, context=context))
else:
res = super(todo_todo, self)._needaction_count(cr, uid, dom, context=context)
return res

The dom parameter of the function is the domain of the menu action:

<field name="domain">[('state', '=', 'created')]</field>

If the result of the function is 0 the counter is not show.


I hope this will help!

Ciao

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Get menuitem list Solved
menuitem
Avatar
Avatar
Avatar
3
de des. 21
8228
Clients queue system
8.0
Avatar
Avatar
7
de set. 20
8374
Disabled Menu Items Without using groups
menuitem
Avatar
0
de des. 18
3278
How to delete menuitem? Solved
menuitem
Avatar
Avatar
Avatar
Avatar
Avatar
7
d’oct. 18
23448
odoo 8.0 crash after update crm module
8.0
Avatar
Avatar
1
de nov. 17
4946
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now