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

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.

Awatar
Odrzuć
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!

Najlepsza odpowiedź

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.



Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
mar 17
3222
0
mar 15
4294
1
lut 25
4263
1
lis 24
1549
1
wrz 24
1580