Hello odooers & developers,
Introduction
Welcome to another Odoo technical article,.In Odoo, the Widget Percentile is a visual representation of the data corresponding to the distribution modeled by percentiles. It is defined as the distance of a value from all values in the dataset. This percentage shows how a certain value is compared with all other values by presenting data on percentiles. To put that another way, it provides the means to look at the call-in relative position for a particular dataset by offering percentiles. The widget therefore finds good use in analyzing performance metrics, sales data, or any other numerical information for smooth interpretation. I would like to share more knowledge about the percentpie widget in Odoo 17.
The percentpie widget is used to graphically represent a percentage value as a pie chart.
This widget is particularly useful for displaying:
- Completion rates
- Progress tracking
- Discount rates
- Other percentage-based metrics
In this article, we will cover:
- How the percentpie widget works in Odoo 17
- Defining a Float field to store percentage values
- Adding the percentpie widget to a form view
- Implementing percentpie in a kanban view
By the end of this guide, you’ll be able to effectively use the percentpie widget in your Odoo projects.
Understanding the percentpie Widget
The percentpie widget in Odoo is designed to replace a numeric percentage value with a graphical pie chart representation.
Key Benefits of percentpie Widget:
- Provides a visual indicator instead of plain numbers
- Enhances user experience in dashboards & forms
- Dynamically adjusts the pie chart based on value
- Works in form views and kanban views
Example Use Cases:
Project Completion Rate (e.g., 75% done)
Task Progress Visualization (e.g., 60% completed)
Discount Rate Representation (e.g., 8% discount)
Performance Metrics in Kanban Views
Defining the Field in the Model
To use the percentpie widget, we first need to define a Float field in our model to store the percentage value.
Python Model (.py)
.py
<from odoo import models, fields
<class Mall(models.Model):
_name = 'mall.shop'
_description = 'Shop'
<rate = fields.Float(string='Discount Rate', default=8.0, help="Enter a percentage value")
Explanation:
- The rate field is defined as a Float field to hold the percentage value.
- The default=8.0 sets an initial value of 8%.
- The help attribute provides a tooltip for user guidance.
Adding the percentpie Widget in the View
Next, we will add the rate field to the form view and specify the percentpie widget.
XML Form View (.xml)
.py
<record id="view_shop_form" model="ir.ui.view">
<field name="name">view.shop.form</field>
<field name="model">mall.shop</field>
<field name="arch" type="xml">
<form string="Shop">
<sheet>
<group>
<field name="name"/>
<field name="rate" widget="percentpie"/>
</group>
</sheet>
</form>
</field>
</record>
Explanation:
- The widget="percentpie" is applied to the rate field.
- The percentage value is now displayed as a pie chart instead of a number.
XML Kanban View (.xml)
.py
<record id="view_your_model_kanban" model="ir.ui.view">
<field name="name">your.model.kanban.view</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name="kanban-box">
<div class="o_kanban_record">
<strong><t t-esc="record.name.value"/></strong>
<div class="o_field_widget o_field_float" t-field="record.rate" widget="percentpie"/>
</div>
</t>
</templates>
</kanban>
</field>
</record>
Why Use percentpie in Kanban View?
- Ideal for dashboards and reports
- Provides quick insights without opening individual records
- Enhances task progress visualization
Conclusion
The percentpie widget in Odoo is a powerful tool for graphically representing percentage-based values. Whether you need to visualize task progress, discount rates, or completion percentages, this widget enhances the user experience by making data more engaging.
Key Takeaways:
- Easily integrates with Float fields
- Works in Form and Kanban views
- Enhances user experience with visual representation
By implementing and customizing the percentpie widget, you can create more interactive dashboards and improve readability for percentage-based metrics in Odoo 17.
If you want odoo technical training on any odoo version , please let us know by mail at [email protected]. Then our odoo expoert will conduct odoo online or offline training with you
Devintellecs & team are odoo training providers in the USA and INDIA, so we will try our best to give the training either individal or any bulk employee company.
If you want to check your odoo technical or functional knowledge, then we have prepared the odoo EXam practice test for the odoo technical & functional people.
Customizing Widget Percentpie in odoo