跳至內容
選單
此問題已被標幟
2 回覆
1069 瀏覽次數

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?


頭像
捨棄
最佳答案

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

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
10月 25
125
0
9月 25
2
0
9月 25
2
2
9月 25
340
0
9月 25
1