Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
438 Widoki

Hello,

I am trying to add custom fields in the list of measures in Odoo 18.0. Below is my sale_report.py and sale_report_views.xml.



I get below error when entering the view:
Caused by: Error: No aggregate function has been provided for the measure 'rct_origin'

Can someone help me identify the problem?

Thanks.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,


You are getting the error because rct_origin is a Char field and cannot be used as a measure in a pivot view.

Pivot measures must be of type float or integer since they need to support aggregate functions like sum, average, etc.

Using type="measure" on a Char field causes Odoo to throw: "No aggregate function has been provided for the measure".

To fix the issue, you should use type="row" or type="col" instead of type="measure" for Char or Selection fields.

Update your XML view as follows:

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

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

This will allow the pivot table to group data by origin and destination, which is appropriate for string-type fields.

If you need an actual measure, you can create a numeric computed field (e.g., a count or boolean flag as integer) and use that instead.


Hope it helps.

Awatar
Odrzuć
Autor

Thanks for the reply. Was very useful.

Najlepsza odpowiedź

You'll need to define an aggregator attribute on that field. See options here: https://www.odoo.com/documentation/18.0/developer/reference/backend/orm.html#fields -> aggregator

For example:

x = fields.Float(aggregator='sum')
Awatar
Odrzuć