From 33a7d35f82f53dccc0ca3e90b24afe09573f65f0 Mon Sep 17 00:00:00 2001 From: Robert Graham Merkel Date: Fri, 1 Jun 2001 07:46:31 +0000 Subject: [PATCH] Return 'foreign' quantities unchanged if 'foreign' and 'domestic' are equivalent currencies, rather than looking up in the pricedb. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4351 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 6 +++ src/scm/commodity-utilities.scm | 66 ++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9aa1b3db1d..8ed81853df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-06-01 Robert Graham Merkel + + * src/scm/commodity-utilities.scm: exchange functions + now return unchanged quantity if the two currencies are + identical. + 2001-06-01 Dave Peticolas * src/doc/design/engine.texinfo: document commodity table API diff --git a/src/scm/commodity-utilities.scm b/src/scm/commodity-utilities.scm index a968837a43..9773f227ff 100644 --- a/src/scm/commodity-utilities.scm +++ b/src/scm/commodity-utilities.scm @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; commodity-utilities.scm: Functions for handling different commodities. -;; Copyright 2001 Christian Stimming +;; Copyright 2001 Christian Stimming ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as @@ -590,6 +590,16 @@ (gnc:convert-to-euro (gnc:gnc-monetary-commodity foreign) (gnc:gnc-monetary-amount foreign)))))) + +;; A trivial exchange function - if the "foreign" monetary amount +;; and the domestic currency are the same, return the foreign +;; amount unchanged, otherwise return 0 + +(define (gnc:exchange-if-same foreign domestic) + (if (gnc:commodity-equiv? (gnc:gnc-monetary-commodity foreign) domestic) + foreign + #f)) + ;; This one returns the ready-to-use function for calculation of the ;; exchange rates. The returned function takes a and ;; the domestic-commodity, exchanges the amount into @@ -597,19 +607,23 @@ (define (gnc:make-exchange-function exchange-alist) (let ((exchangelist exchange-alist)) (lambda (foreign domestic) - (if foreign - (or (gnc:exchange-by-euro foreign domestic #f) - (gnc:make-gnc-monetary - domestic - (let ((pair (assoc (gnc:gnc-monetary-commodity foreign) - exchangelist))) - (if (not pair) - (gnc:numeric-zero) - (gnc:numeric-mul (gnc:gnc-monetary-amount foreign) - (cadr pair) - (gnc:commodity-get-fraction domestic) - GNC-RND-ROUND))))) - #f)))) + (begin + (gnc:debug "foreign: " foreign) + (gnc:debug "domestic: " domestic) + (if foreign + (or (gnc:exchange-by-euro foreign domestic #f) + (gnc:exchange-if-same foreign domestic) + (gnc:make-gnc-monetary + domestic + (let ((pair (assoc (gnc:gnc-monetary-commodity foreign) + exchangelist))) + (if (not pair) + (gnc:numeric-zero) + (gnc:numeric-mul (gnc:gnc-monetary-amount foreign) + (cadr pair) + (gnc:commodity-get-fraction domestic) + GNC-RND-ROUND))))) + #f))))) ;; Helper for the gnc:exchange-by-pricalist* below. Exchange the ;; 'foreign' into the 'domestic' by @@ -668,6 +682,7 @@ foreign domestic) (if (and (record? foreign) (gnc:gnc-monetary? foreign)) (or (gnc:exchange-by-euro foreign domestic #f) + (gnc:exchange-if-same foreign domestic) (gnc:exchange-by-pricedb-helper foreign domestic (gnc:pricedb-lookup-latest @@ -689,6 +704,7 @@ (if (and (record? foreign) (gnc:gnc-monetary? foreign) date) (or (gnc:exchange-by-euro foreign domestic date) + (gnc:exchange-if-same foreign domestic) (gnc:exchange-by-pricedb-helper foreign domestic (gnc:pricedb-lookup-nearest-in-time @@ -705,14 +721,22 @@ ;; function returns a . (define (gnc:exchange-by-pricealist-nearest pricealist foreign domestic date) - (if (and (record? foreign) (gnc:gnc-monetary? foreign) - date (not (null? pricealist))) + (begin + (gnc:debug "foreign " foreign) + (gnc:debug "domestic " domestic) + (gnc:debug "pricealist " pricealist) + + (if (and (record? foreign) (gnc:gnc-monetary? foreign) + date) (or (gnc:exchange-by-euro foreign domestic date) - (gnc:exchange-by-pricevalue-helper - foreign domestic - (gnc:pricealist-lookup-nearest-in-time - pricealist (gnc:gnc-monetary-commodity foreign) date))) - #f)) + (gnc:exchange-if-same foreign domestic) + (if (not (null? pricealist)) + (gnc:exchange-by-pricevalue-helper + foreign domestic + (gnc:pricealist-lookup-nearest-in-time + pricealist (gnc:gnc-monetary-commodity foreign) date)) + #f)) + #f)))