odoo視圖views.xml文件詳解


本文主要介紹Odoo模塊中視圖文件views.xml文件對應的的字段詳細解析,為odoo模塊開發及修改提供參考

視圖分類

主要有四個視圖:

菜單視圖:把 數據模型——菜單——視圖(tree、form) 連接起來

表單視圖:創建、編輯數據模型所用視圖。

列表視圖:展示數據模型(顯示數據)時使用。

搜索視圖:制定odoo右上角對於當前數據模型的可搜索字段以及可用過濾器。

菜單視圖

在定義了數據模型之后,我們要操作該模型。就需要把模型——菜單——視圖 連接起來。這可以通過act_window+menuitem來實現。
元素定義了一個客戶端窗口動作,該動作將以列表和表單視圖的順序打開todo.task模型。 定義了一個頂級菜單項,調用前面定義的action_todo_task動作。

兩個元素都包含了id屬性。 此id屬性也稱為XML ID,它用於唯一標識模塊內的每個數據元素,並且可以由其他元素使用來引用它。

菜單視圖

最后,把視圖文件所在路徑注冊到manifest的data中:

 
'data': [
        'views/views.xml',  //注意:路徑要全。
    ],

表單視圖

所有的視圖都存儲在數據庫中。我們在XML文件中聲明一個描述視圖的元素,該模塊在安裝模塊時將被加載到數據庫中。

<?xml version="1.0" encoding="UTF-8"?>
<template id="template" xml:space="preserve">
<!-- 拓展Tree視圖增加自定義按鈕 -->
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_save" t-operation="after">
<button type="button" class="btn btn-primary o_list_tender_button_say_hello" style="display:inline-block;">Tree:Say Hello</button>
</t>
</t>
<!-- 拓展Form視圖增加自定義按鈕 -->
<t t-extend="FormView.buttons">
<t t-jquery="button.o_form_button_create" t-operation="after">
<button type="button" class="btn btn-primary o_list_tender_button_say_hello" style="display:inline-block;">Form:Say Hello</button>
</t>
</t>
</template>

參考文章:https://www.erpdaxue.cn/odoo/odoo教程/odoo視圖views-xml文件詳解/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM