Merge Frank Ellenberger's 'Bug684507' into maint.

This commit is contained in:
John Ralls
2022-03-08 12:39:47 -08:00
11 changed files with 25 additions and 111 deletions

View File

@@ -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
)

View File

@@ -1,44 +0,0 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; commodity-table.scm
;;; load and save commodity tables
;;;
;;; Bill Gribble <grib@billgribble.com> 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"))

View File

@@ -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)

View File

@@ -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, ['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, ['AMEX', 'NYSE', 'NASDAQ', 'EUREX', 'FUND', 'template', 'CURRENCY'])
self.assertEqual(namespace_names, ['All non-currency', 'template', 'CURRENCY'])
if __name__ == '__main__':
main()

View File

@@ -305,6 +305,8 @@
<property name="model">liststore2</property>
<property name="has-entry">True</property>
<property name="entry-text-column">0</property>
<property name="has-tooltip">True</property>
<property name="tooltip-markup" translatable="yes">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.</property>
<signal name="changed" handler="gnc_ui_commodity_changed_cb" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="combobox-entry5">

View File

@@ -736,58 +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 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)
;; 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))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@@ -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

View File

@@ -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)

View File

@@ -2510,11 +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_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_MUTUAL, 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);

View File

@@ -104,21 +104,13 @@ 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_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 "ISO4217"
#define GNC_COMMODITY_NS_CURRENCY "CURRENCY"
#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.

View File

@@ -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