Bug 797521 - Receivable Aging (beta): omit duplicate invoices

When processing payment->invoices, don't show duplicate invoices. This
is an unusual case documented in the bug.

Note: Instead of sort-and-delete-duplicates the invoices, we could
replace the invoice accumulator with the O(N^2) version:

(if (member invoice invoices) invoices (cons invoice invoices))
This commit is contained in:
Christopher Lam
2019-12-15 21:18:09 +08:00
parent 43fab24e2c
commit 924fee2f3e

View File

@@ -345,12 +345,16 @@
(gnc:make-gnc-monetary tfr-curr tfr-amt)))))
result)))))))))))
(define (invoice<? a b)
(string<? (gncInvoiceGetGUID a) (gncInvoiceGetGUID b)))
(define (payment-txn->overpayment-and-invoices txn)
(let lp ((splits (xaccTransGetAPARAcctSplitList txn #f))
(overpayment 0)
(invoices '()))
(match splits
(() (cons (AP-negate overpayment) invoices))
(() (cons (AP-negate overpayment)
(sort-and-delete-duplicates invoices invoice<? equal?)))
((split . rest)
(let ((invoice (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot split))))
(if (null? invoice)