Some Useful Odoo XML Patterns


Image

<field name="image" widget="image" class="oe_right" nolabel="1" img_width="150" img_height="200" width="150" height="30/>


Insert divider between rows

    <div style="height:50px">
  </div>

Insert character between fields

<field name="module_file" colspan="4"/> |  <field name="force"/>

Two Fields In the Same Line

                               <label for="readability"/>
                                <div>
                                    <field name="readability"
                                        on_change="onchange_accuracy_class_id(accuracy_class_id, readability,max_capacity)"
                                        class="oe_inline"/>
                                    <field name="uom_id" groups="product.group_uom" class="oe_inline" placeholder="UOM"/>
                                </div>

Many2many Widget

<field name="shift_ids" widget="many2many_tags"/>

Place holder

<field name="description" class="oe_inline" nolabel="1" placeholder="Put an internal note..."/>

Title Field

    <record model="ir.ui.view" id="od_hr_document_type_view_form">
        <field name="name">od.hr.document.type</field>
        <field name="model">od.hr.document.type</field>
        <field name="arch" type="xml">
            <form string="Hr Document Type">
           <sheet>
               <div class="oe_title">
                            <label for="name" class="oe_edit_only"/>
                            <h1>
                                <field name="name"/>
                             
                            </h1>
                        </div>
          <group col="4">
               <field name="code"/>
        </group>
          </sheet>
            </form>
      </field>
    </record>

Smart Buttons

<div class="oe_right oe_button_box">
      <button class="oe_inline oe_stat_button" name="action_view_brand" string="Brand" type="object" icon="fa-strikethrough">
      </button>
      <button class="oe_inline oe_stat_button" name="action_view_product" type="object" icon="fa-refresh" string="Product"/>
      <button class="oe_inline oe_stat_button" name="action_view_saleman" type="object" icon="fa-refresh" string="Saleman"/>
      <button class="oe_inline oe_stat_button" name="action_view_category" type="object" icon="fa-refresh" string="Category"/>
      <button class="oe_inline oe_stat_button" name="action_view_customer" type="object" icon="fa-refresh" string="Customer"/>
      <button class="oe_inline oe_stat_button" name="action_view_supplier" type="object" icon="fa-refresh" string="Supplier"/>
</div>

Tree Colour Giving

<tree string="Unit" colors="blue:status_date &gt;status_next_date ; red:status_date &gt; current_date and status_date &lt; status_next_date;">

Separator

<separator string="Allocation Method"/>

Action View Domain Giving

<record id="od_action_move_line" model="ir.actions.act_window">
            <field name="name">Stock Moves</field>
            <field name="res_model">stock.move</field>
            <field eval="30" name="priority"/>
            <field name="type">ir.actions.act_window</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="od_view_move_picking_tree"/>
            <field name="context">{}</field>
            <field name="domain">[('raw_material_production_id','!=',False)]</field>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to create a stock movement.
              </p><p>
                This menu gives you the full traceability of inventory
                operations on a specific product. You can filter on the product
                to see all the past or future movements for the product.
              </p>
            </field>
        </record>

Attributes (by example)

<field name="p9_amount" attrs="{'invisible': [('period_type','in',('half','yearly'))]}"/>

<field name="p1_qty" attrs="{'invisible': ['|',('distribution_type','in',
('brand','category','saleman','customer','supplier')),('period_type','in',
('quaterly','half','yearly'))]}"/>

Colour for a field

<field name=”your_field_name” style=”color:green;font-size:28pt;”/>

                <p style="color:red;font-size:10pt;">
                    Are you sure you want to cancel this document?
             
                        <button name="cancel" string="Yes" type="object"  attrs="{'invisible': ['|',('state', '!=', 'draft'),('active_model', '=', 'account.invoice')]}" class="oe_link"/>
                        <button name="cancel_confirmed" string="Yes" type="object" class="oe_link" attrs="{'invisible': ['|',('state', '=', 'draft'),('active_model', '=', 'account.invoice')]}" />
                        <button name="action_cancel_for_invoice" string="Yes" type="object"  attrs="{'invisible': [('active_model','!=','account.invoice')]}" class="oe_link"/>
                        or
                        <button string="No"  class="oe_link" special="cancel"/>
                   </p>

Colour For State Field

                   <header>
                    <field name="state" widget="statusbar" statusbar_visible="draft,confirm,done" statusbar_colors='{"cancel":"red","draft":"blue"}'/>
                    </header>

Double Inheriting Procedure

           <record id="od_office_project_view_inherited_from_risk" model="ir.ui.view">
            <field name="name">project.task.risk.inherited</field>
            <field name="model">project.task</field>
            <field name="inherit_id" ref="orchid_office.view_task_form_in_risk"/>
            <field name="arch" type="xml">
                               <xpath expr="//field[@name='od_task_type']" position="replace">
                      <field name="od_task_type" required="1"/>
                </xpath>
            </field>
            </record>

Footer

       <footer>
                <button string="Generate" name="action_move_create" type="object" class="oe_highlight"/> or
                <button string="Cancel" class="oe_link" special="cancel" />
       </footer>

Xpath

Example1:

<xpath expr="/form/sheet/notebook/page[@string='Order Lines']/field[@name='order_line']/tree/field[@name='price_unit']" position="after">

Example 2:

 <xpath expr="/form[@string='Produce']/group[@string='To Consume']/field[@name='consume_lines']/tree[@string='Consume Lines']/field[@name='product_id']" position="after">
                <field name="product_uom"/>
                </xpath>

Example 3:

 <xpath expr="/form[@string='Produce']/group[@string='To Consume']/field[@name='consume_lines']/tree[@string='Consume Lines']/field[@name='product_qty']" position="after">
                  <field name="location_id"/>
                  <field name="cost_price"/>
                </xpath>

Red Color for Button

class="oe_highlight"

Default Value For Field

<field name="category_line" context="{'default_distribution_type':'category'}">

Footer Right Setting

<group>
     <group class="oe_subtotal_footer oe_right">
           <field name="od_sub_total"/>
           <field name="od_discount"/>
           <field name="od_total"/>
     </group>
</group>

Graph View Default Measure

<field name="net_salary" type="measure"/>

Hide Create Button and Edit Button

<form string="Target Brand" version="7.0" create="false" edit="false">

Group Arrangements

<group>
       <group>
                <label for="name" class="oe_edit_only"/>
                <h2><field name="name"/></h2>
                <label for="code"/>
                <h2><field name="code"/></h2>
       </group>
        <group></group>              
</group>

Iframe Adding

           <page string="openerp">
              <iframe marginheight="0" marginwidth="0" frameborder = "0"
                src="https://www.odoo.com/forum/help-1/question/adding-i-frame-in-openerp-34242" width="100%" height="1000"/>
            </page>

Readonly Class

class="oe_read_only"