GnuCash
Contact   Instructions
Bug 798019 - Currency rates in OFX file are ignored
Summary: Currency rates in OFX file are ignored
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Import - OFX (show other bugs)
Version: 3.8
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: import
QA Contact: import
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-22 10:08 EST by Dmitry Pavlov
Modified: 2021-02-09 18:13 EST (History)
5 users (show)

See Also:


Attachments
patched source file (50.32 KB, text/x-csrc)
2021-02-09 16:45 EST, Norbert Kaiser
no flags Details
ofx File with currency_ratio (5.96 KB, application/vnd.intu.qfx)
2021-02-09 16:46 EST, Norbert Kaiser
no flags Details

Description Dmitry Pavlov 2020-11-22 10:08:37 EST
Ofx statement lines may contain information about currency rates (see p105 in ofx spec: https://www.ofx.org/downloads/OFX%202.2.pdf)

I tried to import file that contains CURRENCY section as well as ORIGCURRENCY - no luck for both options, rate is just ignored.

This complicates importing transactions that are of different currencies (e.g. account where import is done is in USD and source account is in EUR). Right now Gnucash will always set conversion rate to 1 that is misleading in most of the times and requires manual fixes after import is done.

P.S. I see that libofx has support for all the tags, not sure if there is somethig wrong with parsing or Gnucash simply ignores this now.

CURRENCY: https://github.com/libofx/libofx/blame/master/lib/ofx_container_transaction.cpp#L151
ORIGCURRENCY: https://github.com/libofx/libofx/blame/master/lib/ofx_container_transaction.cpp#L156
CURRATE:https://github.com/libofx/libofx/blame/master/lib/ofx_container_transaction.cpp#L442
Comment 1 Norbert Kaiser 2020-12-05 04:38:53 EST
Hello,

the missing effect of the exchange rate makes the use of OFX import for shares, options not usable for international trading. Here simply too many transactions result, which must be reworked. It seems to be the same problem also in the unfortunately still open bug 577032. Unfortunately I can't do enough c programming to help myself.
Is there anything I can do to solve the bug?

Many greetings
Norbert
Comment 2 Norbert Kaiser 2020-12-05 04:40:26 EST
found in version 4.2
Comment 3 Norbert Kaiser 2020-12-05 09:13:15 EST
example:
<UNITS>1</UNITS>
<UNITPRICE>319.28855</UNITPRICE>--the rate must be applied to these values
<COMMISSION>0</COMMISSION>      --the rate must be applied to these values
<TAXES>0</TAXES>                --the rate must be applied to these values
<TOTAL>-319.28855</TOTAL>       --the rate must be applied to these values
<CURRENCY>
    <CURRATE>0.8425</CURRATE> ---- the rate
    <CURSYM>USD</CURSYM>
</CURRENCY>
Comment 4 John Ralls 2020-12-05 13:31:28 EST
(In reply to Norbert Kaiser from comment #1)
> Hello,
> 
> the missing effect of the exchange rate makes the use of OFX import for
> shares, options not usable for international trading. Here simply too many
> transactions result, which must be reworked. It seems to be the same problem
> also in the unfortunately still open bug 577032. Unfortunately I can't do
> enough c programming to help myself.
> Is there anything I can do to solve the bug?
> 
> Many greetings
> Norbert

This isn't quite the same as bug 577032, though fixing that would be a prerequisite to fixing this. This is a little more involved: GnuCash isn't very good at handling transactions with more than 2 commodities/currencies regardless of how they're entered. See bug 797796 for a very long discussion about that.

Fixing the bug requires programming in C, so it would seem that the only thing you can do is to sharpen your C skills enough to add currency recognition and conversion to GnuCash's OFX importer.
Comment 5 Norbert Kaiser 2020-12-13 12:58:05 EST
Hello,

I have now dealt with the topic even further. The cause seems to be in lib_ofx. The whole currency section is not taken into account. In the log appears every time:

LibOFX INFO: Created OfxDummyContainer to hold unsupported aggregate CURRENCY

If the section is ignored, it is also not possible to convert. :-(

So the bug should belong to the lib_ofx section.

Many greetings
Norbert
Comment 6 John Ralls 2020-12-13 13:23:50 EST
I think what you mean is that you need to open a new issue at https://github.com/libofx/libofx/issues, and both that this bug (which is in the correct component) and 577032 will depend on it being implemented there.
Comment 7 Norbert Kaiser 2020-12-13 14:33:39 EST
found in ofx_lib doc:

OfxCurrency Struct Reference

Detailed Description

NOT YET SUPPORTED.

Definition at line 708 of file inc/libofx.h.
Comment 8 Norbert Kaiser 2021-02-09 16:44:03 EST
Hi,
I solved the problem with changes in the gnc-ofx-import.c file. Here is my proposed solution. For this lib_ofx-0.10 is needed. Thanks to jeffjl74 and cstim for the version of lib_ofx! Furthermore I have attached an ofx file for testing.  For the function it is necessary that the base currency in gnucash matches the one in the ofx file. 

I would be happy if you would include the solution in the next release of gnucash.

Many greetings
Norbert

Translated with www.DeepL.com/Translator (free version)
Comment 9 Norbert Kaiser 2021-02-09 16:45:26 EST
Created attachment 373998 [details]
patched source file
Comment 10 Norbert Kaiser 2021-02-09 16:46:54 EST
Created attachment 373999 [details]
ofx File with currency_ratio
Comment 11 John Ralls 2021-02-09 18:13:56 EST
Thanks. I've rewritten your changes to be easier to #ifdef and added the CMakeLists conditional logic. It will appear in GnuCash 4.5.

If you feel motivated to contribute again please create a proper patch or Github pull request. See https://wiki.gnucash.org/wiki/Development#Submitting_Patches for details.

Note You need to log in before you can comment on or make changes to this bug.