From c7f842c081ad794d2020f0b8417dfe3637c298c0 Mon Sep 17 00:00:00 2001 From: "Frank H. Ellenberger" Date: Thu, 8 Jul 2021 16:15:03 +0200 Subject: [PATCH 1/5] Bug 684507 - commodity namespace should be localized --- bindings/python/tests/test_commodity.py | 4 ++-- libgnucash/engine/gnc-commodity.c | 7 +++---- libgnucash/engine/gnc-commodity.h | 20 +++++++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/bindings/python/tests/test_commodity.py b/bindings/python/tests/test_commodity.py index 6eb2c0d2c8..36ffe6fc43 100644 --- a/bindings/python/tests/test_commodity.py +++ b/bindings/python/tests/test_commodity.py @@ -21,12 +21,12 @@ class TestCommodityNamespace(CommoditySession): #print(self.table.__class__) namespace_names = self.table.get_namespaces() #print(namespace_names) - self.assertEqual(namespace_names, ['AMEX', 'NYSE', 'NASDAQ', 'EUREX', 'FUND', 'template', 'CURRENCY']) + self.assertEqual(namespace_names, ['BOND', 'SHARE', 'FUND', 'OPTION', 'template', 'CURRENCY']) def test_namespaces_list(self): namespaces = self.table.get_namespaces_list() namespace_names = [ns.get_name() for ns in namespaces] - self.assertEqual(namespace_names, ['AMEX', 'NYSE', 'NASDAQ', 'EUREX', 'FUND', 'template', 'CURRENCY']) + self.assertEqual(namespace_names, ['BOND', 'SHARE', 'FUND', 'OPTION', 'template', 'CURRENCY']) if __name__ == '__main__': main() diff --git a/libgnucash/engine/gnc-commodity.c b/libgnucash/engine/gnc-commodity.c index 745be68bc6..01b17f38e6 100644 --- a/libgnucash/engine/gnc-commodity.c +++ b/libgnucash/engine/gnc-commodity.c @@ -2510,11 +2510,10 @@ gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book) gnc_commodity* c; ENTER ("table=%p", table); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_AMEX, book); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NYSE, book); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book); + gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_BOND, book); + gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_SHARE, book); gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book); + gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_OPTION, book); gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book); c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1); gnc_commodity_table_insert(table, c); diff --git a/libgnucash/engine/gnc-commodity.h b/libgnucash/engine/gnc-commodity.h index fda6045909..6336fb8237 100644 --- a/libgnucash/engine/gnc-commodity.h +++ b/libgnucash/engine/gnc-commodity.h @@ -104,21 +104,19 @@ GType gnc_commodity_namespace_get_type(void); * only used to populate an option menu in the commodity selection * window. */ -#define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES" -#define GNC_COMMODITY_NS_TEMPLATE "template" +#define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES" +#define GNC_COMMODITY_NS_TEMPLATE "template" /* The ISO define is deprecated in favor of CURRENCY */ -#define GNC_COMMODITY_NS_ISO "ISO4217" -#define GNC_COMMODITY_NS_CURRENCY "CURRENCY" -#define GNC_COMMODITY_NS_NASDAQ "NASDAQ" -#define GNC_COMMODITY_NS_NYSE "NYSE" -#define GNC_COMMODITY_NS_EUREX "EUREX" -#define GNC_COMMODITY_NS_MUTUAL "FUND" -#define GNC_COMMODITY_NS_AMEX "AMEX" -#define GNC_COMMODITY_NS_ASX "ASX" +#define GNC_COMMODITY_NS_ISO "ISO4217" +#define GNC_COMMODITY_NS_CURRENCY "CURRENCY" +#define GNC_COMMODITY_NS_BOND N_("BOND") +#define GNC_COMMODITY_NS_SHARE N_("SHARE") +#define GNC_COMMODITY_NS_MUTUAL N_("FUND") +#define GNC_COMMODITY_NS_OPTION N_("OPTION") #define GNC_COMMODITY_NS_NONCURRENCY _("All non-currency") /* Delay translation of this one, we use it in both translated and untranslated form when presenting the currency related namespace to the user */ -#define GNC_COMMODITY_NS_ISO_GUI N_("Currencies") +#define GNC_COMMODITY_NS_ISO_GUI N_("Currencies") /** Max fraction is 10^9 because 10^10 would require changing it to an * int64_t. From 716d746315aa6ad0bdc5a7fdfa9c3c0c7e65eb30 Mon Sep 17 00:00:00 2001 From: "Frank H. Ellenberger" Date: Thu, 8 Jul 2021 21:23:17 +0200 Subject: [PATCH 2/5] Adjust qif-dialog-utils to new namespaces For US users it will no longer distinguish between NASDAQ and NYSE but map both to SHARE for new commodities. --- .../qif-imp/qif-dialog-utils.scm | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/gnucash/import-export/qif-imp/qif-dialog-utils.scm b/gnucash/import-export/qif-imp/qif-dialog-utils.scm index f0f81e4f6c..6b0a036d24 100644 --- a/gnucash/import-export/qif-imp/qif-dialog-utils.scm +++ b/gnucash/import-export/qif-imp/qif-dialog-utils.scm @@ -736,7 +736,7 @@ ;; compatible with the QIF type? (and (string=? s (caddr elt)) (not (and (string? qif-type) - (string=? GNC_COMMODITY_NS_MUTUAL + (string=? (GNC-COMMODITY-NS-MUTUAL) (cadr elt)) (or (string-ci=? qif-type "stock") (string-ci=? qif-type "etf")))))) @@ -747,27 +747,15 @@ (pref-match (cadr pref-match)) - ;; Guess NYSE for symbols of 1-3 characters. - ((< l 4) - GNC_COMMODITY_NS_NYSE) - - ;; Guess NYSE for symbols of 1-3 characters - ;; followed by a dot and 1-2 characters. - ((and d - (< l 7) - (< 0 d 4) - (<= 2 (- l d) 3)) - GNC_COMMODITY_NS_NYSE) - - ;; Guess NASDAQ for symbols of 4 characters. - ((= l 4) - GNC_COMMODITY_NS_NASDAQ) + ;; Guess SHARE for symbols of 1-4 characters. + ((<= l 4) + (GNC-COMMODITY-NS-SHARE)) ;; Otherwise it's probably a fund. (else - GNC_COMMODITY_NS_MUTUAL))) + (GNC-COMMODITY-NS-MUTUAL)))) ;; There's no symbol. Default to a fund. - GNC_COMMODITY_NS_MUTUAL)) + (GNC-COMMODITY-NS-MUTUAL))) ;; Was a QIF type given? (if (string? qif-type) @@ -775,12 +763,12 @@ (cond ;; Mutual fund ((string-ci=? qif-type "mutual fund") - GNC_COMMODITY_NS_MUTUAL) + (GNC-COMMODITY-NS-MUTUAL)) ;; Index ((string-ci=? qif-type "index") ;; This QIF type must be wrong; indexes aren't tradable! - GNC_COMMODITY_NS_MUTUAL) + (GNC-COMMODITY-NS-MUTUAL)) (else (guess-by-symbol qif-symbol))) From 09296dfb96f2e88039c80337ad6f6d29d1040d62 Mon Sep 17 00:00:00 2001 From: "Frank H. Ellenberger" Date: Fri, 9 Jul 2021 18:44:06 +0200 Subject: [PATCH 3/5] Drop commodity-table.scm, no longer required after adjusting qif-dialog-utils --- bindings/guile/CMakeLists.txt | 1 - bindings/guile/commodity-table.scm | 44 -------------------- bindings/guile/engine.scm | 1 - gnucash/import-export/qif-imp/qif-to-gnc.scm | 2 +- libgnucash/app-utils/options.scm | 6 +-- po/POTFILES.in | 1 - 6 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 bindings/guile/commodity-table.scm diff --git a/bindings/guile/CMakeLists.txt b/bindings/guile/CMakeLists.txt index b5446b027e..0cbb7aa3f3 100644 --- a/bindings/guile/CMakeLists.txt +++ b/bindings/guile/CMakeLists.txt @@ -85,7 +85,6 @@ gnc_add_scheme_targets(scm-core-utils DEPENDS "${GUILE_DEPENDS}") set (engine_SCHEME_0 - commodity-table.scm gnc-numeric.scm business-core.scm ) diff --git a/bindings/guile/commodity-table.scm b/bindings/guile/commodity-table.scm deleted file mode 100644 index 511c1eaac3..0000000000 --- a/bindings/guile/commodity-table.scm +++ /dev/null @@ -1,44 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; commodity-table.scm -;;; load and save commodity tables -;;; -;;; Bill Gribble 3 Aug 2000 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License as -;; published by the Free Software Foundation; either version 2 of -;; the License, or (at your option) any later version. -;; -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, contact: -;; -;; Free Software Foundation Voice: +1-617-542-5942 -;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 -;; Boston, MA 02110-1301, USA gnu@gnu.org -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(define-module (gnucash engine commodity-table)) - -(export GNC_COMMODITY_NS_CURRENCY) -(export GNC_COMMODITY_NS_NASDAQ) -(export GNC_COMMODITY_NS_NYSE) -(export GNC_COMMODITY_NS_AMEX) -(export GNC_COMMODITY_NS_EUREX) -(export GNC_COMMODITY_NS_MUTUAL) - -(define GNC_COMMODITY_NS_CURRENCY "CURRENCY") - -;; If you change the C side, change this too. -(define GNC_COMMODITY_NS_AMEX "AMEX") -(define GNC_COMMODITY_NS_NYSE "NYSE") -(define GNC_COMMODITY_NS_NASDAQ "NASDAQ") -(define GNC_COMMODITY_NS_EUREX "EUREX") -(define GNC_COMMODITY_NS_MUTUAL "FUND") -(define GNC_COMMODITY_NS_ASX "ASX") -(define GNC_COMMODITY_NS_NONCURRENCY (gettext "ALL NON-CURRENCY")) diff --git a/bindings/guile/engine.scm b/bindings/guile/engine.scm index bc75b8172f..c7697068e6 100644 --- a/bindings/guile/engine.scm +++ b/bindings/guile/engine.scm @@ -28,7 +28,6 @@ (load-and-reexport (sw_engine) (gnucash engine business-core) - (gnucash engine commodity-table) (gnucash engine gnc-numeric)) (export gnc-pricedb-lookup-latest-before-t64) diff --git a/gnucash/import-export/qif-imp/qif-to-gnc.scm b/gnucash/import-export/qif-imp/qif-to-gnc.scm index cc785e8253..ec10404371 100644 --- a/gnucash/import-export/qif-imp/qif-to-gnc.scm +++ b/gnucash/import-export/qif-imp/qif-to-gnc.scm @@ -270,7 +270,7 @@ (default-currency (gnc-commodity-table-find-full (gnc-commodity-table-get-table (gnc-get-current-book)) - GNC_COMMODITY_NS_CURRENCY default-currency-name)) + (GNC-COMMODITY-NS-CURRENCY) default-currency-name)) (sorted-accounts-list '()) (markable-xtns '()) (sorted-qif-files-list (sort qif-files-list diff --git a/libgnucash/app-utils/options.scm b/libgnucash/app-utils/options.scm index 52ab8cf3d1..9e950dcfaa 100644 --- a/libgnucash/app-utils/options.scm +++ b/libgnucash/app-utils/options.scm @@ -435,7 +435,7 @@ the option '~a'.")) (if (string? currency) (gnc-commodity-table-lookup (gnc-commodity-table-get-table (gnc-get-current-book)) - GNC_COMMODITY_NS_CURRENCY currency) + (GNC-COMMODITY-NS-CURRENCY) currency) currency)) (let* ((value (currency->scm default-value)) @@ -561,7 +561,7 @@ the option '~a'.")) (define (commodity->scm commodity) (if (string? commodity) (list 'commodity-scm - GNC_COMMODITY_NS_CURRENCY + (GNC-COMMODITY-NS-CURRENCY) commodity) (list 'commodity-scm (gnc-commodity-get-namespace commodity) @@ -1560,7 +1560,7 @@ the option '~a'.")) (if (string? currency-string) (gnc-commodity-table-lookup (gnc-commodity-table-get-table (gnc-get-current-book)) - GNC_COMMODITY_NS_CURRENCY currency-string) + (GNC-COMMODITY-NS-CURRENCY) currency-string) #f)) (define (currency? val) diff --git a/po/POTFILES.in b/po/POTFILES.in index 2194e9e5e3..6a1a85fa78 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,7 +1,6 @@ # This is a list of files which contain translatable strings. # This file was autogenerated by cmake. bindings/guile/business-core.scm -bindings/guile/commodity-table.scm bindings/guile/core-utils.scm bindings/guile/engine.scm bindings/guile/glib-guile.c From 9ad24321b4708c94f363c93698097a31ee20e746 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 1 Mar 2022 15:10:02 -0800 Subject: [PATCH 4/5] Remove investment-type namespaces. Leave it to users to categorize their non-currency commodities. In the QIF importer default non-classifiable commodities to GNC_COMMODITY_NS_NONCURRENCY. --- bindings/python/tests/test_commodity.py | 4 +- .../qif-imp/qif-dialog-utils.scm | 37 +++++-------------- libgnucash/engine/gnc-commodity.c | 5 +-- libgnucash/engine/gnc-commodity.h | 10 +---- 4 files changed, 15 insertions(+), 41 deletions(-) diff --git a/bindings/python/tests/test_commodity.py b/bindings/python/tests/test_commodity.py index 36ffe6fc43..9577515118 100644 --- a/bindings/python/tests/test_commodity.py +++ b/bindings/python/tests/test_commodity.py @@ -21,12 +21,12 @@ class TestCommodityNamespace(CommoditySession): #print(self.table.__class__) namespace_names = self.table.get_namespaces() #print(namespace_names) - self.assertEqual(namespace_names, ['BOND', 'SHARE', 'FUND', 'OPTION', 'template', 'CURRENCY']) + self.assertEqual(namespace_names, ['All non-currency', 'template', 'CURRENCY']) def test_namespaces_list(self): namespaces = self.table.get_namespaces_list() namespace_names = [ns.get_name() for ns in namespaces] - self.assertEqual(namespace_names, ['BOND', 'SHARE', 'FUND', 'OPTION', 'template', 'CURRENCY']) + self.assertEqual(namespace_names, ['All non-currency', 'template', 'CURRENCY']) if __name__ == '__main__': main() diff --git a/gnucash/import-export/qif-imp/qif-dialog-utils.scm b/gnucash/import-export/qif-imp/qif-dialog-utils.scm index 6b0a036d24..e261476fcf 100644 --- a/gnucash/import-export/qif-imp/qif-dialog-utils.scm +++ b/gnucash/import-export/qif-imp/qif-dialog-utils.scm @@ -736,46 +736,29 @@ ;; compatible with the QIF type? (and (string=? s (caddr elt)) (not (and (string? qif-type) - (string=? (GNC-COMMODITY-NS-MUTUAL) + (string=? (GNC-COMMODITY-NS-NONCURRENCY) (cadr elt)) (or (string-ci=? qif-type "stock") (string-ci=? qif-type "etf")))))) prefs) #f))) - (cond - ;; If a preferences match was found, use its namespace. - (pref-match - (cadr pref-match)) - - ;; Guess SHARE for symbols of 1-4 characters. - ((<= l 4) - (GNC-COMMODITY-NS-SHARE)) - - ;; Otherwise it's probably a fund. - (else - (GNC-COMMODITY-NS-MUTUAL)))) + ;; If a preferences match was found, use its namespace. + (if pref-match (cadr pref-match)) ;; There's no symbol. Default to a fund. - (GNC-COMMODITY-NS-MUTUAL))) + (GNC-COMMODITY-NS-NONCURRENCY)))) ;; Was a QIF type given? (if (string? qif-type) ;; Yes. We might be able to definitely determine the namespace. - (cond - ;; Mutual fund - ((string-ci=? qif-type "mutual fund") - (GNC-COMMODITY-NS-MUTUAL)) - - ;; Index - ((string-ci=? qif-type "index") - ;; This QIF type must be wrong; indexes aren't tradable! - (GNC-COMMODITY-NS-MUTUAL)) - - (else - (guess-by-symbol qif-symbol))) + (if (or + (string-ci=? qif-type "mutual fund") + (string-ci=? qif-type "index")) + (GNC-COMMODITY-NS-NONCURRENCY) + (guess-by-symbol qif-symbol))) ;; No QIF type was given, so guess a ;; default namespace by symbol alone. - (guess-by-symbol qif-symbol))) + (guess-by-symbol qif-symbol)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/libgnucash/engine/gnc-commodity.c b/libgnucash/engine/gnc-commodity.c index 01b17f38e6..f36a7565b6 100644 --- a/libgnucash/engine/gnc-commodity.c +++ b/libgnucash/engine/gnc-commodity.c @@ -2510,10 +2510,7 @@ gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book) gnc_commodity* c; ENTER ("table=%p", table); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_BOND, book); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_SHARE, book); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book); - gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_OPTION, book); + gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NONCURRENCY, book); gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book); c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1); gnc_commodity_table_insert(table, c); diff --git a/libgnucash/engine/gnc-commodity.h b/libgnucash/engine/gnc-commodity.h index 6336fb8237..d7f475db2e 100644 --- a/libgnucash/engine/gnc-commodity.h +++ b/libgnucash/engine/gnc-commodity.h @@ -109,14 +109,8 @@ GType gnc_commodity_namespace_get_type(void); /* The ISO define is deprecated in favor of CURRENCY */ #define GNC_COMMODITY_NS_ISO "ISO4217" #define GNC_COMMODITY_NS_CURRENCY "CURRENCY" -#define GNC_COMMODITY_NS_BOND N_("BOND") -#define GNC_COMMODITY_NS_SHARE N_("SHARE") -#define GNC_COMMODITY_NS_MUTUAL N_("FUND") -#define GNC_COMMODITY_NS_OPTION N_("OPTION") -#define GNC_COMMODITY_NS_NONCURRENCY _("All non-currency") -/* Delay translation of this one, we use it in both translated and untranslated form - when presenting the currency related namespace to the user */ -#define GNC_COMMODITY_NS_ISO_GUI N_("Currencies") +#define GNC_COMMODITY_NS_NONCURRENCY NC_("Commodity Type", "All non-currency") +#define GNC_COMMODITY_NS_ISO_GUI NC_("Commodity Type", "Currencies") /** Max fraction is 10^9 because 10^10 would require changing it to an * int64_t. From 6f28d49f956d2eeee60ba9be6711a4128920e104 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 1 Mar 2022 15:30:30 -0800 Subject: [PATCH 5/5] Add tooltip to namespace combo in security editor. --- gnucash/gtkbuilder/dialog-commodity.glade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gnucash/gtkbuilder/dialog-commodity.glade b/gnucash/gtkbuilder/dialog-commodity.glade index f2fcd2928f..4667cd3b01 100644 --- a/gnucash/gtkbuilder/dialog-commodity.glade +++ b/gnucash/gtkbuilder/dialog-commodity.glade @@ -305,6 +305,8 @@ liststore2 True 0 + True + Select a category for the commodity or enter a new one. One might use investment categories like STOCKS and BONDS or exchange names like NASDAQ and LSE.