Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
102 Visualizzazioni

Hello, we are implementing Odoo since a couple of months. So still new to some of the tricks. 
Our company is trading in three different currencies, and we have these currencies set up in Accounting/Currencies with their exchange rates.


In the sales module, in pivot view, I can add the "Currency Rate" as a metric, but the displayed numbers are only correct on the level of the individual sales order number. 

Any summary does not show the average of the individual currency rates, but the sum of it. This is not what I need.

If I have 10 Transactions at a 0.8 currency rate, these transaction have a currency rate of 0.8 and not of 8, as it is displayed.

Avatar
Abbandona
Autore

Thanks a lot!

While your solution works, I found an easier option.
I found that after exporting the pivot to a spreadsheet, I get the option to edit the pivot parameters and set "Aggregate by" for the currency rate from "sum" to "average". 
So, for reporting purposes, this works well.
Thank you!

Risposta migliore

Hi,

You can add a computed stored field on sale.order that represents the currency rate as a float, but tell Odoo to aggregate it as an average in the pivot view.

from odoo import models, fields, api


class SaleOrder(models.Model):

    _inherit = 'sale.order'


    avg_currency_rate = fields.Float(

        string="Currency Rate (Avg)",

        compute="_compute_avg_currency_rate",

        store=True,

        group_operator="avg",  # 👈 Key point — use average aggregation

    )


    @api.depends('currency_rate')

    def _compute_avg_currency_rate(self):

        for order in self:

            order.avg_currency_rate = order.currency_rate


Hope it helps.



Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
mar 17
3221
0
mar 15
4294
1
feb 25
4262
1
nov 24
1548
1
set 24
1577