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

What should onchange methods do and return?

Odoberať

Get notified when there's activity on this post

This question has been flagged
1 Odpoveď
9792 Zobrazenia
Avatar
Leonardo Donelli

I see a lot of onchange methods in the modules, but I'm not clear on their purpose and what they should return.

0
Avatar
Zrušiť
Leonardo Donelli
Autor

Doc question, feel free to edit and add in any more information guys.

Avatar
Leonardo Donelli
Autor Best Answer

Version 7 and lower, the API for onchange methods are different for version 8+

The onchange method are server side functions called by the client when a field in a form view is changed.
They should be used to help the user during data input, allowing him to work faster.

The onchange methods can change the data of all the record fields, not only the field that was changed. If an onchange method changes the value of another field (with the 'value' dict key we'll see in a bit) it will trigger the onchange method of that field, if any. So pay attention to not create onchange loops.

Onchange methods can show errors and/or change fields domain/values by returning a dictionary with one of more of these keys:

  • `warning`
    • Used to show an error popup, useful for example for alerting the user that the value he inserted is invalid.
    • The value should be a dict in the form {'title': <title>, 'message': <message>} where <title> will be the title of the error popup and <message> the error message.
    • This doesn't replace server-side validation: even if the client shows a popup error and doesn't accept the value the user could send a bad value with a direct RPC call, request tampering and other ways..
       
  • `domain`:
    • Used to change the domain of a relational field. Useful you have a relational field B which options should be related to the value of field A: you can write and onchange method on field A that returns a new domain for field B according to the new value. For example, if you have a field "company" and a field "contact" you can make an onchange method that when you change the company will limit the options of "contact" to only people of that company.
    • The value should be in the form {<field>: <domain>, <field>: <domain>, ...}, where field is the name of the field you want to update and domain is the new domain, in the usual domain notation.
       
  • `value`:
    • Used to change the value of a field. Onchange methods can change values even if invisible and readonly fields. (but if the fields are readonly the values won't be saved: it should be seen only as a visual hint).
    • The value should be in the form {<field_name>: <value>, <field_name>:  <value>, ...} and value should be in the correct form according to the field type. You can even change the fields of a relational field by using the correct write syntax. For example, you can update the quantity field of all the lines of a sale order.
    • This doesn't replace functional fields and bussiness logic: as with `warning`, the user could bypass the automaatic value set by onchange if he wanted to.

An example of a complete onchange return dict structure (assume the model is sale_order):

{
    'warning': {'title': 'Error!', 'message': 'Something went wrong! Please check your data'},
    'domain': {'partner_shipping_id': [('parent_id', '=', 42)]},
    'value': {
        'partner_id': 42,
        'note': 'I was changed automatically!',
        'order_lines': [
            (1, 13, {'discount': 30, 'quantity': 10}),
            (1, 14, {'discount': 15, 'quantity': 34}),
            ...
        ]
    }
}

 

 

1
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