gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Thu Sep 19 09:57:01 EDT 2019
Updated via https://github.com/Gnucash/gnucash/commit/656d2718 (commit)
via https://github.com/Gnucash/gnucash/commit/6b573de1 (commit)
via https://github.com/Gnucash/gnucash/commit/acf359a7 (commit)
via https://github.com/Gnucash/gnucash/commit/f88c54bb (commit)
from https://github.com/Gnucash/gnucash/commit/0c9c9c25 (commit)
commit 656d2718d8e570f6eb21e1ad29b0f7ea8cdd652f
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Sep 19 21:21:35 2019 +0800
[trial-balance] compact (collect-unrealized-gains)
use functional style
diff --git a/gnucash/report/standard-reports/trial-balance.scm b/gnucash/report/standard-reports/trial-balance.scm
index 9a9cc8974..fd726ee71 100644
--- a/gnucash/report/standard-reports/trial-balance.scm
+++ b/gnucash/report/standard-reports/trial-balance.scm
@@ -523,36 +523,21 @@
;;
;; This procedure returns a commodity collector.
(define (collect-unrealized-gains)
+ (define (acct->bal acct)
+ (gnc:account-get-comm-balance-at-date acct end-date #f))
(if (eq? price-source 'average-cost)
;; No need to calculate if doing valuation at cost.
(gnc:make-commodity-collector)
- (let ((book-balance (gnc:make-commodity-collector))
- (unrealized-gain-collector (gnc:make-commodity-collector))
- (cost-fn (gnc:case-exchange-fn
- 'average-cost report-commodity end-date)))
-
- ;; Calculate book balance.
- ;; assets - liabilities - equity; normally 0
- (for-each
- (lambda (acct)
- (book-balance
- 'merge
- (gnc:account-get-comm-balance-at-date acct end-date #f)
- #f))
- all-accounts)
-
- (let ((value (gnc:gnc-monetary-amount
- (gnc:sum-collector-commodity
- book-balance report-commodity exchange-fn)))
- (cost (gnc:gnc-monetary-amount
- (gnc:sum-collector-commodity
- book-balance report-commodity cost-fn))))
-
- ;; Get the unrealized gain or loss (value minus cost).
- (unrealized-gain-collector
- 'add report-commodity (- value cost))
- unrealized-gain-collector))))
-
+ (let* ((cost-fn (gnc:case-exchange-fn
+ 'average-cost report-commodity end-date))
+ (acct-balances (map acct->bal all-accounts))
+ (book-balance (apply coll-plus acct-balances))
+ (value (gnc:sum-collector-commodity
+ book-balance report-commodity exchange-fn))
+ (cost (gnc:sum-collector-commodity
+ book-balance report-commodity cost-fn)))
+ ;; Get the unrealized gain or loss (value minus cost).
+ (gnc:monetaries-add value (gnc:monetary-neg cost)))))
;; set default cell alignment
(gnc:html-table-set-style!
commit 6b573de128c6509bb447db0020849cbde764b457
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Sep 19 21:07:58 2019 +0800
[trial-balance] use coll-plus and coll-minus for functional style
diff --git a/gnucash/report/standard-reports/trial-balance.scm b/gnucash/report/standard-reports/trial-balance.scm
index 49a4ba485..9a9cc8974 100644
--- a/gnucash/report/standard-reports/trial-balance.scm
+++ b/gnucash/report/standard-reports/trial-balance.scm
@@ -692,18 +692,14 @@
(and ga-or-is? (coll-minus adjusting pos-adjusting)))
(pre-closing-bal (coll-minus curr-bal closing))
(pre-adjusting-bal (coll-minus pre-closing-bal adjusting))
- (atb (if is?
- (let* ((debit (gnc:make-commodity-collector))
- (credit (gnc:make-commodity-collector)))
- (debit 'merge pos-adjusting #f)
- (credit 'merge neg-adjusting #f)
- (if (double-col
- 'credit-q pre-adjusting-bal
- report-commodity exchange-fn show-fcur?)
- (credit 'merge pre-adjusting-bal #f)
- (debit 'merge pre-adjusting-bal #f))
- (list debit credit))
- pre-closing-bal)))
+ (atb (cond ((not is?) pre-closing-bal)
+ ((double-col 'credit-q pre-adjusting-bal
+ report-commodity exchange-fn show-fcur?)
+ (list (coll-plus pos-adjusting)
+ (coll-plus neg-adjusting pre-adjusting-bal)))
+ (else
+ (list (coll-plus pos-adjusting pre-adjusting-bal)
+ (coll-plus neg-adjusting))))))
;; curr-bal = account-bal with closing & adj entries
;; pre-closing-bal = account-bal with adj entries only
@@ -870,8 +866,8 @@
(tot-abs-amt-cell bs-credits))
'())))
(if (eq? report-variant 'work-sheet)
- (let* ((net-is (gnc:make-commodity-collector))
- (net-bs (gnc:make-commodity-collector))
+ (let* ((net-is (coll-minus is-debits is-credits))
+ (net-bs (coll-minus bs-debits bs-credits))
(tot-is (gnc:make-commodity-collector))
(tot-bs (gnc:make-commodity-collector))
(is-entry #f)
@@ -880,10 +876,6 @@
(bs-credit? #f)
(tbl-width (+ account-cols (* 2 bs-col) 2))
(this-row (gnc:html-table-num-rows build-table)))
- (net-is 'merge is-debits #f)
- (net-is 'minusmerge is-credits #f)
- (net-bs 'merge bs-debits #f)
- (net-bs 'minusmerge bs-credits #f)
(set! is-entry
(double-col 'entry net-is report-commodity exchange-fn show-fcur?))
(set! is-credit?
commit acf359a7973aa30686529ce46d18617ac51d77f8
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Sep 19 21:07:41 2019 +0800
[trial-balance] upgrade coll-plus and coll-minus to report-wide fns
diff --git a/gnucash/report/standard-reports/trial-balance.scm b/gnucash/report/standard-reports/trial-balance.scm
index 35aa425a1..49a4ba485 100644
--- a/gnucash/report/standard-reports/trial-balance.scm
+++ b/gnucash/report/standard-reports/trial-balance.scm
@@ -316,6 +316,19 @@
options))
+;; (coll-plus collectors ...) equiv to (+ collectors ...)
+(define (coll-plus . collectors)
+ (let ((res (gnc:make-commodity-collector)))
+ (for-each (lambda (coll) (res 'merge coll #f)) collectors)
+ res))
+
+;; (coll-minus collectors ...) equiv to (- collector0 collector1 ...)
+(define (coll-minus . collectors)
+ (let ((res (gnc:make-commodity-collector)))
+ (res 'merge (car collectors) #f)
+ (for-each (lambda (coll) (res 'minusmerge coll #f)) (cdr collectors))
+ res))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; trial-balance-renderer
;; set up the document and add the table
@@ -665,12 +678,6 @@
splits)
total))
- (define (coll-minus . collectors)
- (let ((res (gnc:make-commodity-collector)))
- (res 'merge (car collectors) #f)
- (for-each (lambda (mon) (res 'minusmerge mon #f)) (cdr collectors))
- res))
-
(while (< row rows)
(let* ((env (gnc:html-acct-table-get-row-env acct-table row))
(acct (get-val env 'account))
commit f88c54bb50a8527067225ea3586331238844ad79
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Sep 19 21:07:01 2019 +0800
[trial-balance] use gnc:commodity-collector-get-negated
diff --git a/gnucash/report/standard-reports/trial-balance.scm b/gnucash/report/standard-reports/trial-balance.scm
index 8b8aed9d5..35aa425a1 100644
--- a/gnucash/report/standard-reports/trial-balance.scm
+++ b/gnucash/report/standard-reports/trial-balance.scm
@@ -152,9 +152,7 @@
(amt (and sum (gnc:gnc-monetary-amount sum)))
(neg? (and amt (negative? amt)))
(bal (if neg?
- (let ((bal (gnc:make-commodity-collector)))
- (bal 'minusmerge signed-balance #f)
- bal)
+ (gnc:commodity-collector-get-negated signed-balance)
signed-balance))
(bal-sum (gnc:sum-collector-commodity
bal
Summary of changes:
gnucash/report/standard-reports/trial-balance.scm | 90 +++++++++--------------
1 file changed, 36 insertions(+), 54 deletions(-)
More information about the gnucash-changes
mailing list