Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

Create a dynamic form view

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
viewsformdynamicodooodoo8
3 Trả lời
25369 Lượt xem
Ảnh đại diện
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
Ảnh đại diện
Huỷ bỏ
Pepiño
Tác giả

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.

Ảnh đại diện
Pepiño
Tác giả Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Dr Obx
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Adil Akbar
Câu trả lời hay nhất

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

0
Ảnh đại diện
Huỷ bỏ
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Bài viết liên quan Trả lời Lượt xem Hoạt động
How can I show integers measured fields instead floats in graph views in Odoo 8?
views graph odoo odoo8
Ảnh đại diện
0
thg 5 15
13695
Can't switch views from Form to Kanban
views form kanban odoo Odoo13.0
Ảnh đại diện
0
thg 3 22
3070
Many2one related form view in odoo 13
views form many2one odoo Odoo13.0
Ảnh đại diện
2
thg 1 20
132
How to set the default value in the view of an existing form, depending on the decision (boolean) field? Đã xử lý
views form contacts odoo odoo10.0
Ảnh đại diện
Ảnh đại diện
2
thg 12 18
13766
Odoo Google Map : How to add google map inside any form view of odoo? Đã xử lý
views form google map odoo
Ảnh đại diện
Ảnh đại diện
2
thg 4 24
15406
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة 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 là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

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