Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

Conditionally display or hide a field in a view

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
12 Antworten
134444 Ansichten
Avatar
oumaima

Hi everyone, I asked please about a question in the file.xml how i can display a view depending on a field. for example,i have a module with a field married or not.i want to have a special view following the field

thank's

8
Avatar
Verwerfen
Sehrish

How to visible and invisible fields in odoo: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

Avatar
Francesco OpenCode
Beste Antwort

In OpenERP is possibile to show or hide field in relation to another field (or fields) value. For example, if you have married field and boyfriend_name as field to show if married is true, you can use this system:

<field name="boyfriend_name" attrs="{'invisible':[('married', '!=', False)]}" />

You're telling to OpenERP to hide ({'invisible':...) the field boyfriend_name if married is not false (it's true!!)

Another example is the comparation with another type of field. For example a selection.

<field name="boyfriend_name" attrs="{'invisible':[('married', '!=', 'selection_key')]}" />

With this system you can create your view dinamically based on your field value

21
Avatar
Verwerfen
Voathnak Lim

Hello, could you tell me how can i do that if the married field is in on another model?

Francesco OpenCode

If the field is in another class, you must insert a related field in the current class and set the attrs on this one.

Manjunath

It works great.

OpenGest.Solutions

Exemple for label: http://gitlab.opengest.fr/opengest/odoo/blob/master/addons/account/views/account_invoice_view.xml#L233

Exemple for div:

http://gitlab.opengest.fr/opengest/odoo/blob/master/addons/account/views/account_invoice_view.xml#L227

Exemple for field:

http://gitlab.opengest.fr/opengest/odoo/blob/master/addons/account/views/account_invoice_view.xml#L250

Exemple for button:

http://gitlab.opengest.fr/opengest/odoo/blob/master/addons/account/views/account_invoice_view.xml#L351

Jérôme Thériault

not visible when condition is not false... *head explodes*

Benoit Frisque

Hello, I have tried to compare to a string but it does not work:
<field name="x_studio_company_name_1" optional="show" attrs="{'invisible': [('location_id', '!=', 'Partner Locations/Customers/Rented out')]}"/>

Could you help me?

Avatar
Dharmesh Rathod
Beste Antwort

Hi,

You are using following which is correct for selection field:

attrs="{'invisible':[('lang_mat', '!=', 'eng')]}"

You can use another operators like : 'in' or 'not in' and check.

Email : info@acespritech.com
Skype : acespritech

5
Avatar
Verwerfen
oumaima
Autor

Thank you for your answer it works now...I had an error on the bug windows :)

Avatar
Andreas Maertens
Beste Antwort

You can add an invisible field on your view (invisible="1") relating to a function field in your model. There you can evolve by anything you want and return a stringm bool or number and so in to evaluate if another field is visible or maybe readonly:

The View:

<field name="write_if_manager" attrs="{'readonly':['|',('is_manager', '==', 'false'),('state','not in','['draft']') ] }/>
<field name="is_manager" invisible="1"/>

The class looks like

class classname(osv.osv): 
    ...
    def _is_manager(cr, uid, ids ...
        res = {}
        for this_id in ids:
            if obj_users.has_group(cr, uid, 'MANAGER-GROUPNAME'):
                res[this_id] = manager
        return res
    ...
    _columns = {
        'is_manager':fields.function(_is_manager, type='boolean' ...
        'write_if_manager':fields.char( ...)
3
Avatar
Verwerfen
Ankit H Gandhi(AHG)

Nice Its working good..

Avatar
Nikhil Krishnan
Beste Antwort

I have an issue please help me.

<record id="view_order_form_inherit" model="ir.ui.view">
 <field name="name">sale.order.form</field>
 <field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
 <field name="arch" type="xml">
<xpath expr="//field[@name='payment_term_id']" position="after"> 
   <field name="head_option"/>
</xpath>
    <xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="before">
         <field name="head" attrs="{'required':[('head_option','=',True)], 'invisible':[('head_option','=',False)]}"/>
</xpath>

he head option is a Boolean field that is in the sale order. and head option is in the sale order_line tree view..

so attrs can't work.
replay ur answers,...

1
Avatar
Verwerfen
OpenGest.Solutions

You shoud create a related field. Exemple: http://gitlab.opengest.fr/opengest/odoo/blob/8.0/addons/sale/sale.py#L945

Avatar
oumaima
Autor Beste Antwort

Hi,thank u for your answer;it work's with a boolean fields but i have an error when the type of field is a selection it doesn't work...

file.py

class student(osv.osv): 
    _name = 'student'
    _order = 'name, prenom'
    _description = 'Informations sur l etudiants'
    _columns = {
        'name': fields.char('Nom Famille', size=64),
        'prenom': fields.char('Prenom', size=64),
        'married':fields.boolean('marri'),
        'boy':fields.char('boyfriend',size=30),
        'lang_mat':fields.selection([('eng','English'), ('fr','French')], 'Langue Maternelle'),
        'email':fields.char('E-mail',size=14),
    }

student()

file.xml

<openerp> <data> <menuitem name="marriedbis" id="menu_stage_parent"/>
<menuitem name="enseignant" id="menu_enseignant_parent1" parent="menu_stage_parent"/>

<record model="ir.ui.view" id="view_school_student_form">
    <field name="name">student.form</field>
    <field name="model">student</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="Information Eleve">
                    <field name="name" colspan="6" />
                    <field name="prenom" colspan="6"/>  
                    <field name="married" colspan="6"/> 
                    <field name="lang_mat" colspan="6"/>    
                    <field name="boy" attrs="{'invisible':[('lang_mat', '!=', 'eng')]}" />
      </form>
    </field>
</record>


<record model="ir.ui.view" id="view_school_student_tree">
    <field name="name">student.tree</field>
    <field name="model">student</field>
    <field name="type">tree</field>
    <field name="arch" type="xml">
        <tree string="stages.enseignant">
            <field name="name"/>
            <field name="prenom"/>
        </tree>
    </field>
</record>
<record model="ir.actions.act_window" id="action_school_student_form">
    <field name="name">Eleves</field>
    <field name="res_model">student</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>

<!--  Et finalement il y a le menu qui contient l'action pour ouvrir la vue tree de ton module -->

<menuitem action="action_school_student_form" id="menu_stages_enseignant" parent="menu_enseignant_parent1" />

</data> </openerp>

0
Avatar
Verwerfen
Francesco OpenCode

The attrs values works witrh all the type of field. If you nedd to hide a field in relation a selection you must compare che field to show/hide with the selection field. I've updated my answer.

oumaima
Autor

Thank you for you're answer;it works now :)

Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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