[GNC-dev] Extending GnuCash: CSV-import/lookup commodity by cusip
John Ralls
jralls at ceridwen.us
Fri Jan 21 13:53:26 EST 2022
> On Jan 21, 2022, at 9:32 AM, Thomas <tduellmann+gnucashdevel at gmail.com> wrote:
>
> Dear list,
>
> recently, I spotted a feature that I would love to have added to GnuCash. As I have a software development background, I could definitely contribute to the solution, but as it is quite some time ago that I developed in C++ and am new to contributing to GnuCash, I might need some cues.
>
> Desired feature:
> When importing prices from a CSV file, the matching to existing commodities seems to be possible only based on the symbol. What would be really helpful for me would be, if this matching could also be done by cusip.
>
> The optimal scenario would be the possiblity to choose either "symbol" or "cusip" in the dropdown list above the columns and then use another method that retrieves the respective commodity as done in gnucash/import-export/csv-imp/gnc-imp-props-price.cpp:106 using the symbol_str.
>
> From the functional point of view, I am currently only lacking an idea on how such a lookup based on the cusip would look like, as there seems only to be a 'gnc_commodity_table_lookup' function that only takes namespace and symbol. Would a respective method also need to be implemented or what would be the proper approach for looking up a commodity by cusip?
>
> Thanks a lot in advance and would be grateful for any hint in this regard!
Yes, you'd need to write a search function to find commodities by cusip. Commodities are currently stored in a nested hash table so the least-code method would be to use g_hash_table_foreach on each and test each commodity's cusip for a match. Iterating over hash tables isn't exactly efficient so that would be pretty slow.
The more performant way would be to create a separate hash table keyed on the cusip field and load it as part of gnc_commodity_table_insert and gnc_commodity_set_cusip.
If your C++ experience is with pre C++-11 you've got a lot of learning to do. The language has changed a lot.
Regards,
John Ralls
More information about the gnucash-devel
mailing list