Search code examples
pythonodoo

create graph from attributes of a table


I want to add a pie chart showing the product with the quantity available, for this I have a table called product and in it is the name with the quantity available. The problem is that I try to create the view but I get an error. The work code is as follows:

    <record model = "ir.ui.view" id = "inventory_graph_view">

        <field name = "name"> Inventory </field>

        <field name = "model"> project_rc.product </field>

        <field name = "arch" type = "xml">

            <graph string = "Inventory">

                <field name = "name" type = "row" />

                <field name = "quantity_available" type = "col" />

            </graph>

        </field>

    </record>

    <record model = "ir.actions.act_window" id = "project_rc.product_action_window">

    <field name = "name"> Product registration </field> <! - add name to outside screen ->

    <field name = "res_model"> project_rc.product </field>

    <field name = "view_mode"> tree, form, graph </field>

    </record>

and the error presented is the following:

Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True

help me please


Solution

  • Field quantity_available is compute field in your model, compute field doesn't store field value in the database but computes it on the fly. The graph feature relies on database groupby functionality which can not perform here because column not available in database. What you have to do is set store=True in the quantity_available field definition. Also in case of stored compute value, you must define @api.depends carefully, as recompute of the stored value depends on the decorator.