Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How can i count records in domain and display it in line with menu ?

Odoberať

Get notified when there's activity on this post

This question has been flagged
4 Replies
10052 Zobrazenia
Avatar
Dr Obx

As I mentioned in title, need count for example all records with state = "in" and add this figure into menu line as it is in Messaging "Inbox"


1
Avatar
Zrušiť
Avatar
Pawan
Best Answer

Dr Obx,

inherit "ir.needaction_mixin" in your class and override _needaction_domain_get()

def _needaction_domain_get(self):
return [('state', '=', 'in')]

 Hope it helps

0
Avatar
Zrušiť
Dr Obx
Autor

Hi Pawan, Why you not responding my questions on Skype :):):) Thanx, I'll try (Student Rob)

Dr Obx
Autor

TypeError: _needaction_domain_get() takes exactly 1 argument (4 given)

Temur

add @api.model decorator to _needaction_domain_get function definition. as follows:

@api.model
def _needaction_domain_get(self):
    return [('state', '=', 'in')]
Temur

or change it to v7 style:

def _needaction_domain_get(self, cr, uid, context=None):
    return [('state', '=', 'in')]
Temur

then it should work... does it?

Dr Obx
Autor

Better, no errors now ;) So what next, how to add the counter into the line ?

Temur

do you actually have some records with state=in right now?

Dr Obx
Autor

Yes, a lot of them ;)

Temur

if you've done all right, then it should already displaying the counter in the menu... no more actions are required.

Temur

do you inherit additionally "ir.needaction_mixin"? what is your inherit statement?

Dr Obx
Autor

_inherit = 'ir.needaction_mixin' @api.model def _needaction_domain_get(self): return[('state','=','in')]

Temur

you should include _name attribute as well, when you inherit from multiple models then it's necessary, you'll get something like:

_name = "a.base.model.name"
_inherit = ["a.base.model.name", "ir.needaction_mixin"]
Temur

"ir.needaction_mixin" should be additional inherit, not the main one... see comment above

Temur

"a.base.model.name" here is the model name you're extending. if you are NOT extending any model, then just add _name parameter:

_name = "my.new.model.name"
_inherit = "ir.needaction_mixin"
...
Dr Obx
Autor

''class iprodstep_log(models.Model): _name = 'iprodstep.log' _inherit = ["iprodstep.log","ir.needaction_mixin"] ''

Temur

so if you're extending some model, use first option... but you'll need to add _name in both cases... and do not forget to restart odoo and update module from Settings/Modules... page. normally it should work already

Temur

is the 'iprodstep.log' existing model you're extending? if so, then it's correct... if it's a new model then use second option, _inherit = "ir.needaction_mixin". I do not know your scenario, so I posted all two options

Dr Obx
Autor

Whatever i do, either first or second scenario still getting errors :(

class iprodstep_log(models.Model):
    _name = 'iprodstep.log'
    _description = 'iprodstep Log'
    _inherit = ["iprodstep.log","ir.needaction_mixin"]

...
    @api.model
    def _needaction_domain_get(self):
        return[('state','=','in')]
Temur

first things first... is the 'iprodstep.log' another model you're extending OR it's a new model you're creating?

Temur

what kind of errors

Dr Obx
Autor

iprodstep.log is a model I'm creating. I'll tell you, just need restore everyting and solve the Server 500 error now :)

Dr Obx
Autor
  File "/usr/share/pyshared/werkzeug/serving.py", line 159, in run_wsgi
    execute(app)
  File "/usr/share/pyshared/werkzeug/serving.py", line 146, in execute
    application_iter = app(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/service/server.py", line 285, in app
    return self.app(e, s)
  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 216, in application
    return application_unproxied(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 202, in application_unproxied
    result = handler(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1281, in __call__
    return self.dispatch(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1255, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/share/pyshared/werkzeug/wsgi.py", line 411, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1413, in dispatch
    ir_http = request.registry['ir.http']
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 339, in registry
    return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 339, in get
    update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 152, in load_module_graph
    models = registry.load(cr, package)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 163, in load
    model = cls._build_model(self, cr)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 595, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 102, in __getitem__
    return self.models[model_name]
KeyError: 'iprodstep.log'

Temur

error you posted is because 'iprodstep.log' is not an existing model, but new one.. as you're not extending any model, then _inherit = "ir.needaction_mixin" is correct option for you

Dr Obx
Autor

Oh i got it, so how can I now assign it to the specified menu ?

Temur

you do not need to.

Temur

it'll be added automatically. you just need to have separated page for your 'iprodstep.log' models, you need ordinary menu for that, nothing special

Dr Obx
Autor

Not really, because at this moment I have a few menus which contain records in state 'in', 'out', 'cancelled' so i have to separate it somehow or create same kind of counters for each state. like in messaging, it separate numbers of messages for specified group. I hope you know what i mean.

Pawan

Rob, for what you what to achieve, you have to add this:
'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...... Hope this helps you.......

Dr Obx
Autor

it doesn't work ;(

    @api.model
    def _needaction_iprodstep_log_pack_menu_get(self):
        return[('in','out','pack')]
Pawan

Rob, don't add this part and implement above mentioned functionality in action's context.....
and in _needaction_domain_get() just return [('active', '=', True)]

Dr Obx
Autor

Aaaaaa hahahahahah i sorted it. It was quiet simple :)

    @api.model
    def _needaction_domain_get(self):
        return[('state','not in',['draft'])]
and now I can see in each menu a number of orders :) The only problem is.... it update the counter only in one menu if you pass the order to another state. every time you want to know the actual states you have to click on the top bar menu
Temur

congrats :)

Avatar
Temur
Best Answer


for count records matching a domain you should use function "search_count", quote from documentation:

search_count(args) → int
Returns the number of records in the current model matching the provided domain.

in your case, it'll be something like,

in v8 style:

count = self.env['model.name.to.search.in'].search_count([('state','=','in')])

in v7 style:

count = self.pool['model.name.to.search.in'].search_count(cr,uid, [('state', '=', 'in')], context=context) 

then in "count" variable you'll have the desired number. adapt it to your case.

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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