odoo视图
菜单
菜单是相当于是应用的入口,如果安装好了应用,但是在菜单不显示,这个应用是没有作用的
创建菜单-menus.xml
注意
1.动作必须先定义在使用(同一个文件),不同文件的时候,在mainfest里面data也要按顺序
2.动作绑定使用的是外部的标识符
动作
https://www.odoogo.com/manual/odoo-dev-doc/f922b3a7
https://ruterly.com/2018/09/19/Odoo-basic-tutorial-06/
<record id="action_todo_task" model="ir.actions.act_window">
<field name="name">待办事项</field>
<field name="res_model">todo.task</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="target">current</field>
<field name="limit">2</field>
</record>
res_model:要打开的视图(窗口)关联的数据模型
view_type:视图类型,默认值为 form,一般情况下我们取默认值就可以了
view_mode:允许打开的视图类型,以逗号分隔,默认值为 tree,form
target:打开的窗口类型,常用的有 current(当前窗口打开)和 new (弹窗打开)这两种,默认为 current
案例
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- 主菜单定义 -->
<menuitem id="menu_todo" name="Todo"/>
<menuitem id="menu_todo_submenu" parent="menu_todo" name="待办事项"/>
<!-- 菜单动作定义 -->
<record id="action_todo_task" model="ir.actions.act_window">
<field name="name">待办事项</field>
<field name="res_model">todo.task</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="target">current</field>
</record>
<record id="action_todo_category" model="ir.actions.act_window">
<field name="name">分类</field>
<field name="res_model">todo.category</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="target">current</field>
</record>
<!-- 子菜单定义 -->
<menuitem action="action_todo_category" id="submenu_todo_category" name="分类" parent="menu_todo_submenu"
sequence="8"/>
<menuitem action="action_todo_task" id="submenu_todo_task" name="事项" parent="menu_todo_submenu"
sequence="9"/>
</data>
</odoo>
列表视图
数据展示,默认是显示一个字段的
https://segmentfault.com/a/1190000014047552
https://www.odoogo.com/manual/odoo-dev-doc/ee9a55e8
<odoo>
<data>
<record id="todo_task_view_tree" model="ir.ui.view">
<field name="name">todo.task.view_tree</field>
<field name="model">todo.task</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Todo">
<field name="name"/>
<field name="is_done"/>
</tree>
</field>
</record>
</data>
</odoo>
表单视图
一对多
不显示一方的多方数据
<record id="todo_category_view_form" model="ir.ui.view">
<field name="name">todo.category.view_form</field>
<field name="model">todo.category</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Todo Category">
<sheet>
<group>
<group>
<field name="name"/>
</group>
<group>
<field name="count" readonly="True"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
或者直接使用这种可以在外部修改数据,不跳转界面的方式 editable="bottom"
<record id="todo_category_view_tree" model="ir.ui.view">
<field name="name">todo.category.view_tree</field>
<field name="model">todo.category</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Todo Category" editable="bottom">
<field name="name"/>
<field name="count"/>
</tree>
</field>
</record>
表单视图规划
<record id="todo_task_view_form" model="ir.ui.view">
<field name="name">todo.task.view_form</field>
<field name="model">todo.task</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Todo">
<sheet>
<group>
<group>
<field name="name"/>
<field name="category_id"/>
<field name="is_done"/>
</group>
<group>
<field name="priority"/>
<field name="deadline"/>
<field name="is_expired" readonly="True"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
表单视图-notebook
<notebook colspan="4">
<page string="描述">
<field name="name" nolabel="1"/>
</page>
<page string="关于">
这是事项
</page>
</notebook>
搜索视图
https://www.odoogo.com/manual/odoo-dev-doc/ee9a55e8
https://www.odoogo.com/manual/odoo-dev-doc/701ffd98
搜索框
搜索框默认只会根据模型的name字段进行搜索,如果想要搜索更多的字段,需要定义搜索视图
#搜索视图基本结构
<record id="todo_task_view_filter" model="ir.ui.view">
<field name="name">todo.task.view_filter</field>
<field name="model">todo.task</field>
<field name="arch" type="xml">
<search string="Todo">
...
</search>
</field>
</record>
#配置允许搜索的字段
<search string="Todo">
<field name="name"/>
<field name="category_id"/>
</search>
#自定义过滤器
<separator/>
<filter string="未完成" name="undone" domain="[('is_done', '=', False)]"/>
<filter string="已完成" name="done" domain="[('is_done', '=', True)]"/>
<separator/>
<filter string="待办" name="todo" domain="[('priority', '=', 'todo')]"/>
<filter string="普通" name="normal" domain="[('priority', '=', 'normal')]"/>
<filter string="紧急" name="urgency" domain="[('priority', '=', 'urgency')]"/>
#分组-expend为1数据默认展开
<group expand="0" string="分组">
<filter name="group_by_name" string="" context="{'group_by': 'name'}"/>
<filter name="group_by_name" string="" context="{'group_by': 'category_id'}"/>
</group>
参考链接
https://segmentfault.com/a/1190000014047552
https://www.cnblogs.com/ygj0930/p/10826168.html\
比较全面
https://www.cnblogs.com/sunshuhai/p/11661573.html