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

Check condition based on a child field from a related many2one field on form view

S'inscrire

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

Cette question a été signalée
many2oneform_viewodoo12.0
3 Réponses
7487 Vues
Avatar
Paulo Matos

Hello everyone,

I am using Odoo 12 and need to check for a condition that is based on a child field from a "many2one" relation.

What I have:

    class Model1(models.Model):
        _name = 'model1'
        _description = 'This is the model1'

        code = fields.Char('Model 1 Code', required=True)
        name = fields.Char('Model 1 Name', required=True)
        reference_required = fields.Boolean('Requires a Reference', default=False)

    class Model2(models.Model):
         _name = 'model2'
         _description = 'This is the model2'

         #some fields here
         relation_to_model1_id = fields.Many2one('model1',)

What I am trying to do, is to check if the "reference_required" field on "model1" is true and if so, "relation_to_model1_id" field is shown.

Tried with no luck:

     <field name="relation_to_model1_id" attrs="{'invisible': [('relation_to_model1_id.reference_required','=',False)]}"/>

How can I achieve this on a form view?
I cannot even add a child field to the "model2" form view, using for instance:

     <field name="relation_to_model1_id.code"

Can anyone help achieve this?

Thank you in advance

PM

0
Avatar
Ignorer
Sehrish

Odoo Technical Tips: https://learnopenerp.tumblr.com/

Avatar
Alessandro Fiorino
Meilleure réponse

Have you tried adding a related field in Model2, i.e.

model1_id_reference_required = fields.Boolean(related='relation_to_model1_id.reference_required')

Then you can add it to the view and use it domain filters.

For reference  https://www.odoo.com/documentation/13.0/reference/orm.html#reference-fields-related

1
Avatar
Ignorer
Paulo Matos
Auteur

Dear @Alessandro Fiorino,

Thank you very much (and all others also).

You were right. The method you described solved my problem.

I have tried later but having an inconsistency error because I was using the wrong field type on the destination related field and the origin field.

Problem solved.

Best regards

PM

Avatar
Paresh Wagh
Meilleure réponse

Hi Paulo:

Something does not seem right with the example. You are self-referencing in the attrs attribute of relation_to_model1_id. The value of relation_to_model1_id.reference_required cannot be determined till the value of relation_to_model1_id is set. 

0
Avatar
Ignorer
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 to search in many2one with selection widget applied to the field? Résolu
many2one odoo12.0
Avatar
Avatar
1
avr. 19
10662
Remove external conection from many2one field on form view. How to do that? Résolu
many2one Widgets odoo12.0
Avatar
Avatar
1
mars 22
12478
Refresh a view form with many2one relation. How to achieve that?
many2one refresh odoo12.0
Avatar
Avatar
1
sept. 21
6302
Odoo[12]: How to make Many2one field readonly for particular user.
many2one readonly odoo12.0
Avatar
Avatar
Avatar
Avatar
5
sept. 19
7157
How to access tax information for pos order lines in Odoo 12
many2one many2many point_of_sale odoo12.0
Avatar
0
mars 20
4209
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