Bug 342047 - Price quote importer does not take into account locale settings
Summary: Price quote importer does not take into account locale settings
Status: RESOLVED FIXED
Alias: None
Product: libalkimia
Classification: Frameworks and Libraries
Component: Online quotes widget (show other bugs)
Version: 8.1.2
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-20 12:54 UTC by David Houlden
Modified: 2024-03-13 17:10 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 8.2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Houlden 2014-12-20 12:54:49 UTC
In webpricequote.cpp there is the following code and comment.

if (priceRegExp.indexIn(quotedata) > -1) {
      gotprice = true;

      // Deal with european quotes that come back as X.XXX,XX or XX,XXX
      //
      // We will make the assumption that ALL prices have a decimal separator.
      // So "1,000" always means 1.0, not 1000.0.
      //
      // Remove all non-digits from the price string except the last one, and
      // set the last one to a period.
      QString pricestr = priceRegExp.cap(1);

      int pos = pricestr.lastIndexOf(QRegExp("\\D"));
      if (pos > 0) {
        pricestr[pos] = '.';
        pos = pricestr.lastIndexOf(QRegExp("\\D"), pos - 1);
      }
      while (pos > 0) {
        pricestr.remove(pos, 1);
        pos = pricestr.lastIndexOf(QRegExp("\\D"), pos);
      }

      d->m_price = pricestr.toDouble();
      kDebug(Private::dbgArea()) << "Price" << pricestr;
      emit status(i18n("Price found: %1 (%2)", pricestr, d->m_price));
    }

This causes problems with a quote source I have which doesn't return decimal places if they are zero.

e.g. The source returns 1,065.25 and this correctly gets interpreted as 1065.25 but if the source returns 1,065 this is interpreted as 1.065 instead of 1065.00

Could KMyMoney use the locale thousand separator and decimal indicator when interpreting prices from quote sources?

Reproducible: Always
Comment 1 Thomas Baumgart 2014-12-29 08:34:36 UTC
Don't know. What about the use case that I have setup my system to use the German locale but import prices from a source using a US/UK locale (so usage of comma and period in a number are reverse)? One idea that just crosses my mind is to have some sort of format option for each price source or specify the thousands separator and decimal delimiter for each of them in the settings.
Comment 2 Ralf Habacker 2024-03-05 22:07:09 UTC
> In webpricequote.cpp th

Assigned to libalkimia, as this support was outsourced to the aforementioned library.
Comment 3 Ralf Habacker 2024-03-05 22:18:19 UTC
This issue may be related to bug 432770.
Comment 4 Ralf Habacker 2024-03-05 22:25:39 UTC
Git commit 55a0d05a414850df9a4bf12843e022d61fe42f0d by Ralf Habacker.
Committed on 05/03/2024 at 22:25.
Pushed by habacker into branch 'master'.

Add additional unit test for parsing prices using 'x,yyy'

M  +5    -0    autotests/alkonlinequoteprivatetest.cpp

https://invent.kde.org/office/alkimia/-/commit/55a0d05a414850df9a4bf12843e022d61fe42f0d
Comment 5 Ralf Habacker 2024-03-05 22:25:50 UTC
(In reply to David Houlden from comment #0)
> but if the source returns 1,065 this is interpreted as 1.065 instead
> of 1065.00

This is still the case
Comment 6 Bug Janitor Service 2024-03-07 20:30:35 UTC
A possibly relevant merge request was started @ https://invent.kde.org/office/alkimia/-/merge_requests/26
Comment 7 Ralf Habacker 2024-03-13 17:10:52 UTC
Git commit f4b8e6d3a30260174ddc7a99cdf6d421d057e622 by Ralf Habacker.
Committed on 13/03/2024 at 17:00.
Pushed by habacker into branch 'master'.

Add support to select decimal separator used for parsing prices

To support the previous behaviour, an "old" decimal separator has also
been added as existing users may rely on it. For existing online source
definitions, this variant is automatically used as the default.
FIXED-IN:8.2

M  +37   -1    autotests/alkonlinequoteprivatetest.cpp
M  +3    -0    autotests/alkonlinequotesourcetest.cpp
M  +30   -16   src/alkonlinequote_p.cpp
M  +1    -1    src/alkonlinequote_p.h
M  +110  -84   src/alkonlinequotedetails.ui
M  +13   -1    src/alkonlinequotesource.cpp
M  +13   -1    src/alkonlinequotesource.h
M  +18   -1    src/alkonlinequotesource_p.h
M  +6    -0    src/alkonlinequoteswidget.cpp

https://invent.kde.org/office/alkimia/-/commit/f4b8e6d3a30260174ddc7a99cdf6d421d057e622