odoo 基础视图


odoo 基础的视图

odoo 视图

泛型视图声明

视图声明为模型的记录。ir.ui.view。对象的根元素暗示视图类型。arch字段:

<record model="ir.ui.view" id="view_id">
    <field name="name">view.name</field>
    <field name="model">object_name</field>
    <field name="priority" eval="16"/>
    <field name="arch" type="xml">
        <!-- view content: <form>, <tree>, <graph>, ... -->
    </field>
</record>

tree 视图

树视图(也称为列表视图)以表格形式显示记录。

它们的根元素是<tree>。树视图的最简单形式只是列出表中要显示的所有字段(每个字段作为一列):

<tree string="Idea list">
    <field name="name"/>
    <field name="inventor_id"/>
</tree>

form 视图

表单用于创建和编辑单个记录。

它们的根元素是<form>。它们由高层结构元素(组、笔记本)和交互元素(按钮和字段)组成:

支持栅格化,以下是一个例子

<form string="Idea form">
    <group colspan="4">
        <group colspan="2" col="2">
            <separator string="General stuff" colspan="2"/>
            <field name="name"/>
            <field name="inventor_id"/>
        </group>

        <group colspan="2" col="2">
            <separator string="Dates" colspan="2"/>
            <field name="active"/>
            <field name="invent_date" readonly="1"/>
        </group>

        <notebook colspan="4">
            <page string="Description">
                <field name="description" nolabel="1"/>
            </page>
        </notebook>

        <field name="state"/>
    </group>
</form>

表单视图还可以使用普通HTML进行更灵活的布局:

<form string="Idea Form">
    <header>
        <button string="Confirm" type="object" name="action_confirm"
                states="draft" class="oe_highlight" />
        <button string="Mark as done" type="object" name="action_done"
                states="confirmed" class="oe_highlight"/>
        <button string="Reset to draft" type="object" name="action_draft"
                states="confirmed,done" />
        <field name="state" widget="statusbar"/>
    </header>
    <sheet>
        <div class="oe_title">
            <label for="name" class="oe_edit_only" string="Idea Name" />
            <h1><field name="name" /></h1>
        </div>
        <separator string="General" colspan="2" />
        <group colspan="2" col="2">
            <field name="description" placeholder="Idea description..." />
        </group>
    </sheet>
</form>

search 视图

搜索视图自定义与列表视图(和其他聚合视图)关联的搜索字段。它们的根元素是<search>它们由定义可以在哪些字段上搜索的字段组成:

<search>
    <field name="name"/>
    <field name="inventor_id"/>
</search>

文章作者: theing
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 theing !
评论
  目录