odoo12—开发手册>>P06

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">

在这里插入图片描述

主体信息部分

主要用group和field的组合进行信息显示

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

要在生成的元素上设置的HTML类,常用如下:
oe_read_only:仅在只读模式下显示该元素
oe_edit_only:仅在编辑模式下显示该元素
oe_no_button:用于many2one字段,避免在导航栏中显示导航按钮
oe_avatar:用于图像字段就是binary字段和widget="image"一起使用,显示90*90的图片。一般在<div class="oe_titile">之前添加,页面显示示例如下:
在这里插入图片描述

groups

权限组设置,值是对应的权限组的xmlid,添加后只能该用户组的用户能看见该元素,用于页面组件的权限控制


nolabel

field标签转化为html标签是自带label标签的,标签的值就是字段的string值,如果只想显示字段的值的话,可以将改属性值设为1,nolabel=“1”

readonly

设置为1,该字段只读不能 编辑。

required

设置为1,该字段必填。

placeholder

设置显示在input输入框中的提示信息

help

鼠标悬停在字段上后显示的帮助信息

invisible

隐藏字段。

password

将输入信息显示为**的加密形式

filename

对于binary字段而言,值是用来显示文件名称的字段名。

force_save

对页面上的只读字段使用,当使用onchange方法改变了该字段的值要将force_save属性设置为1否则该字段不会保存。

attrs

对字段状态的动态控制。

xml attrs="{'invisible': domian, 'required':domain,'readonly':domain}"

domain代表domain条件语句,一个简单的使用示例:

xml attrs="{'invisible': [('use_questions', '=', False)]}"

当use_questions字段为False时隐藏字段。

widget

用于渲染字段的小部件名。其实每个类型的字段都有一个默认的widget,他们在web模块的/web/static/src/js/fields路径文件中的js文件定义。

options

值的话就是json格式的字符串,一般都是用来给widget小部件传递参数的。

domain

many2one字段下拉选项的过滤,属性值就是domain语句。只适用于关系字段。

context

只用于关系字段,设置上下文,如设置context="{'a':True}",然后在关系字段对应model的一些方法中可以获得该context,例如name_get()方法,通过self.env.context可以拿到这里设置的值:{‘a’:True}然后进行一些处理。

mode

还没用到过,看官网说是设置one2many渲染显示的视图,one2many默认是tree视图的样式显示的,可以设置成tree,form,kanban或graph

视图内—button的属性

icon

用于显示按钮的图标。 使用的是Font Awesome 图标,查找到想要的图标代码,给icon赋值即可。

<button name="%(action_window_oa_flow_context)d" type="action" class="oe_stat_button"
        string="流程"
        icon="fa-flag">
</button>

string

按钮的文本

type

按钮的类型,有object、action两种。 object类型,按钮的name属性值是要调用的model中的方法名,将使用当前行的记录ID和当前上下文来调用该方法。示例:

<button name="action_approval" 
		string="批准" 
		type="object" 
		class="oe_highlight"        
		attrs="{'invisible': ['|',('oa_state', 'not in', ['noapprove','approving','goback','editing'])]}"/>

action类型,一般是给按钮绑定上定义的action record,name属性值为对应的action record
的xmlid,只不过要通过%(xmlid)d将xmlid进行转化。

args

object类型的按钮,给调用的后台方法传递参数的,是json类型的参数。

attrs

和上面field中对应的属性作用一样。

states

当表中有定义工作流字段state时才有用,例:states="confirm、done"当状态为confirm或者done时才显示该按钮。

confirm

在点击按钮时会弹出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'}"/>

这块是给delivery.action_delivery_carrier_form弹窗动作的search视图传递默认筛选条件,serach_default_

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值