Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
409 Vistas

My goal is to show the not invoiced amount of salesorders grouped by delivery date with a graph.


for this i created a custom field (type float, since we invoice in EUR and CHF and i dont want to mess around with currency problems and for forecasting is this ok) which gets calculated like this:

for record in self:

    record['x_offener_betrag_calc'] = record.amount_total - record.amount_invoiced


the field works properly, i also can aggregate it in lists with sum. but somehow i cant use it in the diagram view. two problems here:

1. i cant select the field in the "values" list and dont find any possibilit to bring it there.

2. if i add filter and adjust the context manually like this:


{'group_by': ['commitment_date:month', 'partner_id'], 'graph_measure': 'x_offener_betrag_calc', 'graph_mode': 'bar', 'graph_groupbys': ['commitment_date:month', 'partner_id'], 'graph_order': None, 'graph_stacked': True}


then i get the following error when applying the filter:


Uncaught Promise > No aggregate function has been provided for the measure 'x_offener_betrag_calc'


has anybody an idea how to make that work?


Avatar
Descartar
Mejor respuesta

Hii,


In your model, update the field like this:

x_offener_betrag_calc = fields.Float(

    string="Not Invoiced Amount",

    compute="_compute_offener_betrag",

    store=True,

    group_operator='sum',  # ← This line is required!

)

@api.depends('amount_total', 'amount_invoiced')

def _compute_offener_betrag(self):

    for record in self:

        record.x_offener_betrag_calc = record.amount_total - record.amount_invoiced

Example Graph View XML with the Custom Field:

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

    <field name="name">sale.order.graph.offener.betrag</field>

    <field name="model">sale.order</field>

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

        <graph string="Open Sales by Delivery Date" type="bar" stacked="True">

            <field name="commitment_date" type="row" interval="month"/>

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

            <field name="x_offener_betrag_calc" type="measure"/>

        </graph>

    </field>

</record>

 i  hope it is use full

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 25
73
0
jul 25
150
2
jul 25
755
1
jul 25
224
0
jul 25
144