mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[commodity-utils] simplify gnc:make-exchange-function
Remove assigning exchangelist to exchange-alist. Removes need to test foreign-amount against 0 - multiplication will result in 0 anyway. The only functional change is the condition whereby foreign's commodity is not present in exchangelist; previously it would return (gnc:make-gnc-monetary domestic 0); now it returns #f. This function *is* allowed to return #f for invalid or missing prices; see the (and foreign ...) conditional.
This commit is contained in:
parent
e111c5bb07
commit
375013f9ea
@ -690,23 +690,18 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
|
||||
;; the <gnc:commodity*> domestic-commodity, exchanges the amount into
|
||||
;; the domestic currency and returns a <gnc-monetary>.
|
||||
(define (gnc:make-exchange-function exchange-alist)
|
||||
(let ((exchangelist exchange-alist))
|
||||
(lambda (foreign domestic)
|
||||
(gnc:debug "foreign: " (gnc:monetary->string foreign))
|
||||
(gnc:debug "domestic: " (gnc-commodity-get-printname domestic))
|
||||
(and foreign
|
||||
(or (gnc:exchange-by-euro foreign domestic #f)
|
||||
(gnc:exchange-if-same foreign domestic)
|
||||
(let* ((foreign-comm (gnc:gnc-monetary-commodity foreign))
|
||||
(pair (assoc foreign-comm exchange-alist)))
|
||||
(and pair
|
||||
(gnc:make-gnc-monetary
|
||||
domestic
|
||||
(let ((pair (assoc (gnc:gnc-monetary-commodity foreign)
|
||||
exchangelist))
|
||||
(foreign-amount (gnc:gnc-monetary-amount foreign)))
|
||||
(if (or (not pair)
|
||||
(zero? foreign-amount))
|
||||
0
|
||||
(* foreign-amount
|
||||
(cadr pair))))))))))
|
||||
(* (gnc:gnc-monetary-amount foreign) (cadr pair)))))))))
|
||||
|
||||
;; Helper for the gnc:exchange-by-pricalist* below. Exchange the
|
||||
;; <gnc:monetary> 'foreign' into the <gnc:commodity*> 'domestic' by
|
||||
|
Loading…
Reference in New Issue
Block a user