[GNC] Budget report fails in multiple currencies

ml enquirer ml.hnel.227484 at gmail.com
Mon Jan 9 03:11:46 EST 2023


Here is a pull request that demonstrates a "better" handling of the
exchange. Basically, conversion to the report currency should happen
*after* the balance change has been computed, not before. If it happens
before, it makes the historical, cumulative total's exchange-rate
fluctuation during the budget period part of the result.

In the language of my last e-mail, this pull request computes "ES_12*X_1"
(but perhaps it should be "ES_12*X_2"... to be discussed).

https://github.com/Gnucash/gnucash/pull/1497

On Sun, Jan 8, 2023 at 9:34 AM ml enquirer <ml.hnel.227484 at gmail.com> wrote:

> Yes, it's cumulative, which is a problem I think.
>
> Let:
> 0 indicate the opening of the book
> 1 indicate the start of the budget period in question
> 2 indicate the end of that period
> S_i indicates the sum of transactions since 0 at marker i, in the currency
> of the sub-account
> P_i indicates the sum of transactions since 0 at marker i, in the currency
> of the parent account
> ES_ij indicates the sum of transactions during a period bounded by i and
> j, in sub-account currency
> X_i gives the exchange rate between sub-account and parent-account
>
> The trouble is that the report prints out:
>
> P_2 - P_1
> = S_2*X_2 - S_1*X_1
> = (S_1+ES_12) * X_2 - S_1 * X_1
> = ES_12 * X_2         +      S_1( X_2 - X_1)
>
> My problem is that I only really care about the first term, that contains
> ES_12. But as the years go by, S_1 >> ES_12, so the second term
> increasingly dominates. This becomes particularly visible when X_2-X_1 is
> significant, which has certainly been the case looking at GBP and EUR in
> recent years ;)
>
> By the way, I agree that "ES_12*X_2" is a bit trivial, and it would be
> nice to account for the variation of exchange rates during the year, but
> that's a second-order effect compared to this bug.
>
>
>
>
> To show this in the code:
>
> The "Actual" column in the budget report is populated by
> "gnc:get-account-periodlist-actual-value"
>
> https://github.com/Gnucash/gnucash/blob/master/gnucash/report/reports/standard/budget.scm#L404
>
> which just calls "gnc-budget-get-account-period-actual-value budget acct
> period"
>
> https://github.com/Gnucash/gnucash/blob/master/gnucash/report/reports/standard/budget.scm#L313
>
> which calls "gnc_budget_get_account_period_actual_value"
>
> https://github.com/Gnucash/gnucash/blob/master/libgnucash/engine/gnc-budget.cpp#L671gnc_budget_get_account_period_actual_value
>
> which calls "recurrenceGetAccountPeriodValue"
>
> https://github.com/Gnucash/gnucash/blob/master/libgnucash/engine/Recurrence.c#L421
> where the documentation says "@return the amount that an Account's value
> changed between the beginning  and end of the nth instance of the
> Recurrence."
>
> The problem is that this does:
>
> https://github.com/Gnucash/gnucash/blob/master/libgnucash/engine/Account.cpp#L3992
> gnc_numeric b1, b2;
> b1 = xaccAccountGetNoclosingBalanceAsOfDateInCurrency(acc, t1, NULL,
> recurse);
> b2 = xaccAccountGetNoclosingBalanceAsOfDateInCurrency(acc, t2, NULL,
> recurse);
> return gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
>


More information about the gnucash-user mailing list