Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Conditional invisible field...

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
selectioninvisibleconditionals
2 Antwoorden
17316 Weergaven
Avatar
Alfa y Omega Pachuca

In Odoo 9, i am using on_change function and i need to hide some custom fields in view sale order

in models.py i have:

...

#Selecction Field

b = fields.Selection([('hide', 'Hide'),('nohide', 'Not Hide'),('choiceoption', 'Choice Option')], default='choiceoption')

b_value = fields.Char('Value', default='Hello')

b_unit = fields.Char('Unit', readonly='True', default='World')

#Function

def on_change_b(self,cr,user,ids,b,b_value,b_unit,context=None):

if b=='choiceoption':

v = {'b_value': 'Choice Option', 'b_unit': 'Choice Option'}

return {'value': v}

elif b=='nohide':

v = {'b_value': 'No Hide Field b_value', 'b_unit': 'No Hide Field b_unit'}

return {'value': v}

else:

v = {'b_value': 'Yes Hide Field b_value', 'b_unit': 'Yes Hide Field b_unit'}

return {'value': v}

...

in templates.xml i have:

...

<field name="b" on_change="on_change_b(b, b_value, b_unit)" />

<field name="b_value" />

<field name="b_unit" />

...

1.- How i can hide the field "b_value" and "b_unit" when i choice "Hide" in the selection field, i think this must be writed in the function "on_change_b" but i do not know how doit the code, maybe with "attrs"


2.- How to initialize a field with invisible = yes for default like:

fieldxyz = fields.Char('This is Field XYZ', default=This is the value of fieldxyz', attrs="{'invisible':true}") <---This is correct?



0
Avatar
Annuleer
Avatar
Akhil P Sivan
Beste antwoord

Hi,

To use attrs you may try like this in your xml file:

<field name="b" />

<field name="b_value" attrs="{'invisible':[('b','==','hide')]}" />

<field name="b_unit" attrs="{'invisible':[('b','==','hide')]}"/>


To hide a field, you can use invisible="1" attribute in xml file:

for eg:

<field name="b_unit" invisible="1" />


I tried to correct your code, so that you may understand the syntax of onchange in new api:

from openerp import models, fields, api
class SaleOrder(models.Model):    
    _inherit = 'sale.order'         
    b = fields.Selection([('hide', 'Hide'),('nohide', 'Not Hide'),('choiceoption', 'Choice Option')], default='choiceoption')    
    b_value = fields.Char('Value', default='Hello')    
    b_unit = fields.Char('Unit', readonly=True, default='World')         
    
    @api.onchange('b')

def _on_change(self):

         if self.b=='choiceoption':             

             self.b_value = 'Choice Option'

             self.b_unit = 'Choice Option'         

        elif self.b == 'nohide':             

             self.b_value = 'No Hide Field b_value'

             self.b_unit = 'No Hide Field b_unit'         

        else:

            self.b_value = 'Yes Hide Field b_value'

            self.b_unit = 'Yes Hide Field b_unit' 

3
Avatar
Annuleer
Alfa y Omega Pachuca
Auteur

Thank you Akhil, your code works for me :-)

Avatar
ABU K
Beste antwoord

    Refer Onchange in Odoo9 New API

Your onchange syntax is not correct ,First chk that one




0
Avatar
Annuleer
Alfa y Omega Pachuca
Auteur

Thank you Dep for your advise, i will learn more about this.

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
how to hide the color column that refer to division selection ?
on_change selection invisible
Avatar
Avatar
1
mrt. 15
5377
How to hide Selection Field Options based on condition : Opgelost
fields selection invisible odooV11
Avatar
Avatar
Avatar
5
mrt. 24
20391
how to add values dynamically in selection fields? Opgelost
selection
Avatar
Avatar
Avatar
Avatar
Avatar
4
dec. 23
23309
Dynamically change choices in selection fields Opgelost
selection
Avatar
Avatar
Avatar
Avatar
Avatar
5
jul. 24
16702
Working with fields.selection values Opgelost
selection
Avatar
Avatar
1
jun. 22
28413
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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