Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How to display needaction count only in one menu ?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
menuitemneedaction8.0
21 Besvarelser
15563 Visninger
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
Kassér
Avatar
Axel Mendoza
Bedste svar

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
Kassér
Emanuel Cino
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Bedste svar

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
Kassér
Emanuel Cino
Forfatter

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
Forfatter

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

Emanuel Cino
Forfatter

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
Forfatter

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
Forfatter

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

Avatar
Emanuel Cino
Forfatter Bedste svar

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
Kassér
Avatar
Marco Costella
Bedste svar

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
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Get menuitem list Løst
menuitem
Avatar
Avatar
Avatar
3
dec. 21
8223
Clients queue system
8.0
Avatar
Avatar
7
sep. 20
8371
Disabled Menu Items Without using groups
menuitem
Avatar
0
dec. 18
3265
How to delete menuitem? Løst
menuitem
Avatar
Avatar
Avatar
Avatar
Avatar
7
okt. 18
23442
odoo 8.0 crash after update crm module
8.0
Avatar
Avatar
1
nov. 17
4942
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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