Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

How to fill up Many2Many after user took an option from a selection?

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
domainmany2oneselectionmany2manyodoo8.0
1 Rispondi
18887 Visualizzazioni
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys

I've built a selection that gets all the modelnames from the database:

model_names = fields.Many2one('ir.model', 'Model to use')

This builds a selection where the user can see all models and choose one out. The next step that I want is that when the user selects a model from the selection that the next field (a Many2Many) is automaticly getting all fields that are in the model the user selects.
For example: the user chooses res.partner from the model_names selection. The next field (Many2Many) should now show all fields that are available in the res.partner model.

How exactly should I do this? I should access the model ir.model.fields and get every single field that matches the correct model the user selected. I assume I should create an onchange that loads all fieldnames in the Many2Many when the user selected something in the Many2one? Would this also be possible with a domain_filter?

XML file:

     <record model="ir.ui.view" id="my_form_view">
            <field name="name">myname.form</field>
            <field name="model">model.builder</field>
            <field name="arch" type="xml">
                <form string="My Form">
                    <sheet string="test">
                        <group>
                            <field name="name"/>
                <field name="model_names"/>
                <field name="fields_to_use"/>
                        </group>
             <notebook>
                            <page string="Advanced" name="Advanced">
                
                </page>
                </notebook>
            </sheet>
                </form>
            </field>
        </record>

Python code:

from openerp import models, fields, api

class MyClass(models.Model):
    _name = 'model.builder'

    name = fields.Char(string="Title", required=True)
    model_names = fields.Many2one('ir.model', 'Model to use', help='The model that you use here will give you access to all fields from this model. This will auto-generate the fields in the next dropdown.', required=True)
    fields_to_use = fields.Many2many('ir.model.fields', 'field_names_model', required=True)

    @api.one
    @api.depends(
        'model_names',
        'model_names.field_id',
        'model_names.field_id.model_id',
    )
    def _get_names(self):
        self.fields_to_use_computed = self.model_names.field_id.filtered(lambda l: l.model_id.id == self.model_names.id)    

    fields_to_use_computed = fields.Many2many('ir.model.fields', compute='_get_names', string='Fields to use COMPUTED')

    @api.onchange('fields_to_use_computed')
    def do_stuff(self):
        self.fields_to_use=self.fields_to_use_computed

I'd love some help as I have no clue here.

Thanks
Yenthe

0
Avatar
Abbandona
Zbik

Settings/Database Structure is not similar?

Yenthe Van Ginneken (Mainframe Monkey)
Autore

When you open up a specific module and get all the field names yes.. But I would like to get all those fields from a specific model in a Many2Many so the user can select the fields from the specific model he chose in the previous selection.

Avatar
Zbik
Risposta migliore

Try this:

field_names = fields.Many2many('ir.model.fields', string='Fields to use', domain="[('model_id', '=', model_names )]")

but this not auto select-fill all fields and not clear previous selection, if you expect?

UPDATE:

If you need auto fill, you additionaly add, like this (not tested):

    @api.one
    @api.depends(
        'model_names',
        'model_names.field_id',
        'model_names.field_id.model_id',
    )
    def _get_names(self):
        self.field_names_computed = self.model_names.field_id.filtered(lambda l: l.model_id.id == self.model_names.id)    

    model_names = fields.Many2one('ir.model', 'Model to use')
    field_names_computed = fields.Many2many('ir.model.fields', compute='_get_names', string='Fields to use COMPUTED')   
    field_names = fields.Many2many('ir.model.fields', string='Fields to use', domain="[('model_id', '=', model_names )]")

    @api.onchange('field_names_computed')
    def do_stuff(self):
        self.field_names=self.field_names_computed

 

4
Avatar
Abbandona
Yenthe Van Ginneken (Mainframe Monkey)
Autore

Thanks for the suggestion Zbik. Sadly the Many2many should be reloaded and filtered every time the user selects another model. The Many2many should only be filled with the fields from the model of the selection. Any idea on this? I was thinking about an on_change method but didn't get anything working yet.

Zbik

Answer updated

Zbik

updated again

Yenthe Van Ginneken (Mainframe Monkey)
Autore

Thanks Zbik! I gave this a try but nothing changed.. sadly the data is still showing all fields from all fields. Even after selecting the model from the selection.. I've updated my question with the whole code I have now! Any idea?

Zbik

You missed domain="[('model_id', '=', model_names )]") in full solutions. updated again.

Yenthe Van Ginneken (Mainframe Monkey)
Autore

Awesome, this works like a charm. Thank you so much zbik :) Accepted & upvoted!

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
How to use widget='selection' and domain in many2one field Risolto
domain many2one selection
Avatar
Avatar
Avatar
2
dic 23
33783
How to dynamically update domain filter on selection widget?
filter domain many2one selection
Avatar
Avatar
Avatar
2
set 23
10509
how to populate many2one field with condition
domain many2one many2many pop
Avatar
Avatar
1
apr 18
9470
How to create a many2one based on a many2many relation? Risolto
many2one selection many2many filtering
Avatar
Avatar
1
nov 16
8996
Why is my tax not filled in when using an automated action? Risolto
many2one many2many automation odoo8.0
Avatar
Avatar
1
mag 15
5211
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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