Web Graph Widget | Graph Widget | Bar Chart Widget | Line Chart Widget | Pie Chart Widget | Doughnut Chart Widget | PolarArea Chart Widget | Radar Chart Widget
by CFIS https://www.cfis.store$ 52.05
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
•
Sales (sale_management)
• Discuss (mail) • Invoicing (account) |
| Lines of code | 439 |
| Technical Name |
web_graph_widget |
| License | See License tab |
| Website | https://www.cfis.store |
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
•
Sales (sale_management)
• Discuss (mail) • Invoicing (account) |
| Lines of code | 439 |
| Technical Name |
web_graph_widget |
| License | See License tab |
| Website | https://www.cfis.store |
Web Graph Widget | Graph Widget | Bar Chart Widget | Line Chart Widget | Pie Chart Widget | Doughnut Chart Widget | PolarArea Chart Widget | Radar Chart Widget
This module provides beautiful graphs into your forms views, It allows you to display the Bar, Line, Pie, Dougnut, Polar Area or Radar chart.
Installation
- Copy web_graph_widget module to addons folder
- Install the module normally like other modules
1. Model Setup
In your model you need to create a function that returns a Chart Widget's graph data, for example:
from odoo import models, fields, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
graph_data = fields.Char(
string='Graph Data',
compute='_compute_graph_data',
store=False,
help='Dummy field to hold graph widget for visualization'
)
@api.depends('amount_untaxed', 'amount_tax', 'amount_total')
def _compute_graph_data(self):
"""Compute graph data field - this is just a placeholder for the widget"""
for record in self:
record.graph_data = 'graph'
def compute_amount_bar_chart(self):
"""Return chart configuration for amount breakdown - Bar Chart"""
self.ensure_one()
return {
'type': 'bar',
'data': {
'labels': ['Untaxed', 'Tax', 'Total'],
'datasets': [{
'label': 'Amount Breakdown',
'data': [
float(self.amount_untaxed or 0),
float(self.amount_tax or 0),
float(self.amount_total or 0)
],
'backgroundColor': ['#4CAF50', '#FF9800', '#2196F3'],
}]
},
'options': {
'responsive': True,
'maintainAspectRatio': False,
'plugins': {
'legend': {'display': False},
'title': {
'display': True,
'text': 'Sales Order Amount Breakdown'
}
}
}
}
â More samples you can find on the sale order view.
2. XML Definition
In the XML definition you should write something like this:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_order_form_graph_widget" model="ir.ui.view">
<field name="name">sale.order.form.graph.widget</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Analytics Dashboard" name="analytics_dashboard">
<group>
<field
name="graph_data"
widget="graph_view"
graph_method="compute_amount_bar_chart"
graph_width="600px"
graph_height="300px"
nolabel="1"
/>
</group>
</page>
</xpath>
</field>
</record>
</odoo>
3. Examples
Sales -> Orders -> Analytics Dashboard
Features
Help and Support
Web Graph Widget | Graph Widget | Bar Chart Widget | Line Chart Widget | Pie Chart Widget | Doughnut Chart Widget | PolarArea Chart Widget | Radar Chart Widget
This module provides beautiful graphs into your forms views, It allows you to display the Bar, Line, Pie, Dougnut, Polar Area or Radar chart.
XML Add widget="graph_widget" to a char field in your form view with graph configuration: <field
name="graph_data" widget="graph_widget" graph_method="compute_amount_bar_chart" graph_width="150px" graph_height="300px" nolabel="1"/>
PY class SaleOrder(models.Model): _inherit = 'sale.order'
- graph_data = fields.Char(
string='Graph Data', compute='_compute_graph_data', store=False, help='Dummy field to hold graph widget for visualization'
)
@api.depends('amount_untaxed', 'amount_tax', 'amount_total') def _compute_graph_data(self):
"""Compute graph data field - this is just a placeholder for the widget""" for record in self:
record.graph_data = 'graph'
- def compute_amount_bar_chart(self):
"""Return chart configuration for amount breakdown - Bar Chart""" self.ensure_one() return {
'type': 'bar', 'data': {
'labels': ['Untaxed', 'Tax', 'Total'], 'datasets': [{
'label': 'Amount Breakdown', 'data': [
float(self.amount_untaxed or 0), float(self.amount_tax or 0), float(self.amount_total or 0)
], 'backgroundColor': ['#4CAF50', '#FF9800', '#2196F3'],
}]
}, 'options': {
'responsive': True, 'maintainAspectRatio': False, 'plugins': {
'legend': {'display': False}, 'title': {
'display': True, 'text': 'Sales Order Amount Breakdown'
}
}
}
}
Installation
- Copy web_graph_widget module to addons folder
- Install the module normally like other modules.
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module