mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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
This commit is contained in:
parent
50ce14ad5c
commit
33a7d35f82
@ -1,3 +1,9 @@
|
||||
2001-06-01 Robert Graham Merkel <rgmerk@mira.net>
|
||||
|
||||
* src/scm/commodity-utilities.scm: exchange functions
|
||||
now return unchanged quantity if the two currencies are
|
||||
identical.
|
||||
|
||||
2001-06-01 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/doc/design/engine.texinfo: document commodity table API
|
||||
|
@ -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 <gnc-monetary> and
|
||||
;; the <gnc:commodity*> domestic-commodity, exchanges the amount into
|
||||
@ -597,8 +607,12 @@
|
||||
(define (gnc:make-exchange-function exchange-alist)
|
||||
(let ((exchangelist exchange-alist))
|
||||
(lambda (foreign domestic)
|
||||
(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)
|
||||
@ -609,7 +623,7 @@
|
||||
(cadr pair)
|
||||
(gnc:commodity-get-fraction domestic)
|
||||
GNC-RND-ROUND)))))
|
||||
#f))))
|
||||
#f)))))
|
||||
|
||||
;; Helper for the gnc:exchange-by-pricalist* below. Exchange the
|
||||
;; <gnc:monetary> 'foreign' into the <gnc:commodity*> '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 <gnc-monetary>.
|
||||
(define (gnc:exchange-by-pricealist-nearest
|
||||
pricealist foreign domestic date)
|
||||
(begin
|
||||
(gnc:debug "foreign " foreign)
|
||||
(gnc:debug "domestic " domestic)
|
||||
(gnc:debug "pricealist " pricealist)
|
||||
|
||||
(if (and (record? foreign) (gnc:gnc-monetary? foreign)
|
||||
date (not (null? pricealist)))
|
||||
date)
|
||||
(or (gnc:exchange-by-euro foreign domestic date)
|
||||
(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)))
|
||||
pricealist (gnc:gnc-monetary-commodity foreign) date))
|
||||
#f))
|
||||
#f)))
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user