Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

What should onchange methods do and return?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
1 Răspunde
9779 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Leonardo Donelli
Autor

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

Imagine profil
Leonardo Donelli
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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