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

Fields definitions parameter change_default?

Abonare

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

Această întrebare a fost marcată
fieldsparameters
6 Răspunsuri
20424 Vizualizări
Imagine profil
Zbik

I have not found any documentation on the parameter change_default. Can anyone knows its meaning?

Example from sale.py:

'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True, readonly=True, states={'draft': [('readonly', False)]}, ondelete='restrict'),

1
Imagine profil
Abandonează
Imagine profil
Jérémy Kersten (jke)
Cel mai bun răspuns

Hi,


A example will maybe help you...

Take a model with a field A, and a field B.  

The field B has change_default set to True.


Now, if you go to the form view in debug mode and set a default value for the field A. You can set this value depending on the value of B...



5
Imagine profil
Abandonează
Zbik
Autor

Thank you very much for this helpful picture and answer. Now I understand :)

Imagine profil
Ivan Elizaryev
Cel mai bun răspuns

I made a video with explanation https://youtu.be/y82IftkWdCM

2
Imagine profil
Abandonează
Imagine profil
Axel Mendoza
Cel mai bun răspuns

Well I haven't see the answer of @jke before find mine and I think that this question haven't had an answer. That's a way to use it. I will write my own version that could help developers more and also is more technical to express value change rules by xml ir.values record. I don't mean that @jke answer is incorrect. Just that these are the technical insides.

The other way is by writing ir.values records with type='default' and key2='field_with_change_default=value' for the model in question. It will cause that the name and value of those ir.values records that match the key2 value condition will be used as a result of the change of the field_with_change_default. As example you could use the field zip of the res.partner model that has defined with change_default=True. Writing some records like this:

<record model="ir.values" id="partner_zip_name">
<field name="name">name</field>
<field name="value">Axel</field>
<field name="key">default</field>
<field name="key2">zip=5000</field>
<field name="model">res.partner</field>
</record>
<record model="ir.values" id="partner_zip_phone">
<field name="name">phone</field>
<field name="value">+99999999</field>
<field name="key">default</field>
<field name="key2">zip=5000</field>
<field name="model">res.partner</field>
</record>

Will cause that when the zip code in a partner is set to 5000 the name will be changed to 'Axel' and the phone will be changed to '+99999999' like if you have an onchange to return those values and also this could rewrite an existing value returned by an onchange execution that get executed before the code responsible for this, runs. Here is the js code that allow this behavior for references. 

if (field && field.change_default) {

var value_;

if (response.value && (fieldname in response.value)) {

// Use value from onchange if onchange executed

value_ = response.value[fieldname];

} else {

// otherwise get form value for field

value_ = self.fields[fieldname].get_value();

}

var condition = fieldname + '=' + value_;

if (value_) {

defs.push(self.alive(new instance.web.Model('ir.values').call(

'get_defaults', [self.model, condition]

)).then(function (results) {

if (!results.length) {

return response;

}

if (!response.value) {

response.value = {};

}

for(var i=0; i<results.length; ++i) {

// [whatever, key, value]

var triplet = results[i];

response.value[triplet[1]] = triplet[2];

}

return response;

}));

}

}


2
Imagine profil
Abandonează
Zbik
Autor

It is actual in new api? My api@onchange are tirggered without this parameters (with change_default = False)? In old api I did never use this parameter too, but on_change works? I think I do not understand :(

Axel Mendoza

I already know how that works, very tricky, but works. let me rewrite my answer on that with an example of how to test it

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
Related Posts Răspunsuri Vizualizări Activitate
How to display a red * for required fields
fields
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
mai 25
3267
How to display a red * for required fields
fields
Imagine profil
Imagine profil
1
apr. 25
2351
one2one relational field Rezolvat
fields
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
sept. 24
15984
I cannot see custom field in lead form
fields
Imagine profil
Imagine profil
2
feb. 24
3405
calculated fields
fields
Imagine profil
Imagine profil
1
iul. 23
3443
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