Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1059 Visualizzazioni

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
Abbandona
Risposta migliore

Hi,

Make your field stored, then Odoo can aggregate it.

Example:

x_offener_betrag_calc = fields.Float(

    string="Not Invoiced Amount",

    compute="_compute_offener_betrag",

    store=True

)


@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


Now your field is stored in the database, so you can use it in graph views, pivot views, and filters.


You can sum it by month, partner, or any other group.


Hope it helps

Avatar
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
set 25
2
0
set 25
2
2
set 25
331
0
set 25
1
0
set 25
1