Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Create a dynamic form view

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
viewsformdynamicodooodoo8
3 Respuestas
25357 Vistas
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
Descartar
Pepiño
Autor

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
Autor Mejor respuesta

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
Descartar
Avatar
Dr Obx
Mejor respuesta

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
Descartar
Avatar
Adil Akbar
Mejor respuesta

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How can I show integers measured fields instead floats in graph views in Odoo 8?
views graph odoo odoo8
Avatar
0
may 15
13689
Can't switch views from Form to Kanban
views form kanban odoo Odoo13.0
Avatar
0
mar 22
3063
Many2one related form view in odoo 13
views form many2one odoo Odoo13.0
Avatar
2
ene 20
132
How to set the default value in the view of an existing form, depending on the decision (boolean) field? Resuelto
views form contacts odoo odoo10.0
Avatar
Avatar
2
dic 18
13760
Odoo Google Map : How to add google map inside any form view of odoo? Resuelto
views form google map odoo
Avatar
Avatar
2
abr 24
15402
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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