Hello Gnucash Users,
I have now downloaded the foreign exchange rates from the Reserve Bank
of Australia:
https://rba.gov.au/statistics/historical-data.html#exchange-rates
Note that the exchange rate data is published in an Excel .xls file. I
used LibreOffice to save it as a .csv for import into GnuCash.
In this file, the dates are formatted as DD-Mon-YYYY. For example:
18-May-2019
GnuCash cannot understand dates formatted this way. (I tested against
git 3.9-19 on branch maint.)
I made some modifications to gnucash/libgnucash/engine/gnc-datetime.cpp
that allow GnuCash to import the RBA data with word date months. The
changes are very rough, and do not include any internationalisation. I
would appreciate constructive feedback. Flames -> /dev/null.
I note here that I have not tested this patch with dates of format
DD-MM-YYYY.
Perhaps I should sign up to the gnucash-devel mailing list...
Ben.
On 7/4/20 7:28 pm, Christopher Lam wrote:
Yes, you can do that. File import prices from CSV.
On Tue, 7 Apr 2020, 5:22 pm Ben Stanley, <ben.stan...@gmail.com
<mailto:ben.stan...@gmail.com>> wrote:
I can get a CSV file of daily exchange rate data. Is there a way
of importing it into the price database?
On 7 April 2020 7:17:54 pm Christopher Lam
<christopher....@gmail.com <mailto:christopher....@gmail.com>> wrote:
The only report which is capable of using closest-to-date
conversion is the Transaction Report from the
Income:Dividends(USD) and Income:CapGains(USD) accounts, using a
Report Currency of AUD. It will choose the USD/AUD price from the
price editor list closest to each transaction's posting date.
You'll have to ensure the price list has prices at your desired
dates manually.
On Tue, 7 Apr 2020 at 09:13, Ben Stanley <ben.stan...@gmail.com
<mailto:ben.stan...@gmail.com>> wrote:
Hello Gnucash people,
This question may be more suited to Gnucash developers, but
lets try it
here first.
I need to perform a tax calculation in accordance with
instructions from
the Australian Taxation Office. All foreign income,
deductions and
foreign tax paid must be converted to Australian Dollars for
tax purposes.
https://www.ato.gov.au/Business/International-tax-for-business/In-detail/Investing-overseas/Converting-foreign-income-to-Australian-dollars/
The conversion used must correspond to the transaction date.
In Gnucash, it would appear that the price editor could be
used to enter
the necessary conversion data, if it were easy to see all of
the dates
where conversions are required. However, this is tedious.
Far better would be to use Finance::Quote to fetch the necessary
conversion data for the dates it is required for. However, it
seems that
Finance::Quote is only capable of fetching "recent" data. (The
documentation that I looked at seemed to be very old.)
http://finance-quote.sourceforge.net/documentation.html
What is needed is the ability to pass a date, or a range of
dates, and
request Finance::Quote to fetch prices for that date or date
interval.
This would make Finance::Quote far more useful than just
fetching the
most recent price data.
Is there some feature in Gnucash that I have missed that
would allow me
to generate a report, with dividends and Capital Gains
converted from
USD -> AUD using the currency conversion as at the
transaction dates?
Thanks,
Ben Stanley.
_______________________________________________
gnucash-user mailing list
gnucash-user@gnucash.org <mailto:gnucash-user@gnucash.org>
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
If you are using Nabble or Gmane, please see
https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.
Author: Ben Stanley <ben.stan...@gmail.com> 2020-04-08 00:32:32
Committer: Ben Stanley <ben.stan...@gmail.com> 2020-04-08 00:32:32
Parent: 2bdc9366958c243d9d3910921a0dc77ff3186cb7 (Merge Jean Laroche's '797006_subaccounts' into maint.)
Branch: GncDate_with_named_month
Follows: 3.9
Precedes:
Add support for named months in GncDate.
This is useful for importing data from external sources.
This preliminary patch works for months named in English.
No internationalisation support has been added.
The burden of enumerating month names and conversion
should be delegated to the boost library. This may simplify
internationalisation.
---------------------- libgnucash/engine/gnc-datetime.cpp ----------------------
index 2192ffd3f..641891145 100644
@@ -80,6 +80,9 @@ static constexpr auto ticks_per_second = INT64_C(1000000);
static constexpr auto ticks_per_second = INT64_C(1000000000);
#endif
+/* This will need localisation */
+#define MonthRegex "([0-9]+|Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)"
+
/* Vector of date formats understood by gnucash and corresponding regex
* to parse each from an external source
* Note: while the format names are using a "-" as separator, the
@@ -91,7 +94,7 @@ const std::vector<GncDateFormat> GncDate::c_formats ({
N_("y-m-d"),
"(?:" // either y-m-d
"(?<YEAR>[0-9]+)[-/.' ]+"
- "(?<MONTH>[0-9]+)[-/.' ]+"
+ "(?<MONTH>" MonthRegex ")[-/.' ]+"
"(?<DAY>[0-9]+)"
"|" // or CCYYMMDD
"(?<YEAR>[0-9]{4})"
@@ -103,7 +106,7 @@ const std::vector<GncDateFormat> GncDate::c_formats ({
N_("d-m-y"),
"(?:" // either d-m-y
"(?<DAY>[0-9]+)[-/.' ]+"
- "(?<MONTH>[0-9]+)[-/.' ]+"
+ "(?<MONTH>" MonthRegex ")[-/.' ]+"
"(?<YEAR>[0-9]+)"
"|" // or DDMMCCYY
"(?<DAY>[0-9]{2})"
@@ -114,7 +117,7 @@ const std::vector<GncDateFormat> GncDate::c_formats ({
GncDateFormat {
N_("m-d-y"),
"(?:" // either m-d-y
- "(?<MONTH>[0-9]+)[-/.' ]+"
+ "(?<MONTH>" MonthRegex ")[-/.' ]+"
"(?<DAY>[0-9]+)[-/.' ]+"
"(?<YEAR>[0-9]+)"
"|" // or MMDDCCYY
@@ -129,7 +132,7 @@ const std::vector<GncDateFormat> GncDate::c_formats ({
(N_("d-m")),
"(?:" // either d-m(-y)
"(?<DAY>[0-9]+)[-/.' ]+"
- "(?<MONTH>[0-9]+)(?:[-/.' ]+"
+ "(?<MONTH>" MonthRegex ")(?:[-/.' ]+"
"(?<YEAR>[0-9]+))?"
"|" // or DDMM(CCYY)
"(?<DAY>[0-9]{2})"
@@ -140,7 +143,7 @@ const std::vector<GncDateFormat> GncDate::c_formats ({
GncDateFormat {
(N_("m-d")),
"(?:" // either m-d(-y)
- "(?<MONTH>[0-9]+)[-/.' ]+"
+ "(?<MONTH>" MonthRegex ")[-/.' ]+"
"(?<DAY>[0-9]+)(?:[-/.' ]+"
"(?<YEAR>[0-9]+))?"
"|" // or MMDD(CCYY)
@@ -151,6 +154,8 @@ const std::vector<GncDateFormat> GncDate::c_formats ({
}
});
+#undef MonthRegex
+
/** Private implementation of GncDateTime. See the documentation for that class.
*/
static LDT
@@ -578,8 +583,56 @@ GncDateImpl::GncDateImpl(const std::string str, const std::string fmt) :
else /* The input dates have no year, so use current year */
year = m_greg.year(); // Can use m_greg here as it was already initialized in the initializer list earlier
+ std::string month_s = what.str("MONTH");
+ int month_i;
+ boost::regex month_r("[0-9]+");
+ boost::smatch month_what;
+ if ( boost::regex_match(month_s, month_what, month_r) )
+ {
+ month_i = std::stoi (month_s);
+ /* Refer to boost date constants. */
+ if ( month_i < 1 or month_i > 12 )
+ {
+ /* Needs internationalisation */
+ throw std::invalid_argument ("Value appears to contain a month but unable to recognise " + month_s + " as a month.");
+ }
+ }
+ else
+ {
+ /* Figure out how to use boost to do this for me. */
+ if ( month_s == "Jan" or month_s == "January" )
+ month_i = 1;
+ else if ( month_s == "Feb" or month_s == "February" )
+ month_i = 2;
+ else if ( month_s == "Mar" or month_s == "March" )
+ month_i = 3;
+ else if ( month_s == "Apr" or month_s == "April" )
+ month_i = 4;
+ else if ( month_s == "May" )
+ month_i = 5;
+ else if ( month_s == "Jun" or month_s == "June" )
+ month_i = 6;
+ else if ( month_s == "Jul" or month_s == "July" )
+ month_i = 7;
+ else if ( month_s == "Aug" or month_s == "August" )
+ month_i = 8;
+ else if ( month_s == "Sep" or month_s == "September" )
+ month_i = 9;
+ else if ( month_s == "Oct" or month_s == "October" )
+ month_i = 10;
+ else if ( month_s == "Nov" or month_s == "November" )
+ month_i = 11;
+ else if ( month_s == "Dec" or month_s == "December" )
+ month_i = 12;
+ else
+ {
+ /* Needs internationalisation */
+ throw std::invalid_argument ("Value appears to contain a month but unable to recognise " + month_s + " as a month.");
+ }
+ }
+
m_greg = Date(year,
- static_cast<Month>(std::stoi (what.str("MONTH"))),
+ static_cast<Month>(month_i),
std::stoi (what.str("DAY")));
}
_______________________________________________
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
If you are using Nabble or Gmane, please see
https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.