gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Wed Dec 11 08:37:43 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/5f6b9946 (commit)
via https://github.com/Gnucash/gnucash/commit/0212537c (commit)
via https://github.com/Gnucash/gnucash/commit/3efb960d (commit)
from https://github.com/Gnucash/gnucash/commit/60765e38 (commit)
commit 5f6b9946d470636dba99ca6acd78c5ea34e9593e
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Dec 11 19:54:08 2019 +0800
[report-utilities] bugfix: fix overpayment detection
For 1 payment to >1 invoices, previous would miscalculate overpayment.
Old overpayment definition -- from the payment amount, successively
subtract the invoice totals. If remaining is >0, then this is
overpayment. But this fails whereby invoice was partially paid
elsewhere because the overpayment would miss them.
New overpayment definition -- the payment txn is analysed, and all
APAR-splits' lots are analysed. Any lot with no invoice is a
prepayment.
This is a simpler algorithm and does not require the creation and
searching of invoices-and-splits.
diff --git a/gnucash/report/report-system/report-utilities.scm b/gnucash/report/report-system/report-utilities.scm
index 459609e9b..652ab4543 100644
--- a/gnucash/report/report-system/report-utilities.scm
+++ b/gnucash/report/report-system/report-utilities.scm
@@ -1140,19 +1140,17 @@ flawed. see report-utilities.scm. please update reports.")
(buckets (make-vector num-buckets 0)))
(define (addbucket! idx amt)
(vector-set! buckets idx (+ amt (vector-ref buckets idx))))
- (let lp ((splits splits)
- (invoices-and-splits '()))
+ (let lp ((splits splits))
(cond
((null? splits)
(vector->list buckets))
;; next split is an invoice posting split. add its balance to
- ;; bucket, and add splits to invoices-and-splits for payments.
+ ;; bucket
((eqv? (xaccTransGetTxnType (xaccSplitGetParent (car splits)))
TXN-TYPE-INVOICE)
(let* ((invoice (gncInvoiceGetInvoiceFromTxn
(xaccSplitGetParent (car splits))))
- (inv-splits (gnc-lot-get-split-list (gncInvoiceGetPostedLot invoice)))
(lot (gncInvoiceGetPostedLot invoice))
(bal (gnc-lot-get-balance lot))
(bal (if receivable? bal (- bal)))
@@ -1165,33 +1163,31 @@ flawed. see report-utilities.scm. please update reports.")
(if (< date (car bucket-dates))
(addbucket! idx bal)
(loop (1+ idx) (cdr bucket-dates))))
- (lp (cdr splits)
- (cons (cons invoice inv-splits) invoices-and-splits))))
+ (lp (cdr splits))))
- ;; next split is a payment. find the associated invoices,
- ;; deduct their totals. the remaining is an overpayment.
+ ;; next split is a payment. analyse its sister APAR splits. any
+ ;; split whose lot-balance is negative is an overpayment.
((eqv? (xaccTransGetTxnType (xaccSplitGetParent (car splits)))
TXN-TYPE-PAYMENT)
(let* ((txn (xaccSplitGetParent (car splits)))
- (payment (apply + (map xaccSplitGetAmount
- (xaccTransGetAPARAcctSplitList txn #f))))
+ (splitlist (xaccTransGetAPARAcctSplitList txn #f))
+ (payment (apply + (map xaccSplitGetAmount splitlist)))
(overpayment
(fold
- (lambda (inv-and-splits payment-left)
- (if (member txn (map xaccSplitGetParent (cdr inv-and-splits)))
- (- payment-left (gncInvoiceGetTotal (car inv-and-splits)))
- payment-left))
- (if receivable? (- payment) payment) invoices-and-splits)))
+ (lambda (a b)
+ (if (null? (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot a)))
+ (- b (xaccSplitGetAmount a))
+ b))
+ 0 splitlist)))
(gnc:msg "next " (gnc:strify (car splits)) " payment " payment
" overpayment " overpayment)
- (when (positive? overpayment)
- (addbucket! (1- num-buckets) (- overpayment)))
- (lp (cdr splits) invoices-and-splits)))
+ (addbucket! (1- num-buckets) (- overpayment))
+ (lp (cdr splits))))
;; not invoice/prepayment. regular or payment split.
(else
(gnc:msg "next " (gnc:strify (car splits)) " skipped")
- (lp (cdr splits) invoices-and-splits))))))
+ (lp (cdr splits)))))))
;; ***************************************************************************
commit 0212537cca6bf941f09c61dd34c4072d5ed3caba
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Dec 11 19:54:00 2019 +0800
[new-owner-report] bugfix: fix overpayment detection
For 1 payment to >1 invoices, previous would miscalculate overpayment.
Old overpayment definition -- from the payment amount, successively
subtract the invoice totals. If remaining is >0, then this is
overpayment. But this fails whereby invoice was partially paid
elsewhere because the overpayment would miss them.
New overpayment definition -- the payment txn is analysed, and all
APAR-splits' lots are analysed. Any lot with no invoice is a
prepayment.
diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm
index 257e077ee..9366b889c 100644
--- a/gnucash/report/business-reports/new-owner-report.scm
+++ b/gnucash/report/business-reports/new-owner-report.scm
@@ -359,24 +359,29 @@
#f)))
payment-splits)))))
- (define (make-payment->invoices-table amount payment-splits currency)
+ (define (make-payment->invoices-table txn payment-splits currency)
(let lp ((payment-splits payment-splits)
- (amount (- amount))
(result '()))
(cond
((null? payment-splits)
- (reverse
- (if (positive? amount)
- (cons (list (gnc:make-html-table-cell/size 1 2 (_ "Prepayments"))
- (make-cell (gnc:make-gnc-monetary currency amount)))
- result)
- result)))
+ (let ((overpayment
+ (fold
+ (lambda (a b)
+ (if (null? (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot a)))
+ (- b (xaccSplitGetAmount a))
+ b))
+ 0 (xaccTransGetAPARAcctSplitList txn #f))))
+ (reverse
+ (if (positive? overpayment)
+ (cons (list (gnc:make-html-table-cell/size 1 2 (_ "Prepayments"))
+ (make-cell (gnc:make-gnc-monetary currency overpayment)))
+ result)
+ result))))
(else
(let* ((payment-split (car payment-splits))
(inv (car payment-split))
(inv-amount (gncInvoiceGetTotal inv)))
(lp (cdr payment-splits)
- (- amount inv-amount)
(cons (list
(qof-print-date (gncInvoiceGetDatePosted inv))
(gnc:make-html-text
@@ -510,7 +515,7 @@
((and payment-splits (eq? link-option 'simple))
(make-payment->invoices-list invoice payment-splits))
((and payment-splits (eq? link-option 'detailed))
- (make-payment->invoices-table value payment-splits currency))
+ (make-payment->invoices-table txn payment-splits currency))
;; some error occurred, show 1 line containing empty-list
(else '(()))))
commit 3efb960daf319f72b6108ca6632f2a42f19591ff
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Dec 10 18:23:30 2019 +0800
Bug 797521 - Receivable Aging (beta): prepayments logic doesn't work, appears to use incorrect absolute value logic
Overpayments create at least 2 APAR splits (1 for each invoice, and 1
for the overpayment), they were processed multiple times.
Modify query to return unique transactions, thereby ensuring a payment
gets processed once only.
diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index 5f0f8ba5a..a9bb0a045 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -235,7 +235,7 @@ exist but have no suitable transactions."))
(else
(setup-query query accounts report-date)
- (let* ((splits (qof-query-run query))
+ (let* ((splits (xaccQueryGetSplitsUniqueTrans query))
(accounts (sort-and-delete-duplicates (map xaccSplitGetAccount splits)
gnc:account-path-less-p equal?)))
(qof-query-destroy query)
Summary of changes:
gnucash/report/business-reports/new-aging.scm | 2 +-
.../report/business-reports/new-owner-report.scm | 25 +++++++++-------
gnucash/report/report-system/report-utilities.scm | 34 ++++++++++------------
3 files changed, 31 insertions(+), 30 deletions(-)
More information about the gnucash-changes
mailing list