Chapter 6 - Odoo 15 Development Book

View Inheritance

There are different view types in odoo. If you want to change an existing view in odoo, for that you want to inherit the corresponding view and then do your changes. It is possible to inherit all the views like form, tree, kanban, search etc.

For Inheriting a view you want to create an XML file inside the views folder for adding the inheritance. And also add this file path inside the manifest -> data.

Inside the xml file you can add the inheriting records. i.e.,

                        <record id="view_crm_meeting_search" model="ir.ui.view">
  <field name="name">calendar.event.form.inherit</field>
  <field name="model">calendar.event</field>
  <field name="inherit_id" ref="calendar.view_calendar_event_search"/>
  <field name="arch" type="xml">
    <xpath expr="//field[@name='description']" position="after">
      <field name="opportunity_id"/>
    </xpath>
  </field>
</record>
                        

Here inheriting the already existing form view view_calendar_event_search that is inside the module calendar. Inherit_id is used to specify the parent view id that you want to inherit. You can add module_name.parent_view_id for the inheritance. Then you can do your changes by using xpath tag. And you can give different values for xpath.

You can add expressions in different ways:

Some examples are:

expr="//field[@name='user_id']"
expr="//sheet/div[last()]"
expr="/kanban"
expr="."
expr="//filter[@name='activities_overdue']
expr="//header"
expr="//button[@name='action_open_product_lot']"

Also you can give different positions to the xpath. i.e.,

position=”after” : Display the field after the parent view mentioned in “expr”

position=”before” : Display the field before the parent view mentioned in “expr”

position=”inside” : Display the field inside the parent view mentioned in “expr”

position=”attributes” : Change the field attributes

position=”replace” : Replace the parent view field with newly created field

Form Style

If you want to provide a uniform experience for users, then you can style the document form in Odoo. You can follow different steps for styling a form.

1. Header Element

Use the header element for adding buttons or status bar in the starting of a form.

For example:

<header>
  <button name="action_quotation_send" string="Send by Email" type="object" states="sent,sale"
    data-hotkey="g"/>
  <button name="action_cancel" type="object" string="Cancel" attrs="{'invisible': ['|', ('state', 'not in',
    ['draft', 'sent','sale']), ('id', '=', False)]}" data-hotkey="z"/>
  <button name="action_draft" states="cancel" type="object" string="Set to Quotation" data-hotkey="w"/>
  <field name="state" widget="statusbar"
    statusbar_visible="draft,sent,sale"/>
</header>

2. Sheet Element

Next you can add a <sheet> element. Inside this element you can add all other fields.

3. Smart buttons

You can use smart buttons for getting other records that are related to this object. Next step is to add smart buttons on the top of the sheet.

<div class="oe_button_box" name="button_box">
  <button class="oe_stat_button"
   name="button_journal_entries"
   string="Journal Entries"
    type="object"
    attrs="{'invisible':[('move_line_count','=', 0)]}"
    icon="fa-bars"/>
 </div>

4. Prominent fields

If there are any prominent fields then put it first.

<div class="oe_left oe_title">
  <label for="name" />
  <h1>
    <field name="name" />
  </h1>
</div>

Then you can add all other fields.

5. Notebook

If there are a lot of fields on the form, then we can arrange them as notebook pages.

<notebook>
  <page string="Internal Notes" name="internal_notes">
    <field name="description" placeholder="Add a description..."/>
  </page>
</notebook>

You can add more pages to a notebook.

6. Chatter widget

If you want to add a chatter on your form, you can add it after closing the sheet element.

<div class="oe_chatter">
  <field name="message_follower_ids" groups="base.group_user"/>
  <field name="activity_ids"/>
  <field name="message_ids"/>
</div>
whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message