From 595d08d0b4fc83c6b672ec40c85c0039f2708efd Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Mon, 7 Jan 2002 00:52:40 +0000 Subject: [PATCH] 2002-01-07 Christian Stimming * src/report/report-system/commodity-utilities.scm: Tweaked the exchange rate calculation so that it will work in even more complicated cases, involving different Euroland and other currencies. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6524 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 + .../report-system/commodity-utilities.scm | 138 +++++++++++------- .../standard-reports/account-summary.scm | 2 +- 3 files changed, 95 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index f50f1f137b..2ccefd955e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-01-07 Christian Stimming + + * src/report/report-system/commodity-utilities.scm: Tweaked the + exchange rate calculation so that it will work in even more + complicated cases, involving different Euroland and other + currencies. + 2002-01-06 Christian Stimming * src/report/report-system/html-utilities.scm, diff --git a/src/report/report-system/commodity-utilities.scm b/src/report/report-system/commodity-utilities.scm index 0a26d81220..a63eaab5b9 100644 --- a/src/report/report-system/commodity-utilities.scm +++ b/src/report/report-system/commodity-utilities.scm @@ -397,57 +397,93 @@ (if (not (gnc:commodity-equiv? (car otherlist) report-commodity)) (for-each (lambda (pair) - ;; pair-{a,b}: Try to find either the currency of - ;; otherlist or of pair in reportlist. - (let ((pair-a (assoc (car otherlist) reportlist)) - (pair-b (assoc (car pair) reportlist)) - (rate (gnc:numeric-zero))) - (if (and (not pair-a) (not pair-b)) - ;; If neither the currency of otherlist nor of - ;; pair was found in reportlist then we can't - ;; resolve the exchange rate to this currency. - (warn "gnc:resolve-unknown-comm:" - "can't calculate rate for " - (gnc:commodity-value->string - (list (car pair) ((caadr pair) 'total #f))) - " = " - (gnc:commodity-value->string - (list (car otherlist) ((cdadr pair) 'total #f))) - " to " - (gnc:commodity-value->string - (list report-commodity (gnc:numeric-zero)))) - (if (and pair-a pair-b) - ;; If both currencies are found then something - ;; went wrong inside - ;; gnc:get-exchange-totals. FIXME: Find a - ;; better thing to do in this case. - (warn "gnc:resolve-unknown-comm:" - "Oops - exchange rate ambiguity error: " - (gnc:commodity-value->string - (list (car pair) ((caadr pair) 'total #f))) - " = " - (gnc:commodity-value->string - (list (car otherlist) - ((cdadr pair) 'total #f)))) - (let - ;; Usual case: one of pair-{a,b} was found - ;; in reportlist, i.e. this transaction - ;; can be resolved to report-commodity. - ((newrate - (if (not pair-a) - (list (car otherlist) - (make-newrate (cdadr pair) - (caadr pair) pair-b)) - (list (car pair) - (make-newrate (caadr pair) - (cdadr pair) pair-a))))) - ;; (warn "created new rate: " - ;; (gnc:commodity-value->string (list (car - ;; newrate) ((caadr newrate) 'total #f))) " - ;; = " (gnc:commodity-value->string (list - ;; report-commodity ((cdadr newrate) 'total - ;; #f)))) - (set! reportlist (cons newrate reportlist))))))) + ;; Check whether by any accident the report-commodity + ;; appears here. + (if + (not (gnc:commodity-equiv? (car pair) report-commodity)) + ;; pair-{a,b}: Try to find either the currency of + ;; otherlist or of pair in reportlist. + (let ((pair-a + (or + ;; Find the otherlist's currency in reportlist + (assoc (car otherlist) reportlist) + ;; Or try whether that's an Euro currency. + (let + ((euro-monetary + (gnc:exchange-by-euro (gnc:make-gnc-monetary + (car otherlist) + ((cdadr pair) 'total #f)) + report-commodity #f))) + ;; If this is an Euro currency, create the + ;; pair of appropriately exchanged amounts. + (if euro-monetary + (let ((a (gnc:make-numeric-collector))) + (a 'add + (gnc:gnc-monetary-amount euro-monetary)) + (list report-commodity + (cons (cdadr pair) a))) + #f)))) + ;; Find the pair's currency in reportlist. FIXME: + ;; Also try the Euro here. + (pair-b (assoc (car pair) reportlist)) + (rate (gnc:numeric-zero))) + (if (and (not pair-a) (not pair-b)) + ;; If neither the currency of otherlist nor of + ;; pair was found in reportlist then we can't + ;; resolve the exchange rate to this currency. + (warn "gnc:resolve-unknown-comm:" + "can't calculate rate for " + (gnc:commodity-value->string + (list (car pair) ((caadr pair) 'total #f))) + " = " + (gnc:commodity-value->string + (list (car otherlist) ((cdadr pair) 'total #f))) + " to " + (gnc:commodity-value->string + (list report-commodity (gnc:numeric-zero)))) + (if (and pair-a pair-b) + ;; If both currencies are found then something + ;; went wrong inside + ;; gnc:get-exchange-totals. FIXME: Find a + ;; better thing to do in this case. + (warn "gnc:resolve-unknown-comm:" + "Oops - exchange rate ambiguity error: " + (gnc:commodity-value->string + (list (car pair) ((caadr pair) 'total #f))) + " = " + (gnc:commodity-value->string + (list (car otherlist) + ((cdadr pair) 'total #f)))) + (let + ;; Usual case: one of pair-{a,b} was found + ;; in reportlist, i.e. this transaction + ;; can be resolved to report-commodity. + ((newrate + (if (not pair-a) + (list (car otherlist) + (make-newrate (cdadr pair) + (caadr pair) pair-b)) + (list (car pair) + (make-newrate (caadr pair) + (cdadr pair) pair-a))))) + ;; (warn "created new rate: " + ;; (gnc:commodity-value->string (list (car + ;; newrate) ((caadr newrate) 'total #f))) " + ;; = " (gnc:commodity-value->string (list + ;; report-commodity ((cdadr newrate) 'total + ;; #f)))) + (set! reportlist (cons newrate reportlist)))))) + ;; Huh, the report-currency showed up on the wrong side + ;; -- we will just add it to the reportlist on the + ;; right side. + (let ((newrate (list (car otherlist) + (cons (cdadr pair) (caadr pair))))) + ;; (warn "created new rate: " + ;; (gnc:commodity-value->string (list (car newrate) + ;; ((caadr newrate) 'total #f))) " = " + ;; (gnc:commodity-value->string (list + ;; report-commodity ((cdadr newrate) 'total #f)))) + (set! reportlist (cons newrate reportlist))))) (cadr otherlist)))) sumlist) diff --git a/src/report/standard-reports/account-summary.scm b/src/report/standard-reports/account-summary.scm index 735594c6b2..2b53057558 100644 --- a/src/report/standard-reports/account-summary.scm +++ b/src/report/standard-reports/account-summary.scm @@ -81,7 +81,7 @@ (gnc:options-add-account-selection! options gnc:pagename-accounts optname-display-depth optname-show-subaccounts - optname-accounts "a" 3 + optname-accounts "a" 2 (lambda () ;; FIXME : gnc:get-current-accounts disappeared (let ((current-accounts '()))