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

924fee2f3 redux, unfortunately gncInvoiceGetGUID isn't actually
available from scheme so we use the O(N^2) accumulator instead.
This commit is contained in:
Christopher Lam 2019-12-16 02:35:58 +08:00
parent 924fee2f3e
commit 5e7c295471

View File

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