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

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
Zrušit
Autor

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!

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
bře 17
3222
0
bře 15
4294
1
úno 25
4263
1
lis 24
1549
1
zář 24
1580