How to Add a Notebook and Page in Odoo

Abid Patel
25-Sep-2024 Updated : 25-Sep-2024

Understanding rec_name in Odoo: Learn how to customize rec_name in Odoo to improve record display and user experience. Step-by-step guide on overriding the name_get method for better data representation.

How to Add a Notebook and Page in Odoo

Odoo is known for its customizable user interface, which can be tailored to meet various business needs. One of the most useful features in Odoo's form views is the notebook widget, which allows you to group information into multiple tabs, providing a more organized and user-friendly layout. In this blog, we will walk through how to add a notebook and page (tab) to your Odoo form views, enhancing both functionality and presentation.

What is a Notebook in Odoo?

A notebook in Odoo is a user interface element used to group related fields into separate tabs. This is particularly useful when you need to manage large forms with many fields, as it helps improve readability and navigation by breaking down the content into manageable sections.

Benefits of Using Notebooks in Odoo

  • ▹ Improved User Experience: Notebooks allow users to navigate complex forms more easily by grouping fields logically across different pages (tabs).
  • ▹ Organized Layout: With tabs, you can display related fields together, keeping the form cleaner and more structured.
  • ▹ Scalable Forms: As your business grows and forms become more complex, notebooks make it easier to extend the form without overwhelming the user.

Step-by-Step Guide: How to Add a Notebook and Pages in Odoo

Let’s dive into the process of adding a notebook and pages (tabs) in a form view. We will create a custom module that adds a notebook with two tabs to an example model.

Step 1: Define Your Model

We start by creating or modifying an Odoo model to include some fields. In this example, we’ll use a custom model for a product, with fields grouped into different pages in the notebook.

python

from odoo import models, fields

class ProductTemplate(models.Model):
    _inherit = 'product.template'

    description = fields.Text(string="Description")
    features = fields.Text(string="Features")
    additional_info = fields.Text(string="Additional Information")
    

Step 2: Define the Notebook in the Form View

Next, we need to modify the form view of the model to include a notebook and pages. Notebooks in Odoo are defined in XML, and each page corresponds to a tab within the notebook.

Here is an example of how to add a notebook and pages to the form view:

xml

<record id="view_product_form" model="ir.ui.view">
    <field name="name">product.template.form</field>
    <field name="model">product.template</field>
    <field name="arch" type="xml">
        <form string="Product">
            <sheet>
                <group>
                    <field name="name"/>
                    <field name="default_code"/>
                </group>

                <!-- Adding a notebook with two pages -->
                <notebook>
                    <!-- First Tab: Description -->
                    <page string="Description">
                        <group>
                            <field name="description"/>
                        </group>
                    </page>
                    
                    <!-- Second Tab: Additional Information -->
                    <page string="Additional Info">
                        <group>
                            <field name="features"/>
                            <field name="additional_info"/>
                        </group>
                    </page>
                </notebook>
            </sheet>
        </form>
    </field>
</record>
    

Step 3: Explanation of the Code

  • ▹ Notebook: The <notebook> element defines the overall notebook (tab group).
  • ▹ Page The <page> element creates individual tabs within the notebook. The string attribute defines the tab label.
  • ▹ Fields: Fields are placed inside each tab using the <field> element. You can group fields together within a tab using the <group> element for better alignment.

Step 4: Testing the Notebook and Pages

Once you’ve defined the notebook and pages in the view, you can test it by upgrading your custom module. Open the form view of the corresponding model (in this case, the product form) and you should see the fields displayed under two separate tabs—Description and Additional Info.

Step 5: Extending the Notebook

Notebooks can contain any number of tabs, and each tab can include multiple fields or field groups. For instance, if you wanted to add a third tab for pricing details, you could easily extend the form as follows:

xml

<page string="Pricing">
    <group>
        <field name="list_price"/>
        <field name="standard_price"/>
    </group>
</page>
    

This will add a third tab labeled "Pricing" to your notebook, where you can input pricing information.

Best Practices for Using Notebooks in Odoo

  • ▹ Logical Grouping: Group fields into tabs based on their functionality or relevance. For example, separate general information from pricing or technical details.
  • ▹ Keep it Simple: Don’t overwhelm users with too many tabs. Focus on making navigation easier, not more complex.
  • ▹ Consider Tab Order: Place the most important or frequently used tabs first to improve user efficiency.

Conclusion

Adding a notebook and pages to Odoo forms is an excellent way to enhance the organization and usability of your forms. By following this step-by-step guide, you can implement notebooks in your own custom modules, improving user experience and ensuring your Odoo applications are more scalable and efficient.

Make a Comment

Your email address will not be published. Required fields are marked *