gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Thu May 16 07:26:40 EDT 2019
Updated via https://github.com/Gnucash/gnucash/commit/f779b817 (commit)
via https://github.com/Gnucash/gnucash/commit/0ecfc911 (commit)
from https://github.com/Gnucash/gnucash/commit/75a919b2 (commit)
commit f779b81719d86ba6082389dff26e96d3a6e03437
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu May 16 18:25:58 2019 +0800
[balsheet-pnl] unrealized-gain calculator bugfix
The unrealized-gain calculator was flawed.
The fixed function is copied from balance-sheet.scm and adapted to
balsheet-pnl.scm vars.
This fixed function matches unrealized-gains amounts from
balance-sheet.scm
diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 08cb0d2a6..44795c88d 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -937,13 +937,16 @@ also show overall period profit & loss."))
(else (list-ref report-dates col-idx))))
(asset-liability-balance
(list-ref asset-liability-balances col-idx))
- (latest (monetaries->exchanged
- asset-liability-balance
- common-currency price-source date))
- (avg-cost (monetaries->exchanged
- asset-liability-balance
- common-currency 'average-cost date)))
- (gnc:monetary+ latest (gnc:monetary-neg avg-cost))))))
+ (asset-liability-basis
+ (gnc:accounts-get-comm-total-assets
+ (append asset-accounts liability-accounts)
+ (lambda (acc)
+ (gnc:account-get-comm-value-at-date acc date #f))))
+ (unrealized (gnc:make-commodity-collector)))
+ (unrealized 'merge asset-liability-basis #f)
+ (unrealized 'minusmerge asset-liability-balance #f)
+ (monetaries->exchanged
+ unrealized common-currency price-source date)))))
(retained-earnings-fn
(lambda (col-idx)
(let* ((date (case price-source
commit 0ecfc911cae0d1987228c06d1bfaba23aca56e63
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue May 14 22:16:07 2019 +0800
[balsheet-pnl] chart: set report-currency to most used currency
This is a usability upgrade.
This balsheet-pnl report does *not* enforce a report currency; it can
print, process and multilevel-total monetary amounts in their original
currency.
But a linked chart needs one. By default it uses global
report_currency which may not match the book's most used currencies.
This commit will scan the accountlist, retrieve the most common
currency used, and set it as the report-currency for the linked
chart.
The book-main-currency function *may* be upgraded to
report-utilities.scm in the future.
Case example:
* set gnc_default_report_currency to USD
* load book.gnucash with majority accounts in EUR, some in GBP
* run balsheet-pnl.scm - shows EUR and GBP amounts and mixed totals.
* click link to barchart - would not succeed because all amounts
converted to USD0.00. this commit will ensure barchart's target
currency is set to EUR thereby showing useful chart.
diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 8d493a3cf..08cb0d2a6 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -830,6 +830,21 @@ also show overall period profit & loss."))
commodities)
(gnc:make-html-table-cell/markup "number-cell" cell))))
+ ;; scan accounts' commodities, filter currencies only, create
+ ;; hash-map counter, convert to alist, sort descending tally,
+ ;; return first pair's car. result=most used currency. the
+ ;; (cons default-currency 0) avoids crash in an empty-book by
+ ;; ensuring there is at least 1 currency.
+ (book-main-currency
+ (let ((h (make-hash-table)))
+ (for-each
+ (lambda (curr)
+ (hash-set! h curr (1+ (hash-ref h curr 0))))
+ (filter gnc-commodity-is-currency (map xaccAccountGetCommodity accounts)))
+ (caar (sort! (cons (cons (gnc-default-report-currency) 0)
+ (hash-map->list cons h))
+ (lambda (a b) (> (cdr a) (cdr b)))))))
+
;; decompose the account list
(show-foreign? (get-option pagename-commodities optname-show-foreign))
(show-rates? (get-option pagename-commodities optname-show-rates))
@@ -953,8 +968,7 @@ also show overall period profit & loss."))
(list (list "General" "Start Date" (cons 'absolute startdate))
(list "General" "End Date" (cons 'absolute enddate))
(list "General" "Report's currency"
- (or common-currency
- (gnc-default-report-currency)))
+ (or common-currency book-main-currency))
(list "General" "Step Size" incr)
(list "General" "Price Source"
(or price-source 'pricedb-nearest))
@@ -1120,8 +1134,7 @@ also show overall period profit & loss."))
(list "General" "End Date"
(cons 'absolute enddate))
(list "General" "Report's currency"
- (or common-currency
- (gnc-default-report-currency)))
+ (or common-currency book-main-currency))
(list "General" "Step Size" (or incr 'MonthDelta))
(list "General" "Price Source"
(or price-source 'pricedb-nearest))
Summary of changes:
gnucash/report/standard-reports/balsheet-pnl.scm | 38 +++++++++++++++++-------
1 file changed, 27 insertions(+), 11 deletions(-)
More information about the gnucash-changes
mailing list