One of my current projects in Odoo 13.0 requires a lot of dynamically created widgets/items. In this example my goal is to create a new menuitem, whenever a certain model gets saved into the database.
Creating a hard coded menuitem in the view.xml is fairly easy in odoo but is there a way to create a new one dynamic from the code behind e.g. JS/Python?
The possibility of creating a whole new HTML-based view with Qweb is also known, but was not my first intention because it should be in the same form as my parent module.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
1
ตอบกลับ
7339
มุมมอง
Below is my implementation of creating a dynamic menu item. Firstly I create a new action to point the menu item too and then create the new menu item. In the below example this is being made in a create function when I create a new record in a table. Be sure to delete these actions/menuitems manually if you uninstall and reinstall the module. Hope this helps.
action_vals = { | |
'name': vals['menu_name'], | |
'xml_id': 'module_name.documents_list_action', | |
'res_model': 'business.management', | |
'type': 'ir.actions.act_window', | |
'target': 'current', | |
'view_mode': 'tree,form', | |
'domain': "[('le_document_type', '=', '" + vals['menu_name'] + "')]", | |
} | |
action = self.env['ir.actions.act_window'].create(action_vals) | |
###get the parent menu item | |
parent_menu = self.env['ir.ui.menu'].search([('name', '=', 'DropDownParentMenuItem')]) | |
for menu in parent_menu: | |
if menu.parent_id.name == 'ModuleParentMenuItem': | |
parent_id = menu.id | |
parent_path = menu.parent_path | |
menu_item_vals = { | |
'action': 'ir.actions.act_window,%d' % (action.id,), | |
'active': True, | |
'display_name': vals['menu_name'], | |
'name': vals['menu_name'], | |
'parent_id': parent_id, | |
'parent_path': parent_path, | |
} | |
menu_item = self.env['ir.ui.menu'].create(menu_item_vals) | |
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
How can I return a record after deletion
แก้ไขแล้ว
|
|
1
มิ.ย. 22
|
6096 | |
|
4
พ.ค. 24
|
12645 | ||
|
1
เม.ย. 24
|
3276 | ||
|
4
ม.ค. 24
|
23166 | ||
Attrs attribute
แก้ไขแล้ว
|
|
2
ม.ค. 24
|
2452 |