attributes for the “field” tag
required=”1”: the field is marked as required. If a field is marked as required, a user has to fill it the system won’t save the resource if the field is not filled. This attribute supersede the required field value defined in the object.
nolabel=”1”: hides the label of the field (but the field is not hidden in the search view).
on_change: define a function that is called when the content of the field changes. – Example: on_change=”onchange_partner(type,partner_id)” – See ViewsSpecialProperties for details
attrs: Permits to define attributes of a field depends on other fields of the same window. (It can be use on page, group, button Format: “{‘attribute’:[(‘field_name’,’operator’,’value’),(‘field_name’,’operator’,’value’)],’attribute2’:[(‘field_name’,’operator’,’ – where attribute will be readonly, invisible, required – Default value: {}.
– 示例: (in product.product)
<field digits="(14, 3)" name="volume" attrs="{’readonly’:[(’type’,’=’,’service’)]}"/>
示例 Here’s the source code of the view of a sale order object. This is the same object as the object shown on the screen
<?xml version="1.0"?>
<terp>
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field> <field name="model">res.partner</field> <field name="type">form</field>
<field name="arch" type="xml">
<form string="Partners"> <group colspan="4" col="6">
<field name="name" select="1"/> <field name="ref" select="1"/>
<field name="customer" select="1"/>
<field domain="[(’domain’, ’=’, ’partner’)]" name="title"/> <field name="lang" select="2"/>
<field name="supplier" select="2"/>
</group>
<notebook colspan="4"> <page string="General">
<field colspan="4" mode="form,tree" name="address" nolabel="1" select="1"> <form string="Partner Contacts">
<field name="name" select="2"/>
<field domain="[(’domain’, ’=’, ’contact’)]" name="title"/>
<field name="function"/>
<field name="type" select="2"/>
<field name="street" select="2"/>
<field name="street2"/>
<newline/>
<field name="zip" select="2"/>
<field name="city" select="2"/>
<newline/>
<field completion="1" name="country_id" select="2"/> <field name="state_id" select="2"/>
<newline/>
<field name="phone"/>
<field name="fax"/>
<newline/>
<field name="mobile"/>
<field name="email" select="2" widget="email"/>
</form>
<tree string="Partner Contacts">
<field name="name"/> <field name="zip"/>
<field name="city"/>
<field name="country_id"/> <field name="phone"/> <field name="email"/>
</tree> </field>
<separator colspan="4" string="Categories"/>
<field colspan="4" name="category_id" nolabel="1" select="2"/> </page>
<page string="Sales & Purchases">
<separator string="General Information" colspan="4"/> <field name="user_id" select="2"/>
<field name="active" select="2"/>
<field name="website" widget="url"/>
<field name="date" select="2"/>
<field name="parent_id"/>
<newline/>
</page>
<page string="History">
<field colspan="4" name="events" nolabel="1" widget="one2many_list"/> </page>