Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to hide Selection Field Options based on condition :

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
fieldsselectioninvisibleodooV11
5 Réponses
20400 Vues
Avatar
Chaanto

Class ExampleCode(models.Model) :

_name = 'example.code'

there is have a one event list

event_list = fields.Selection([
('commu', 'Community Event'),

('company', 'Company Event'),

('school'', 'School Event'),

('collage'', 'Collage Event'),

], string='Event Type')

there 4 set of option based on event_list :

position_company = fields.Selection([
                                                ('ceo', 'CEO'),
                                                ('manager', 'Manager'),
                                                ('employee', 'Employee'),
                                                ('other', 'Others')
                                                ], string='Position')

position_community = fields.Selection([
                                                ('leader', 'Leader'),
                                                ('vice', 'Vice Leader'),
                                                ('member', 'member'),
                                                ('speaker', 'Speaker'),
                                                ('other', 'Others')
                                                ], string='Position')

position_school = fields.Selection([
                                                ('head', 'Headmaster'),
                                                ('teacher', 'Teacher'),
                                                ('council', 'Student Council'),
                                                ('student', 'Student'),
                                                ('other', 'Others')
                                                ], string='Position')

position_collage = fields.Selection([
                                                ('rector', 'Rector'),
                                                ('lecture', 'Lecturer'),
                                                ('student', 'Collage Student),
                                                ('other', 'Others')
                                                ], string='Position')


so instead of making 4 set of them i wanna to put them all in one fields selection then it would be invisible based on event_list is that possible ? if possible can you show me how to do it ?


reason why i wanna do something like this because i dont wanna show 4 position on one tree view so i should make something like this if there is another alternative please tell me how to do this .


Thank you,

Best Regards

0
Avatar
Ignorer
Avatar
Jake Robinson
Meilleure réponse

As an alternative approach you can use a computed field that will have the correct selection, but still use the 4 sub selections to dynamically show the appropriate options:

from odoo import api, fields, models

COMPANY_SELECTION = [
('ceo', 'CEO'),
('manager', 'Manager'),
('employee', 'Employee'),
('other', 'Others')
]
COMMUNITY_SELECTION = [
('leader', 'Leader'),
('vice', 'Vice Leader'),
('member', 'member'),
('speaker', 'Speaker'),
('other', 'Others')
]
SCHOOL_SELECTION = [
('head', 'Headmaster'),
('teacher', 'Teacher'),
('council', 'Student Council'),
('student', 'Student'),
('other', 'Others')
]
COLLAGE_SELECTION = [
('rector', 'Rector'),
('lecture', 'Lecturer'),
('student', 'Collage Student'),
('other', 'Others')
]


class ExampleCode(models.Model):
_name = 'example.code'
event_list = fields.Selection(string='Event Type', selection=[
('company', 'Company Event'),
('commu', 'Community Event'),
('school', 'School Event'),
('collage', 'Collage Event')
])

position_company = fields.Selection(string='Company Position', selection=COMPANY_SELECTION)
position_community = fields.Selection(string='Company Position', selection=COMMUNITY_SELECTION)
position_school = fields.Selection(string='Company Position', selection=SCHOOL_SELECTION)
position_collage = fields.Selection(string='Company Position', selection=COLLAGE_SELECTION)
position = fields.Selection(string="Position", selection=COMPANY_SELECTION + COMMUNITY_SELECTION + SCHOOL_SELECTION + COLLAGE_SELECTION, compute='_compute_position', store=True)

@api.depends('position', 'position_company', 'position_community', 'position_school', 'position_collage')
def _compute_position(self):
for rec in self:
if rec.event_list == 'company':
rec.position = rec.position_company
elif rec.event_list == 'commu':
rec.position = rec.position_community
elif rec.event_list == 'school':
rec.position = rec.position_school
elif rec.event_list == 'collage':
rec.position = rec.position_collage
else:
                rec.position = False


1
Avatar
Ignorer
Avatar
Ravi Gadhia
Meilleure réponse

There is no way to filter value of selection field or even would not apply domain on it.
​
So the alternative is 
Instead of taking four selection field take one many2one field like
                                                                                                                                                                                                  
position_id = fields.Many2one('job.position')

in job.position take named as type as a selection field like [('community','Community'), ('company','Company'), ....]

now on change of event_list set domain on position_id like
return {'domain': {'position_id': [('type', '=', self.event_list)]}}
​

0
Avatar
Ignorer
Chaanto
Auteur

well i thinks is not a good way to solve this problem, because i must make the many2one to handle this things. and my system already full of selection field for this, so i must fix all of them if i using this way.

Ravi Gadhia

Ok, but my main concern about your approach is if you create four different selection field when you need position value in another part of business logic you have to check/select all the fields

Chaanto
Auteur

thanks for you answer, i'm already found the alternative that can dynamically to change fields selection based on condition, it just need the 4 global variable and 1 selection field and return the domain for filtering the slection field without change to m2o

Vysakh B Thottarath

@Chaanto Please Share your Answer ..

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
how can I make a one2many field a selection field in view Résolu
fields selection
Avatar
Avatar
Avatar
3
oct. 25
18258
how to hide a field if empty in view mode and view it in edit mode (odoo11)?
fields invisible
Avatar
0
nov. 17
6279
How to pass values to a method that defines selection for multiple fields?
fields selection
Avatar
0
avr. 15
4866
How To Change Field Value According To Selection Field Openerp?
fields selection
Avatar
Avatar
1
mars 15
10322
Why in Selection Field Only Key is Store in Database Not the Value ? Résolu
fields database selection
Avatar
Avatar
1
déc. 24
2452
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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