Attributes for XML fields Odoo 17

November 27, 2025 by
Attributes for XML fields Odoo 17
Liu
| No comments yet

Essential Attributes for <field/> in Odoo 17 XML Views

These attributes control how fields look, behave, and interact within Odoo's interface.


1. Presentation and Labeling Attributes
  • name: (Mandatory) The technical name of the field (from the Python model).
    • Example: <field name="product_id"/>
  • string: Overrides the field's display label for the current view only.
    • Example: <field name="name" string="Custom Label"/>
  • widget: Specifies a custom UI control (e.g., monetary, statusbar, many2many_tags).
    • Example: <field name="price_unit" widget="monetary"/>
  • placeholder: Displays a temporary hint inside an empty input field.
  • nolabel: Set to 1 or True to hide the field label in a Form View.
  • help: Provides a tooltip when the user hovers over the field label.

2. Behavioral and Control Attributes

These control user interaction, validation, and security.

  • readonly: Makes the field non-editable. Can be static (1) or dynamic (e.g., readonly="state != 'draft'").
    • Example: <field name="create_date" readonly="1"/>
  • required: Visually marks the field as mandatory in the UI. Can be static or dynamic. (Note: Server-side validation is still needed in Python.)
  • invisible: Hides the field from the user interface. Can be static (1) or dynamic (e.g., invisible="type == 'manual'").
  • groups: Restricts the field's visibility to specific user groups, using external IDs.
    • Example: <field name="cost" groups="base.group_erp_manager"/>

3. Dynamic Attributes (Odoo Expressions)

In Odoo 17, readonly, required, and invisible often use Odoo expressions for dynamic control:

  • Usage: Set the attribute value directly to a domain-like expression.
  • Example (Required): required="state in ['draft', 'sent']"
  • Example (Readonly): readonly="is_paid == True"
Attributes for XML fields Odoo 17
Liu November 27, 2025
Share this post
Archive
Sign in to leave a comment