Odoo

Field

Field

attributes for the “field” tag

  • select=”1”: mark this field as being one of the research criteria for this resource search view.
  • colspan=”4”: the number of columns on which a field must extend.
  • readonly=”1”: set the widget as read only
  • 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).

  • invisible=”True”: hides both the label and the field.
  • string=”“: change the field label. Note that this label is also used in the search view: see select attribute above).
  • domain: can restrict the domain. – Example: domain=”[(‘partner_id’,’=’,partner_id)]”
  • widget: can change the widget. – Example: widget=”one2many_list” * one2one_list
  • one2many_list
  • many2one_list
  • many2many
  • url
  • email
  • image
  • float_time
  • reference
  • 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 &amp; 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>