odoo实操03
xml视图☞Form视图
看图:
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<form string="Purchase Order">
<header>
<button name="action_rfq_send" states="draft" string="Send by Email" type="object"
context="{'send_rfq':True}" class="oe_highlight"/>
...
<field name="state" widget="statusbar" statusbar_visible="draft,sent,purchase" readonly="1"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button type="object" name="action_view_invoice"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible':['|', ('invoice_count', '=', 0), ('state', 'in', ('draft','sent','to approve'))]}">
....
</button>
</div>
<div class="oe_title">
<h1>
<field name="name" readonly="1"/>
</h1>
</div>
<group>
<group>
<field name="currency_id" groups="base.group_multi_currency" force_save="1"/>
...
</group>
<group>
<field name="date_order"/>
...
</group>
</group>
<notebook>
<page string="Products">
<field name="order_line" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}">
<tree string="Purchase Order Lines" editable="bottom">
<field name="currency_id"/>
...
</tree>
<form string="Purchase Order Line">
...
</form>
</field>
</page>
<page string="Other Information" name="purchase_delivery_invoice">
...
</page>
</notebook>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>
header部分:
header部分就是form表单上面的哪一行按钮控件,使用工作流wiget控件widget="statusbar"
后,右边就会有状态变更的显示,左边就是对应单据状态能够执行的按钮。
div .oe_button_box部分:
定义表单右上角的按钮盒子,每个按钮时个带图标的矩形,如下图:
在这个div里面添加按钮都会显示在右上角上图部分。
<div class="oe_button_box" name="button_box">
<button type="object" name="action_view_invoice"
class="oe_stat_button"
icon="fa-pencil-square-o">
</button>
</div>
div .oe_title
表单的标题部分,就是左上角那块:
<div class="oe_title">
<h1>
<span class="o_form_label">Purchase Order</span>
<field name="name" readonly="1"/>
</h1>
</div>
有时候会看到左上角还会有图片,这是在<div class="oe_title">
行之前添加了一个图片字段:
<field name="icon_image" widget="image" class="oe_avatar">
主体信息部分
notebook和page
页面渲染位置:
产品、其他信息就2个page。
一般是在page
里面写一个对应的one2many
字段,然后在字段包裹的标签里面写关联表的tree视图。
div .oe_chatter
这部分需要对应的model继承了’mail.thread’, ‘mail.activity.mixin’, 'portal.mixin’
等模块才可以使用。
对应页面部分就是表单底部这些信息:
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</div>
视图中上下文context的使用
指定many2one
字段对应弹出的form视图 给字段添加如下属性:
context="{'form_view_ref': 'module.form_view_id'}"
module
:指视图文件所在的模块名
form_view_id
:要指定的form视图的id
视图内—field的属性
name
:
class
:
groups
:
。
nolabel
:
readonly
:
required
:
placeholder
:
help
:
invisible
:
password
:
filename
:
force_save
:
attrs
:
xml attrs="{'invisible': domian, 'required':domain,'readonly':domain}"
xml attrs="{'invisible': [('use_questions', '=', False)]}"
当use_questions字段为False时隐藏字段。
widget
:
options
:
domain
:
context
:
mode
:
视图内—button的属性
icon
:
<button name="%(action_window_oa_flow_context)d" type="action" class="oe_stat_button"
string="流程"
icon="fa-flag">
</button>
string
:
type
:
<button name="action_approval"
string="批准"
type="object"
class="oe_highlight"
attrs="{'invisible': ['|',('oa_state', 'not in', ['noapprove','approving','goback','editing'])]}"/>
args
:
attrs
:
states
:
confirm
:
context
:
<button name="%(delivery.action_delivery_carrier_form)d"
icon="fa-arrow-right"
type="action"
string="DHL Delivery Methods"
class="btn-link"
context="{'search_default_delivery_type': '1'}"/>