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

Passing context to a tree view field inside a form view

S'inscrire

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

Cette question a été signalée
developmentviewsmoduletreeviewformview
3 Réponses
18630 Vues
Avatar
Maximilien Celis

Hi all,

I'm struggling to pass a context to a tree view field, which is nested inside a form view. Not 100% certain but I'm pretty sure I've done this successfully before. Is it due to Odoo V14 ?

When I create a new credit, i would like the building field to be populated before saving the record.

My form view :

<record model="ir.ui.view" id="bld_building_form_view">
    <field name="name">bld.building.form</field>
    <field name="model">bld.building</field>
    <field name="arch" type="xml">
    <form string="Building">
...
        <field name="id"/>
        <field name="credits" string="Credits" context="{'default_building_id': id}">
            <tree string="Credits">
                <field name="name"/>
                <field name="amount" widget="monetary" sum="Total"/>
                <field name="interest_rate" string="Annual interest rate %"/>
                <field name="start_date"/>
                <field name="building_id"/>
            </tree> 
        </field>
...

My model :

class Building(models.Model):
    _name = 'bld.building'
    _inherit = ['mail.thread', 'mail.activity.mixin']
    _description = 'Building'

credits = fields.One2many('bld.credit', 'building_id', string='Credits', copy=True, auto_join=True)

class Credit(models.Model): _name = 'bld.credit' _description = 'Credit' building_id = fields.Many2one('bld.building', string='Building', required=True, index=True, copy=True) name = fields.Char(required=True) amount = fields.Monetary(store=True) interest_rate = fields.Float(string='Annual interest rate', store=True) start_date = fields.Date()
 


3
Avatar
Ignorer
Travis Waelbroeck

You might try using `context="{'default_building_id': active_id}">`

Maximilien Celis
Auteur

Just tried it, not working...

Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Meilleure réponse

Why do you want to set buidling_id as default in O2m?

Odoo by default passes the reference m2o fields in o2m as soon as you save the record. You don't need to pass it forcefully.

Remove the "<field name="building_id"/>" from the xml and try it again.

2
Avatar
Ignorer
Maximilien Celis
Auteur

Good point, but I need the field to be populated before saving. On another field I have a domain filter tied to building_id.

Sudhir Arya (ERP Harbor Consulting Services)

Are you creating the lines after saving the main record or creating everything in one go?

If you are saving the main record first and then creating the lines, I think you will see the value in building_id filed as default.

Maximilien Celis
Auteur

Thanks for your help. The main record (Building) is already created and saved.

However when I add a line (Credit), the building_id of that line is not populated by default. It only populates when I save the line. I'm trying to have it populated before saving.

Avatar
Maximilien Celis
Auteur Meilleure réponse

Update :

I just build a basic module with a similar model and view structure on both Odoo 13.0 and 14.0. I can now confirm that it works fine on 13.0 and not on 14.0. Seems like Odoo changed the context approach on 14.0.

Question remains if it is still possible in 14.0 to populate a many2one field without having to save the record first.

2
Avatar
Ignorer
Avatar
Jonathan Van-Dyck
Meilleure réponse

Has anyone found a solution to this issue yet?

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 redirect to form view after clicking row in custom SQL tree view? (14.0)
views treeview formview
Avatar
0
sept. 21
3166
From tree view to dynamic form view
treeview formview
Avatar
Avatar
1
sept. 23
5378
Multiple Create Form Views same Model Résolu
development views
Avatar
Avatar
1
déc. 23
18870
multiple models in one view (form view inside form view)
views formview
Avatar
Avatar
1
oct. 16
11476
How to create a new openerp modules
development module
Avatar
Avatar
2
mars 15
5255
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