GNOME Bugzilla – Bug 733522
gnucash --add-price-quotes fails to update currency price if exchange rate returned by Finance::Quote is in exponential form
Last modified: 2018-06-29 23:32:17 UTC
GnuCash fails to load exchange rate BYR to USD(Currently 1 EUR = 13900 BYR). The inverse rate is 7.19424460431655e-05 and it seems like GnuCash is not able to handle exchange rates in exponential form. I did solve my problem by replacing the following line in Quote.pm: 277: return ($exchange_rate * $amount); with 277: return sprintf("%.8f",$exchange_rate * $amount); Now it returns 0.00007194 and currency price is being updated correct, but I still believe that GnuCash should handle such situation properly, because 7.19424460431655e-05 is absolutely valid number presentation.
Yes, it is, but GnuCash's parser isn't smart enough to read it. This will be addressed in the new numeric system for 2.8.
Perhaps, if can be fixed easily in Quote.pm, you should submit your patch to https://rt.cpan.org/Public/Dist/Display.html?Status=Active&Name=Finance-Quote and we could close it here. But I am not shure about information loss in case the format is to small. @jralls: Could gnucash import it as rationale?
Frank, sure, it should be able to. gnc-fq-helper (which is perl, BTW) returns: $ aeolus:r-git/build/gnucash-git> gnc-fq-helper (currency "BYR" "USD") (("BYR" (symbol . "BYR") (last . 6.757e-05) (currency . "USD"))) The number is passed to double-to-gnc-numeric in src/scm/price-quotes.scm, which should be a scheme wrapper for double_to_gnc_numeric. It ought to return 6757/100000000. This is clearly a GnuCash problem, it shouldn't be sent upstream; if it turns out to be a Guile shortcoming we can fix it in gnc-fq-helper.
I just tested a USD->BYR transaction including retrieving the exchange rate with F::Q, and the resulting rate was 225/3397252, which Python reports as 6.623000001177423e-05; the input to double_to_gnc_numeric() from Scheme was 0.000066229999999999994, with 9 significant figures. The actual string from F::Q was 6.623e-05. That turned $67.50 into BYR 1,019,175.60, which appears to me to be correct. I see no problem here. OP, what exactly did you do and what went wrong?
I update gnucash's price database with "gnucash --add-price-quotes" command every day. In fact, I have a script that switches default currency from BYR to USD then does "gnucash --add-price-quotes" to load exchange rate. Then it switches default currency back to BYR and does "gnucash --add-price-quotes" again to load reverse exchange rate. Doing this way I have both BYR-to-USD and USD-to-BYR exchange rates. To see the loaded rates I use Tools -> Price Editor. I tried to reproduce this issue. I reverted the aforementioned line in Quote.pm to its original value and ran my script. Only USD-to-BYR was loaded (its value is 15100 today). And that's the issue. Then I changed that line in Quote.pm to return sprintf("%.8f",$exchange_rate * $amount); again and ran the script once more. It loaded both exchange rates including BYR-to-USD (its value is 0.00006623 today).
OK. I can reproduce this with the 2.6.5 release, but not with the current maint branch, though I don't understand why. If you're able to build from source, please try that. If not, 2.6.6 will be out in a couple of weeks.
You are right. I see no issue with the latest maint code neither.
OK. I'll mark it fixed pending the release. Once you get the 2.6.6 release installed check it again and reopen this bug if it doesn't work.
Ok. Thank you for your time.
After update to 2.6.8 the issue is reproducible again. Same behaviour with 2.6.9. The difference from 2.6.5 is that the fix in Quote.pm does not help.
Are you sure? Since 2.6.8 GnuCash tries to save exchange rates in the direction that the value is > 1, precisely to avoid the problem of dealing with very small fractions. Your quotes should be in CURRENCY>USD>BYR.
Thanks. I see. In fact the exchange rate USD-EUR also stopped loading although it is not so small. So, now gnucash never uses BYR-USD exchange rate for reports in USD or BYR, but instead always uses USD-BYR. Am I right?
Not exactly. GC will only retrieve USD-BYR. EUR-USD might flip to USD-EUR if the Euro depreciates a bit more against the Dollar. It's set up so that it will preserve the direction on any particular day to maintain the one-quote rule and on the premise that a single-day move won't produce a small enough fraction to cause trouble. BYR->USD on the other hand is always small enough to cause trouble because of the 1000000 maximum denominator. Wm mentioned on the user list that I might have missed something in reports retrieving prices from the pricedb, though. I'll look into that today and make sure that reports get the right price according to the policy option regardless of the direction in the pricedb.
I just checked the asset piechart with "Most Recent" price source. Some of my accounts are in BYR, some in USD. Till 29.09.2015 there are both exchange rates BYR-TO-USD and USD-TO-BYR. Starting from 30.09.2015 there is only USD-TO-BYR. If the reports currency is BYR, the most recent USD-TO-BYR exchange rate(today's value, fine) is used. If the reports currency is USD - the most recent BYR-TO-USD exchange rate is used - a value from 29.09.2015 (bad).
*** Bug 756889 has been marked as a duplicate of this bug. ***
This is fixed in opposite directions in maint and master. In maint (so for the next stable release in December) the automatic inversion of prices has been reverted so that that part will return to the pre-2.6.8 behavior. The price db will still store only one price per day and will still prefer Finance::Quote prices over those originating from handling transactions. In master, for the next major release at the end of 2017, the automatic price inversion is retained and all lookups are made to check both directions for the latest price.
*** Bug 758748 has been marked as a duplicate of this bug. ***
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=733522. Please update any external references or bookmarks.