Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
1379 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
lis 25
90
2
lis 25
141
0
říj 25
394
0
říj 25
14
1
říj 25
290