From af73f13c5375742dee2b00b73abefb414f3f681e Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Tue, 1 May 2001 06:52:35 +0000 Subject: [PATCH] 2001-04-30 Dave Peticolas * src/scm/report/portfolio.scm: fix bug * src/scm/price-quotes.scm: handle 'nav' and 'price' types * src/gnome/dialog-price-editor.c: update for nav price type * src/quotes/finance-quote-helper.in: try 'nav' and 'price' if 'last' fails. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4094 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 11 +++++++ src/engine/gnc-pricedb.h | 2 +- src/gnome/dialog-price-editor.c | 6 +++- src/gnome/glade-gnc-dialogs.c | 3 ++ src/gnome/gnc-dialogs.glade | 1 + src/quotes/finance-quote-helper.in | 20 ++++++++---- src/scm/price-quotes.scm | 49 +++++++++++++++++++----------- src/scm/report/portfolio.scm | 22 +++++++------- 8 files changed, 78 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index f576b998db..317e99981f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2001-04-30 Dave Peticolas + + * src/scm/report/portfolio.scm: fix bug + + * src/scm/price-quotes.scm: handle 'nav' and 'price' types + + * src/gnome/dialog-price-editor.c: update for nav price type + + * src/quotes/finance-quote-helper.in: try 'nav' and 'price' if + 'last' fails. + 2001-05-01 Robert Graham Merkel * src/engine/Query.{ch}: added date-granularity sorting functionality diff --git a/src/engine/gnc-pricedb.h b/src/engine/gnc-pricedb.h index b852733589..4bc156af16 100644 --- a/src/engine/gnc-pricedb.h +++ b/src/engine/gnc-pricedb.h @@ -75,7 +75,7 @@ "Finance::Quote" and "old-file-import". type: the type of quote - types possible right now are bid, ask, - last, and unknown. + last, nav, and unknown. Implementation Details: diff --git a/src/gnome/dialog-price-editor.c b/src/gnome/dialog-price-editor.c index 3fc7bdfffe..4bbb8ebb11 100644 --- a/src/gnome/dialog-price-editor.c +++ b/src/gnome/dialog-price-editor.c @@ -258,7 +258,10 @@ type_string_to_index (const char *type) if (safe_strcmp (type, "last") == 0) return 2; - return 3; + if (safe_strcmp (type, "nav") == 0) + return 3; + + return 4; } static const char * @@ -269,6 +272,7 @@ type_index_to_string (int index) case 0: return "bid"; case 1: return "ask"; case 2: return "last"; + case 3: return "nav"; default: return "unknown"; } } diff --git a/src/gnome/glade-gnc-dialogs.c b/src/gnome/glade-gnc-dialogs.c index 6a85c55a05..487be5f253 100644 --- a/src/gnome/glade-gnc-dialogs.c +++ b/src/gnome/glade-gnc-dialogs.c @@ -7653,6 +7653,9 @@ create_Price_Dialog (void) glade_menuitem = gtk_menu_item_new_with_label (_("Last")); gtk_widget_show (glade_menuitem); gtk_menu_append (GTK_MENU (type_option_menu), glade_menuitem); + glade_menuitem = gtk_menu_item_new_with_label (_("Net Asset Value")); + gtk_widget_show (glade_menuitem); + gtk_menu_append (GTK_MENU (type_option_menu), glade_menuitem); glade_menuitem = gtk_menu_item_new_with_label (_("Unknown")); gtk_widget_show (glade_menuitem); gtk_menu_append (GTK_MENU (type_option_menu), glade_menuitem); diff --git a/src/gnome/gnc-dialogs.glade b/src/gnome/gnc-dialogs.glade index 0f3f62cb2b..920cb29e17 100644 --- a/src/gnome/gnc-dialogs.glade +++ b/src/gnome/gnc-dialogs.glade @@ -11374,6 +11374,7 @@ quit without making any changes. Bid Ask Last +Net Asset Value Unknown 0 diff --git a/src/quotes/finance-quote-helper.in b/src/quotes/finance-quote-helper.in index 9c8d88c074..05d54ddd78 100644 --- a/src/quotes/finance-quote-helper.in +++ b/src/quotes/finance-quote-helper.in @@ -50,12 +50,13 @@ use FileHandle; # this script knows about (and knows how to convert to scheme) are # returned, so the conversion function will have to be updated # whenever Finance::Quote changes. Currently you'll get symbol, -# gnc:time-no-zone, last, and currency. Fields with gnc: prefixes are -# non-Finance::Quote fields. gnc:time-no-zone is returned as a string -# of the form "YYYY-MM-DD HH:MM:SS", basically the unmolested (and -# underspecified) output of the quote source. It's up to you to know -# what it's proper timezone really is. i.e. if you know the time was -# in America/Chicago, you'll need to convert it to that. +# gnc:time-no-zone, and currency, and either last, nav, or price. +# Fields with gnc: prefixes are non-Finance::Quote fields. +# gnc:time-no-zone is returned as a string of the form "YYYY-MM-DD +# HH:MM:SS", basically the unmolested (and underspecified) output of +# the quote source. It's up to you to know what it's proper timezone +# really is. i.e. if you know the time was in America/Chicago, you'll +# need to convert it to that. # For example: @@ -224,6 +225,13 @@ sub schemify_quote { $quotedata .= " ($field . $data)"; $field = 'last'; + if (!($$quotehash{$itemname, $field})) { + $field = 'nav'; + } + if (!($$quotehash{$itemname, $field})) { + $field = 'price'; + } + $data = schemify_num($$quotehash{$itemname, $field}); $quotedata .= " ($field . $data)"; diff --git a/src/scm/price-quotes.scm b/src/scm/price-quotes.scm index 45695b7753..8ab1386045 100644 --- a/src/scm/price-quotes.scm +++ b/src/scm/price-quotes.scm @@ -388,8 +388,7 @@ (cons (car fq-call-data) (map (lambda (quote-item-info) - (string-upcase - (gnc:commodity-get-mnemonic (car quote-item-info)))) + (gnc:commodity-get-mnemonic (car quote-item-info))) (cdr fq-call-data)))) (define (fq-results->commod-tz-quote-triples fq-call-data fq-results) @@ -473,7 +472,8 @@ (time-zone (second c-tz-quote-triple)) (quote-data (third c-tz-quote-triple)) (gnc-time (assq-ref quote-data 'gnc:time-no-zone)) - (last-price (assq-ref quote-data 'last)) + (price #f) + (price-type #f) (currency-str (assq-ref quote-data 'currency)) (commodity-table (gnc:book-get-commodity-table book)) (currency @@ -483,10 +483,26 @@ "ISO4217" (string-upcase currency-str))))) + (or-map (lambda (price-sym) + (let ((p (assq-ref quote-data price-sym))) + (if p + (begin (set! price p) + (set! price-type price-sym) + #t) + #f))) + '(last nav price)) + + (set! price-type + (case price-type + ((last) "last") + ((nav) "nav") + ((price) "unknown") + (else #f))) + ;; FIXME: SIGFIGS is not what we want here... - (if last-price - (set! last-price - (gnc:double-to-gnc-numeric last-price + (if price + (set! price + (gnc:double-to-gnc-numeric price GNC-DENOM-AUTO (logior (GNC-DENOM-SIGFIGS 9) GNC-RND-ROUND)))) @@ -494,22 +510,21 @@ (if gnc-time (set! gnc-time (timestr->time-pair gnc-time time-zone))) - (if (not (and commodity currency gnc-time last-price)) + (if (not (and commodity currency gnc-time price price-type)) (string-append currency-str ":" (gnc:commodity-get-mnemonic commodity)) - (let ((price (gnc:price-create))) - (if (not price) + (let ((gnc-price (gnc:price-create))) + (if (not gnc-price) (string-append currency-str ":" (gnc:commodity-get-mnemonic commodity)) (begin - (gnc:price-set-commodity price commodity) - (gnc:price-set-currency price currency) - (gnc:price-set-time price gnc-time) - (gnc:price-set-source price "Finance::Quote") - (gnc:price-set-type price "last") - (gnc:price-set-value price last-price) - ;;(gnc:price-print-stdout price 2) - price)))))) + (gnc:price-set-commodity gnc-price commodity) + (gnc:price-set-currency gnc-price currency) + (gnc:price-set-time gnc-price gnc-time) + (gnc:price-set-source gnc-price "Finance::Quote") + (gnc:price-set-type gnc-price price-type) + (gnc:price-set-value gnc-price price) + gnc-price)))))) (define (book-add-prices! book prices) (let ((pricedb (gnc:book-get-pricedb book))) diff --git a/src/scm/report/portfolio.scm b/src/scm/report/portfolio.scm index bb774dc10a..12bb9741c3 100644 --- a/src/scm/report/portfolio.scm +++ b/src/scm/report/portfolio.scm @@ -54,10 +54,10 @@ (define (op-value section name) (gnc:option-value (get-op section name))) - (define (table-add-stock-rows table accounts to-date currency pricedb collector) - - (define (table-add-stock-rows-internal table accounts to-date odd-row? + (define (table-add-stock-rows table accounts to-date currency pricedb collector) + + (define (table-add-stock-rows-internal accounts odd-row?) (if (null? accounts) collector (let* ((row-style (if odd-row? "normal-row" "alternate-row")) (current (car accounts)) @@ -69,7 +69,7 @@ (unit-collector (gnc:account-get-comm-balance-at-date current to-date #f)) (units (cadr (unit-collector 'getpair commodity #f))) - + (price (gnc:pricedb-lookup-nearest-in-time pricedb commodity currency @@ -78,13 +78,13 @@ (price-value (if price (gnc:price-get-value price) (gnc:numeric-zero))) - + (value-num (gnc:numeric-mul units price-value (gnc:commodity-get-fraction currency) GNC-RND-ROUND)) - + (value (gnc:make-gnc-monetary currency value-num))) (collector 'add currency value-num) (gnc:html-table-append-row/markup! @@ -96,14 +96,14 @@ (gnc:make-html-table-header-cell/markup "number-cell" (gnc:numeric-to-double units)) (gnc:make-html-table-header-cell/markup - "number-cell" (gnc:make-gnc-monetary currency price-value)) + "number-cell" (gnc:make-gnc-monetary currency + price-value)) (gnc:make-html-table-header-cell/markup "number-cell" value))) (gnc:price-unref price) - (table-add-stock-rows-internal - table rest to-date currency (not odd-row?) pricedb collector)))) - (table-add-stock-rows-internal table accounts to-date - currency #t pricedb collector)) + (table-add-stock-rows-internal rest (not odd-row?))))) + + (table-add-stock-rows-internal accounts #t)) ;; The first thing we do is make local variables for all the specific ;; options in the set of options given to the function. This set will