Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

does self in model method point on the model structure or on the records ?

Naroči se

Get notified when there's activity on this post

This question has been flagged
recordsselfloopcomputed-fields
1 Odgovori
1696 Prikazi
Avatar
yahya sbini

in this example I am iterating on all records in the model ,but way this iteration if i want to compute the value of field in the current record


    @api.depends("age")

    def _computeHalfAge(self):

        for record in self:

            record.age_days = record.age * 365


0
Avatar
Opusti
Avatar
Cédric Paradis
Best Answer

In this case, 'self' is a recordset. Think of it as an array of records. If you log 'self' before the for loop, you should see something like Model(10,23,54), the numbers being the DbIds for the records present in the recordset.

You're doing the iteration correctly. When model.age changes in 1 or many records, the method _computeHalfAge will be called like so: model._computeHalfAge(Model(id_1, id_2,id_3)) for every record in the recordset. Then, the 'record' variable will be each record in the recordset while iterating.

0
Avatar
Opusti
Ray Carnes (ray)

Good answer. The compute method has to work on both the current record as well as a group of records, since in Odoo there are ways to edit muiltiple records (Multi-edit, Import, Server Action, etc).

yahya sbini
Avtor

Thanks Cédric and Ray ,but is that editing all records is efficient ? Imagine i have 10 Millions records ..... so why the compute function is going to compute 10 Millions times (whether the field is stored or not)?

Cédric Paradis

Ideally, you wouldn't be iterating on all records on a certain model all at once all the time. You would iterate over the subset (recordset) of records that had a change in the "age" field. In any case, computers are very fast at multiplication (and basic arithmetic operations in general) and, while I've never dug through the database interface, I'm almost certain Odoo's ORM has a batched read and write mechanism to retrieve and change the whole recordset at once in the database, reducing the overhead cost of I/O for the operation. If you think about it, every time you open a view, you have to fetch all the records with all their stored fields to check against the domain and filters to keep the desired one. That's a lot more read operation than what you're doing here.

Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Loop through record lines - Expected singleton error - Odoo v8 Solved
stock records loop
Avatar
Avatar
1
okt. 17
7571
Using self.env to go over all module record and create new record in another module Solved
self loop self.pool.get self.env.search
Avatar
Avatar
2
jan. 19
15768
"forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in codes))
fields leads datetime self computed-fields
Avatar
0
jun. 18
9995
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
Avatar
Avatar
1
jun. 25
16843
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
Avatar
Avatar
Avatar
Avatar
3
apr. 25
7434
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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