gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Wed Aug 26 11:58:14 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/a50c188d (commit)
via https://github.com/Gnucash/gnucash/commit/3b312e75 (commit)
from https://github.com/Gnucash/gnucash/commit/c210ceb3 (commit)
commit a50c188dca02890c37af4c535b54fad5e2db13f2
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Aug 26 23:16:55 2020 +0800
Bug 797923 - Running employee report results in "Unbound variable: txn"
The bug was triggered by txn referring to the invalid split being
used *outside* the let environment. Use (car splits) instead for
logging. Also augment error handling by listing the invalid splits
before the aging-list.
diff --git a/gnucash/report/reports/standard/new-owner-report.scm b/gnucash/report/reports/standard/new-owner-report.scm
index 9771c638b..be6763670 100644
--- a/gnucash/report/reports/standard/new-owner-report.scm
+++ b/gnucash/report/reports/standard/new-owner-report.scm
@@ -475,7 +475,7 @@
((if negate? - +)
(AP-negate (xaccSplitGetAmount split))))))
- (define (print-totals total debit credit tax sale)
+ (define (print-totals total debit credit tax sale invalid-splits)
(define (total-cell cell)
(gnc:make-html-table-cell/markup "total-number-cell" cell))
(define (make-cell amt)
@@ -519,6 +519,20 @@
(addif (< 0 rhs-cols)
(gnc:make-html-table-cell/size 1 (+ mid-span rhs-cols) #f)))))
+ (unless (null? invalid-splits)
+ (gnc:html-table-append-row/markup!
+ table "grand-total"
+ (list (gnc:make-html-table-cell/size
+ 1 (+ grand-span mid-span rhs-cols)
+ (gnc:make-html-text
+ (G_ "Please note some transactions were not processed")
+ (gnc:html-markup-ol
+ (map
+ (match-lambda
+ ((split txt)
+ (gnc:html-markup-anchor (gnc:split-anchor-text split) txt)))
+ invalid-splits)))))))
+
;; print aging table
(gnc:html-table-append-row/markup!
table "grand-total"
@@ -712,6 +726,7 @@
(let lp ((printed? #f)
(odd-row? #t)
(splits splits)
+ (invalid-splits '())
(total 0)
(debit 0)
(credit 0)
@@ -725,7 +740,7 @@
;;start-date (and no other rows would be added either) so add it now
(when (and (not printed?) (bal-col used-columns) (not (zero? total)))
(add-balance-row odd-row? total))
- (print-totals total debit credit tax sale)
+ (print-totals total debit credit tax sale invalid-splits)
(gnc:html-table-set-style!
table "table"
'attribute (list "border" 1)
@@ -736,7 +751,7 @@
;; not an invoice/payment. skip transaction.
((not (or (txn-is-invoice? (xaccSplitGetParent (car splits)))
(txn-is-payment? (xaccSplitGetParent (car splits)))))
- (lp printed? odd-row? (cdr splits) total debit credit tax sale))
+ (lp printed? odd-row? (cdr splits) invalid-splits total debit credit tax sale))
;; invalid case: txn-type-invoice but no associated invoice, nor lot
((let* ((txn (xaccSplitGetParent (car splits)))
@@ -744,14 +759,17 @@
(and (txn-is-invoice? txn)
(or (null? invoice)
(null? (gncInvoiceGetPostedLot invoice)))))
- (gnc:warn "sanity check fail" txn)
- (lp printed? odd-row? (cdr splits) total debit credit tax sale))
+ (gnc:warn "sanity check fail " (gnc:strify (car splits)))
+ (lp printed? odd-row? (cdr splits)
+ (cons (list (car splits) "Transaction has type invoice but no owner or lot")
+ invalid-splits)
+ total debit credit tax sale))
;; txn-date < start-date. skip display, accumulate amounts
((< (xaccTransGetDate (xaccSplitGetParent (car splits))) start-date)
(let* ((txn (xaccSplitGetParent (car splits)))
(value (AP-negate (xaccTransGetAccountAmount txn acc))))
- (lp printed? odd-row? (cdr splits) (+ total value)
+ (lp printed? odd-row? (cdr splits) invalid-splits (+ total value)
debit credit tax sale)))
;; if balance row hasn't been rendered, consider
@@ -759,7 +777,7 @@
((not printed?)
(let ((print? (and (bal-col used-columns) (not (zero? total)))))
(if print? (add-balance-row odd-row? total))
- (lp #t (not print?) splits total debit credit tax sale)))
+ (lp #t (not print?) splits invalid-splits total debit credit tax sale)))
;; start printing txns.
((txn-is-invoice? (xaccSplitGetParent (car splits)))
@@ -789,7 +807,7 @@
((detailed) (make-invoice->payments-table invoice))
(else '(()))))
- (lp printed? (not odd-row?) (cdr splits) (+ total value)
+ (lp printed? (not odd-row?) (cdr splits) invalid-splits (+ total value)
(if (< 0 orig-value) (+ debit orig-value) debit)
(if (< 0 orig-value) credit (- credit orig-value))
(+ tax (CN-negate gncInvoiceGetTotalTax))
@@ -818,7 +836,7 @@
((detailed) (make-payment->payee-table txn))
(else '(()))))
- (lp printed? (not odd-row?) (cdr splits) (+ total value)
+ (lp printed? (not odd-row?) (cdr splits) invalid-splits (+ total value)
(if (< 0 orig-value) (+ debit orig-value) debit)
(if (< 0 orig-value) credit (- credit orig-value))
tax
commit 3b312e754898899a5bc97d1df87b88501c884097
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Aug 19 20:19:13 2020 +0800
[report-utilities] more dump data functions
Two API to dump splits in whole book:
* gnc:dump-book - splits grouped by account
* gnc:dump-all-transactions - splits grouped by transaction
* gnc:dump-split - dumps single split
Example output -- note (gnc:dump-book) dumps each account followed by
its splits, then account balance. (gnc:dump-all-transactions) dumps all
transactions in date order, each followed by its splits.
(gnc:dump-book)
Account 8e56ef54: <Expense> Comm<USD> Type<Expense>
n Split 5dd1c0a9: 05/11/19 Amt<$200.00> $200.00 Desc<vend1> Memo<AP>
n Split f9cb052f: 05/11/19 Amt<$20.00> $20.00 Desc<emp1> Memo<vouch1>
n Split daafc64b: 05/11/19 Amt<$69.00> $69.00 Desc<vend1> Memo<job-bill>
n Split 5e6af9fe: 14/11/19 Amt<$86.00> $86.00 Desc<emp1> Memo<emp-voucher>
n Split 6d636ea2: 14/11/19 Amt<$46.00> $46.00 Desc<vend1>
n Split e618644b: 14/12/19 Amt<-$100.00> -$100.00 Desc<Vend-USD>
n Split 8be19fbd: 25/12/19 Amt<-$46.00> -$46.00 Desc<Vend-USD> Memo<CN$100-desc>
n Split ee4fe250: 01/04/20 Amt<$32.00> $32.00 Desc<Cell phone>
n Split 2cb02dac: 09/05/20 Amt<-$307.00> -$307.00
Balance: $0.00 Cleared: $0.00 Reconciled: $0.00
Account 6f39f557: <Closing> Comm<USD> Type<Equity>
n Split 13916652: 09/05/20 Amt<$307.00> $307.00
Balance: $307.00 Cleared: $0.00 Reconciled: $0.00
Account fa6507e1: <Closing:GBP> Comm<GBP> Type<Equity>
n Split 34ce3c03: 09/05/20 Amt<-£1,293.00> -£1,293.00
Balance: -£1,293.00 Cleared: £0.00 Reconciled: £0.00
(gnc:dump-all-transactions)
Trans cfbbc2a4: 12/07/19 Curr GBP Desc<Customer-GBP>
n Split d12f74b2: 12/07/19 Acc<AR-GBP> Amt<£120.00> £120.00 Desc<Customer-GBP> Memo<due 91+>
n Split 3880e99c: 12/07/19 Acc<Standard Sales> Amt<-£20.00> -£20.00 Desc<Customer-GBP> Memo<due 91+>
n Split 6bd9c7e4: 12/07/19 Acc<Income-GBP> Amt<-£100.00> -£100.00 Desc<Customer-GBP> Memo<due 91+>
Trans 60344bab: 09/10/19 Curr GBP Desc<Customer-GBP>
n Split aaca8ee0: 09/10/19 Acc<AR-GBP> Amt<£225.00> £225.00 Desc<Customer-GBP> Memo<due 2-3 months ago>
n Split ee49bde8: 09/10/19 Acc<Standard Sales> Amt<-£20.00> -£20.00 Desc<Customer-GBP> Memo<due 2-3 months ago>
n Split e989e863: 09/10/19 Acc<Reduced Sales> Amt<-£5.00> -£5.00 Desc<Customer-GBP> Memo<due 2-3 months ago>
n Split 91d6cadd: 09/10/19 Acc<Income-GBP> Amt<-£200.00> -£200.00 Desc<Customer-GBP> Memo<due 2-3 months ago
diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm
index f5c2f256e..1a2336cf6 100644
--- a/gnucash/report/report-utilities.scm
+++ b/gnucash/report/report-utilities.scm
@@ -17,6 +17,7 @@
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu at gnu.org
+(use-modules (srfi srfi-26))
(use-modules (srfi srfi-13))
(use-modules (ice-9 format))
(use-modules (ice-9 match))
@@ -1089,36 +1090,63 @@
(newline)
(last args))))
+(define (maybe-str name str)
+ (match str
+ ((or "" #f) "")
+ (_ (format #f " ~a<~a>" name str))))
+
+(define-public (gnc:dump-split s show-acc?)
+ (define txn (xaccSplitGetParent s))
+ (format #t "~a Split ~a: ~a~a Amt<~a> ~a~a~a\n"
+ (xaccSplitGetReconcile s)
+ (string-take (gncSplitGetGUID s) 8)
+ (qof-print-date (xaccTransGetDate txn))
+ (maybe-str 'Acc (and show-acc? (xaccAccountGetName (xaccSplitGetAccount s))))
+ (gnc:monetary->string
+ (gnc:make-gnc-monetary
+ (xaccAccountGetCommodity (xaccSplitGetAccount s))
+ (xaccSplitGetAmount s)))
+ (gnc:monetary->string
+ (gnc:make-gnc-monetary
+ (xaccTransGetCurrency txn)
+ (xaccSplitGetValue s)))
+ (maybe-str 'Desc (xaccTransGetDescription txn))
+ (maybe-str 'Memo (xaccSplitGetMemo s))))
+
+(define-public (gnc:dump-all-transactions)
+ (define query (qof-query-create-for-splits))
+ (display "\n(gnc:dump-all-transactions)\n")
+ (qof-query-set-book query (gnc-get-current-book))
+ (qof-query-set-sort-order query (list SPLIT-TRANS TRANS-DATE-POSTED) '() '())
+ (qof-query-set-sort-increasing query #t #t #t)
+ (let lp ((splits (xaccQueryGetSplitsUniqueTrans query)))
+ (newline)
+ (match splits
+ (() (qof-query-destroy query))
+ ((split . rest)
+ (let ((trans (xaccSplitGetParent split)))
+ (format #t " Trans ~a: ~a Curr ~a ~a~a\n"
+ (string-take (gncTransGetGUID trans) 8)
+ (qof-print-date (xaccTransGetDate trans))
+ (gnc-commodity-get-mnemonic (xaccTransGetCurrency trans))
+ (maybe-str 'Desc (xaccTransGetDescription trans))
+ (maybe-str 'Notes (xaccTransGetNotes trans)))
+ (for-each (cut gnc:dump-split <> #t) (xaccTransGetSplitList trans))
+ (lp rest))))))
+
;; utility function for testing. dumps the whole book contents to
;; console.
(define (gnc:dump-book)
(display "\n(gnc:dump-book)\n")
(for-each
(lambda (acc)
- (format #t "\nAccount: <~a> Comm<~a> Type<~a>\n"
+ (format #t "\nAccount ~a: ~a Comm<~a> Type<~a>\n"
+ (string-take (gncAccountGetGUID acc) 8)
(gnc-account-get-full-name acc)
- (gnc-commodity-get-mnemonic
- (xaccAccountGetCommodity acc))
- (xaccAccountGetTypeStr
- (xaccAccountGetType acc)))
- (for-each
- (lambda (s)
- (let ((txn (xaccSplitGetParent s)))
- (format #t "~a Split: ~a Amt<~a> Val<~a> Desc<~a> Memo<~a>\n"
- (xaccSplitGetReconcile s)
- (qof-print-date (xaccTransGetDate txn))
- (gnc:monetary->string
- (gnc:make-gnc-monetary
- (xaccAccountGetCommodity acc)
- (xaccSplitGetAmount s)))
- (gnc:monetary->string
- (gnc:make-gnc-monetary
- (xaccTransGetCurrency txn)
- (xaccSplitGetValue s)))
- (xaccTransGetDescription txn)
- (xaccSplitGetMemo s))))
- (xaccAccountGetSplitList acc))
- (format #t "Balance: ~a Cleared: ~a Reconciled: ~a\n"
+ (gnc-commodity-get-mnemonic (xaccAccountGetCommodity acc))
+ (xaccAccountGetTypeStr (xaccAccountGetType acc)))
+ (for-each (cut gnc:dump-split <> #f) (xaccAccountGetSplitList acc))
+ (format #t " Balance: ~a Cleared: ~a Reconciled: ~a\n"
(gnc:monetary->string
(gnc:make-gnc-monetary
(xaccAccountGetCommodity acc)
Summary of changes:
gnucash/report/report-utilities.scm | 74 +++++++++++++++-------
.../report/reports/standard/new-owner-report.scm | 36 ++++++++---
2 files changed, 78 insertions(+), 32 deletions(-)
More information about the gnucash-changes
mailing list