参考
https://github.com/odoo/odoodays-2014/blob/master/cube_views/index.rst
Develop cube views for your own objects
.. Géry Debongnie
.. image:: images/biview.png :width: 100%
.. image:: images/overview.png :align: center
.. image:: images/bistructure.png :align: center
pivot table: keeps the data, calls the ORM
graph widget : user interaction
graph view : client interaction
.. code-block:: xml
<record id="..." model="ir.ui.view">
<field name="name">crm.opportunity.report.graph</field>
<field name="model">crm.lead.report</field>
<field name="arch" type="xml">
<graph string="Leads Analysis" type="pivot" stacked="True">
<field name="date_deadline" type="row"/>
<field name="stage_id" type="col"/>
<field name="planned_revenue" type="measure"/>
</graph>
</field>
</record>
In graph tag:
In field tags, type attribute:
Always want to be different: date/datetime have a special syntax for groupby:
.. code-block:: xml
<graph string="Leads Analysis" type="pivot" stacked="True">
<field name="date_deadline:week" type="row"/>
<field name="stage_id" type="col"/>
<field name="planned_revenue" type="measure"/>
</graph>
Graph widget has two more options:
Odoo BI view will read the various fields. Depending on their type, it will use them for
The data needs to satisfy two conditions:
If yes, you're done. If not, two possibilities:
.. .. image:: images/choices2.png .. :align: center .. :width: 100%
Bottom line: it needs to be in the DB
WARNING: old API... Do not try this at home!!!
.. code-block:: python
class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
def _total_invoice(self, cr, uid, ids, ...):
...
# [insert here nice looking code to
# compute the total invoice of a customer]
...
return result
_columns = {
'total_invoiced': fields.function(_total_invoice,
string="Total Invoiced", type='float', store=True)
}
.. note::
second warning: untested code!! this is just a proof of concept
to illustrate the point
emphasize that store=true is required, otherwise it will not work
.. give code example
.. image:: images/postgresview.png :align: center
Example: purchase/report/purchase_report.py
All reporting views use that technique. Warning: bypass the ORM
Good for testing.
Add the desired graph view:
.. code-block:: xml
<record id="view_project_task_graph" model="ir.ui.view">
<field name="name">project.task.graph</field>
<field name="model">project.task</field>
<field name="arch" type="xml">
<graph string="Project Tasks" type="bar">
<field name="project_id" type="row"/>
<field name="planned_hours" type="measure"/>
</graph>
</field>
</record>
Add it to the action:
.. code-block:: xml
<record id="action_view_task" model="ir.actions.act_window">
...
<field name="view_mode">kanban,tree,form,calendar,gantt,graph</field>
...
You can force the correct view:
.. code-block:: xml
<field name="view_id" ref="view_project_task_graph"/>
In js, create a widget and append it to your view:
.. code-block:: javascript
this.graph_widget = new openerp.web_graph.Graph(
this,
some_model,
some_domain,
options);
this.graph_widget.appendTo(this.$el);