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

Create a dynamic form view

Iscriviti

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

La domanda è stata contrassegnata
viewsformdynamicodooodoo8
3 Risposte
25373 Visualizzazioni
Avatar
Pepiño

Hi Odoo developers,

I have a model named 'TypeTask' which has a Char field called 'name_task'. This field represents the name of the task type (e.g call, meeting, visit, email, ...).

I have a menu associated with an action to open the form view of the TypeTask model This form only shows the field 'name_task'.

Then, I want that when the user is going to choose a value from this field in the form, new fields appear in the same form. These new fields depend on the task type chosen.
For instance, if the user chose the 'call' task type, the fields that should appear would be: 'telephone', 'day', 'hour', 'call duration', etc.
If the user chose the 'meeting' task type, the fields that should appear would be: 'place', 'assistants', etc.

I have implemented a model for each task type (model Call, model Meeting, model Visit, model Email). Each one inherits from the Task parent model. 
Also, I have a different form view for each ot these models.
The expected behaviour would be that when the user had chosen the 'call' task type in the form, the form view of the Call model would be opened in the Task Type form adding all fields of the Call model.

How can I get this behaviour in the form mentioned above?.

Thanks in advance.
-----------------------------
Odoo: version 8

OS: Ubuntu 14.04

1
Avatar
Abbandona
Pepiño
Autore

I can't comment your answer Robert because I don't have enough karma. Thanks for your answer @Robert. I thought the same as you, but I would rather have an abstract class Task and childs classes inheriting from Task for the different kinds of Tasks (subclass Call, subclass Meeting, etc) using _inherit in my model.py file. Each subclass should have its own form view and each view should be opened when the user choose a kind of Task from the form view of the TypeTask model. The key is how to load dinamically a form view of a model from the form view of other module.

Avatar
Pepiño
Autore Risposta migliore

Hi Odoo developers,

I'm going to answer myself.

In my module I have a Course and a Session model. A course could be composed of zero, one or many sessions.
The Course model has associated a form view:

<record model="ir.ui.view" id="course_form_view">
<field name="name">course.form</field>
<field name="model">openacademy.course</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
<field name="responsible_id" string="Responsible"/>
</group>
<notebook>
<page string="Description">
<group>
<field name="description"/>
</group>
</page>
<page string="Ayuda">
<p>Another <strong>tab</strong></p>
</page>
<page string="Sessions">
<field name="session_ids">
<tree string="Course sessions">
<field name="name"/>
<field name="instructor_id"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

The session model has associated another form view:

<record model="ir.ui.view" id="session_form_view">
<field name="name">session.form</field>
<field name="model">openacademy.session</field>
<field name="arch" type="xml">
<form>
<header>
<button name="draft" type="workflow"
string="Reset to draft"
states="confirmed,done"/>
<button name="confirm" type="workflow"
string="Confirm" states="draft"
class="oe_highlight"/>
<button name="done" type="workflow"
string="Mark as done" states="confirmed"
class="oe_highlight"/>
<button type="action"
name="openacademy.action_new_course1"
string="New course"
confirm="Do you want to create a new course?"/>

<field name="state" widget="statusbar"/>
</header>
<sheet>
<group string="General">
<field name="name" string="Session name"/>
<field name="course_id" string="Course"/>
<field name="instructor_id" string="Instructor"/>
</group>
<group string="Management">
<field name="start_date" string="Start date"/>
<field name="active" string="Activo"/>
<field name="duration" string="Duration (in days)"/>
<field name="seats"/>
<field name="percent_taken_seats" widget="progressbar"/>
</group>
<label for="attendees"/>
<field name="attendees"/>
</sheet>
</form>
</field>
</record>

In the above view there is a button with the string attribute equals to "New course":

<button type="action" name="openacademy.action_new_course1" string="New course" 
    confirm="Do you want to create a new course?"
/>

The button is associated with a window action using the attribute name="openacademy.action_new_course1".
This window action is defined in the same .xml file that this button:

<record id="action_new_course1" model="ir.actions.act_window">
<field name="name">Course</field>
<field name="res_model">openacademy.course</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">current</field>
</record>

The above window action open the form view defined for the Course model mentioned before.
Apart from this, you can have others window actions bind to the same Course model with differente values for view_mode. For example, I have another window action associated to the Course model:

<record model="ir.actions.act_window" id="action_openacademy_list_courses">
<field name="name">Courses Manager</field>
<field name="res_model">openacademy.course</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar</field>
<field name="context" eval="{'search_default_my_courses': 1}"/>
</record>

And this window action is bind to a menu item to open the Course model view:

<menuitem id="courses_menu" name="My Courses"
parent="openacademy_menu"
action="action_openacademy_list_courses"
/>

When I click on the menu named "My Courses", a tree view corresponding to the Course model is opened, and I have two more buttons to open the form and the calendar views associated to this model.

<record model="ir.actions.act_window" id="action_openacademy_list_courses">
<field name="name">Courses Manager</field>
<field name="res_model">openacademy.course</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar</field>
<field name="context" eval="{'search_default_my_courses': 1}"/>
</record>

2
Avatar
Abbandona
Avatar
Dr Obx
Risposta migliore

Hi,

You talking about thing I already made some time ago. It's not exactly the same but idea is the same.

I needed a dynamically created form for products so depending on product type adequate list of fields or option is displayed.

In your case it may be a bit more complicated because you want switch between the views. I would do it that way:

(I'm not sure is the best idea but ....)

using "attrs" hide or show task dedicated fields.
in py file:
task_type = fields.selection([('task_1','taks one'),('task_2','task two'),('task_3','task three')],'Tasks'),

In xml:
<field name="task_type"/> # which let you choose the task you want.

and depending on task chosen task related group will be displayed :)
<group name="task_1" attrs={invisible:('task_type','!=','task_1')}>
...
<field name="_1"/>
<field name="_2"/>
...
</group> 

<group name="task_2" attrs={invisible:('task_type','!=','task_2')}>
...
<field name="_2"/>

<field name="_3"/>
...
</group>

I hope it help or just give you idea how you can solve it :)

1
Avatar
Abbandona
Avatar
Adil Akbar
Risposta migliore

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

0
Avatar
Abbandona
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 can I show integers measured fields instead floats in graph views in Odoo 8?
views graph odoo odoo8
Avatar
0
mag 15
13698
Can't switch views from Form to Kanban
views form kanban odoo Odoo13.0
Avatar
0
mar 22
3077
Many2one related form view in odoo 13
views form many2one odoo Odoo13.0
Avatar
2
gen 20
132
How to set the default value in the view of an existing form, depending on the decision (boolean) field? Risolto
views form contacts odoo odoo10.0
Avatar
Avatar
2
dic 18
13767
Odoo Google Map : How to add google map inside any form view of odoo? Risolto
views form google map odoo
Avatar
Avatar
2
apr 24
15407
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