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
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    Others
    • 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
  • Help

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

What is 'better': search or browse?

Odoberať

Get notified when there's activity on this post

This question has been flagged
v7ormsearchbrowse
1 Odpoveď
21694 Zobrazenia
Avatar
René Schuster

Two snippets to get the same list of ids:

id_list = [];
for obj in self.browse(cr, uid, ids, context=None):
    for o2m in obj.o2m_field_ids:
        id_list.append(o2m.id);

or:

o2m_obj = self.pool.get('o2m.object');
id_list = o2m_obj.search(cr, uid, [('m2o_field_id','in',ids)]);

Which is faster? 'better'? cleaner? more pythonic? more readable? better style?

EDIT:

An actual example would be to collect all tasks of one or more projects:

I could loop over the projects and collect the tasks (browse the projects), or search for all tasks that belong to the given projects (search in tasks).

I think this can make differences in performance, etc.

 

Thanks.

1
Avatar
Zrušiť
Avatar
Ludo - 21South
Best Answer

Well, I don't think you should use both for the same purposes. If you want just a list of ids to push around, use the search. It will always give you back just ids in a list. If you want to do something with the fields of these records as well, you use the browse. 

 

The top example is very counter-intuitive as well. You already have the ids; self.browse(cr, uid, ids, context=None), so why bother going trough the objects to find that the result of the browse and for-loop is the exact same as the ids you are passing already?

So for example if you need all the partners that are customers:

partner_obj = self.pool.get('res.partner')

partner_ids = partner_obj.search(cr, uid, [('customer','=',True)])

and if you need more information of those partners, feed that list into a browse:

partners = partner_obj.browse(cr, uid, partner_ids)

for partner in partners:

    if partner.active:

         print "It is active"

2
Avatar
Zrušiť
René Schuster
Autor

Thx for the reply. Of course often you can't choose between both options. But I#m not sure you got my first example right. Its not just returning the already avaible ids. I've updated my question with an example.

Ludo - 21South

Aha, now I see. Well in that case, part of my point still stands. If you need just the ids and no more information, the simple search should do the trick. If you know you will be using other information of either project or task (as reference to your example) you will need the browse. Speedwise is should not make much of a difference, unless you are talking about millions of records simultaneously.

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
Related Posts Replies Zobrazenia Aktivita
How to search for several words in products name from sales order? Solved
v7 search
Avatar
Avatar
Avatar
Avatar
8
júl 24
17193
search method : "is not null" criteria
v6.1 v7 orm search v6
Avatar
Avatar
Avatar
2
sep 20
37758
Should sudo work with browse ? Solved
orm search browse searching sudouser
Avatar
Avatar
1
aug 17
9581
Using search count Solved
orm search
Avatar
Avatar
Avatar
2
dec 23
20724
How can I locate the certain SO/PO with the product code/desc?
v7 search
Avatar
Avatar
Avatar
2
mar 15
6516
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