Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

[SOLVED] How to do a 'where' in self.env[].search() ?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
envsearch()
2 Antwoorden
28723 Weergaven
Avatar
Quentin Villanova

Hi !

I'm new to Odoo 13 and Python so everything is a bit confusing at the moment.

My problem is that I need to do a request like "SELECT ... FROM ... WHERE ...", but I don't understand how I should do it here.

I have the first part which looks like that "self.env['my.table'].search([('the_this_i_want')])".

I would like to add something like "self.env['my.table'].search([('the_thing_i_want')]).where([('id','=',self.id)])".

Thanks.


0
Avatar
Annuleer
Avatar
Răzvan Anastasescu
Beste antwoord

What you put in search parameter (called domain) it's your where criteria.

You really should read the ORM documentation about domain search

The domain it's written in Polish Notation system, because you can normalize (stringify) the search string (useful from client-side) - more in this post.

For your example:

self.env['my.model'].search([('id', '=', self.id)])

The same (searching by id or a list of ids) can also be done using special browse method like this

self.env['my.model'].browse(self.id)
self.env['my.model'].browse([1, 2, 3])

You have to be careful because browse doesn't check if the record really exists in the DataBase, if you want to be sure it exists, you can use exists() method after it, like this:

self.env['my.model'].browse([1, 2, 3]).exists()

By default, if you write multiple conditions, they are treated as AND

self.env['my.model'].search([('my_field', '=', 'value'), ('my_other_field', '!=', False)])

To build more complex searches, you really have to check documentation, understand how to write complex domains using RPN (with ORs and ANDs) and look in Odoo code for more examples

3
Avatar
Annuleer
Ray Carnes (ray)

Great answer! I updated it to add a link to a post explaining Polish Notation as it applies to Odoo domains.

Avatar
Quentin Villanova
Auteur Beste antwoord

Hi, thanks a lot for your reply.

Ok so it gives me some ligth on my problem. So I put my criteria in "search()", but if I do that it returns me an id, but it's not the thing I want.

I should give you a more precise example.

I want a date stored in my DB, in a table called 'ticket'. But it want this date depends on a specifique id.

So I should do something like : "self.env['ticket'].search([('id','=',self.id)])"

But where do I say that I want the "date" and not the id ?

In SQL it would looks like : "SELECT date FROM ticket WHERE id = self.id.

Thanks a lot for your help.

1
Avatar
Annuleer
Marcos Oitabén

It returns a ticket object, not only the id. (But if you try to print it, you will only get the id printed)
ticket = self.env['ticket'].search([('id','=',self.id)])
ticket.name_of_field
eg: ticket.name, ticket.date, ticket.id

Quentin Villanova
Auteur

I didn't know that ! OMG tanks a lot, you save me precious time !

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
How do I set environment variables when Odoo Upgrade fails?
upgrading env
Avatar
2
sep. 24
44
Multicompany Issue
multicompany env
Avatar
Avatar
Avatar
2
aug. 24
1961
Object has no attribute 'env' error when trying to use self.env. I want to run code on module install (via init). What's the best approach? Opgelost
init env
Avatar
Avatar
Avatar
6
aug. 18
21064
I want to create new self.env.<something>
env v15 v17
Avatar
0
dec. 23
17
How to trigger onchange when creating records through server in V13 Opgelost
onchange env v13
Avatar
1
apr. 24
8019
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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