Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Conditionally display or hide a field in a view

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
12 Odpowiedzi
134454 Widoki
Awatar
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
Awatar
Odrzuć
Sehrish

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

Awatar
Francesco OpenCode
Najlepsza odpowiedź

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
Awatar
Odrzuć
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?

Awatar
Dharmesh Rathod
Najlepsza odpowiedź

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
Awatar
Odrzuć
oumaima
Autor

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

Awatar
Andreas Maertens
Najlepsza odpowiedź

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
Awatar
Odrzuć
Ankit H Gandhi(AHG)

Nice Its working good..

Awatar
Nikhil Krishnan
Najlepsza odpowiedź

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
Awatar
Odrzuć
OpenGest.Solutions

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

Awatar
oumaima
Autor Najlepsza odpowiedź

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
Awatar
Odrzuć
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 :)

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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