Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Correct way: Browse vs Search ?

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
performanceaddonsorm
2 Risposte
42904 Visualizzazioni
Avatar
Mario Arias Badila

Hi,

I have found in official addons that even though a record has a reference to other records (like one2many), and they already have a browse record with the required information, the programmer still uses the search function to get the list of ids from the database.

Example:

Each hr_employee has a field contract_ids, that is a one2many relationship to hr_contract.

If I already have

   employee_data = employee_obj.browse( blah, blah, blah...)

and I want to access the list of contracts for that employee, what is the right way to get it:

a) Use the list I already have on employee_data.contract_ids and get the information from there,

or

b) Execute a search on contract object looking for contracts related to the employee, like:

   contract_ids = obj_contract.search(cr, uid, [('employee_id','=',emp.id),], context=context)

I would think option a), but I have found that in most cases option b) is used in official addons, so I guess there is a reason for that...

What are cons and pros of each aproach ?

3
Avatar
Abbandona
Clément THOMAS

The advantage of first method is that you have an access directly to browse_records. In the second way you must call a browse() method on obj_contracts with your contract_ids to access to their attributes. But I don't know about performances. You must know that many of addons was written in old versions of OpenERP. Maybe browse method was not so efficiently than know...?

Avatar
Serge
Risposta migliore

if you already have that, and no realy need, replace it by a read

employee_data = employee_obj.browse( cr, uid, ids, context=context)

like

for employee in employee_obj.read( cr, uid, ids, ['contract_ids'], context=context):
    #So in employee['contract_ids'], you have a list of all contract id for this employee
1
Avatar
Abbandona
Avatar
Turkesh Patel (tpa)
Risposta migliore

option a is right way as option b dose not make any sense. we can say it is mistake of coding in IMO.

--> there is one big plus point of option a: As it will avoids search on object so it will good if you have lots of records in db.

1
Avatar
Abbandona
Serge

option 1 , is a no sense, browse will read ALL field in db, so performance drop, trace the code, if you have 80 fields in the table, openerp will create a select query for 80 fields. Always avoid Browse, browse is for lazy programmer.

Turkesh Patel (tpa)

what if you have 10-20 lakh records and you fire search query then it will take less time than browse of 80 fields????? in this case search makes no sense.

Serge

No need a search if you already have the IDS, if you do a browse, mean you have IDS, so do a READ not a BROWSE.

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Execute query when installing addon Risolto
modules addons orm query
Avatar
Avatar
2
mag 18
10788
Bug in copy/read function with one2many field in account_move_line that points to one or more other account_move_lines
performance orm bug odoov7
Avatar
1
gen 17
4649
orm.Model browse method memory limit?
performance python orm assets
Avatar
Avatar
1
mar 15
6931
What is the role of Social User and Social Manager in Social Marketing Module. Risolto
performance
Avatar
Avatar
2
nov 25
685
I'm Looking for a real estate Web Design and Development Agency in Dubai
performance
Avatar
Avatar
Avatar
Avatar
Avatar
4
set 25
2024
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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