From 074729bf19fda23350256116bf6d27be229d74a3 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 8 Jul 2021 21:22:55 +0800 Subject: [PATCH] [report-utilities] simplify gnc:payment-txn->payment-info store lot splits in a separate identifier --- gnucash/report/report-utilities.scm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm index e38aa1c0fd..cbb87301b7 100644 --- a/gnucash/report/report-utilities.scm +++ b/gnucash/report/report-utilities.scm @@ -1006,28 +1006,26 @@ query instead.") (lp rest invoices (+ overpayment (xaccSplitGetAmount split)) opposing-splits)) ((split . rest) - (let ((lot (xaccSplitGetLot split))) - (define (equal-to-split? s) (equal? s split)) + (let* ((lot (xaccSplitGetLot split)) + (lot-all-splits (gnc-lot-get-split-list lot))) + (define split=? (cut equal? <> split)) (match (gncInvoiceGetInvoiceFromLot lot) - (() (let lp1 ((lot-splits (gnc-lot-get-split-list lot)) + (() (let lp1 ((lot-splits lot-all-splits) (overpayment overpayment) (opposing-splits opposing-splits)) (match lot-splits (() (lp rest invoices overpayment opposing-splits)) - (((? equal-to-split?) . tail) - (lp1 tail overpayment opposing-splits)) + (((? split=?) . tail) (lp1 tail overpayment opposing-splits)) ((s . tail) - (let* ((s-lot (xaccSplitGetLot s)) - (sum + (let* ((lot-bal (gnc-lot-get-balance lot)) + (lot-bal (if (sign-equal? lot-bal (xaccSplitGetAmount s)) + 0 lot-bal)) + (derived? (not (zero? lot-bal))) + (partial-amount (fold (lambda (a b) (if (equal? s a) b (+ b (xaccSplitGetAmount a)))) - 0 (gnc-lot-get-split-list s-lot))) - (lot-bal (gnc-lot-get-balance s-lot)) - (lot-bal (if (sign-equal? lot-bal (xaccSplitGetAmount s)) - 0 lot-bal)) - (partial-amount (- sum lot-bal)) - (derived? (not (zero? lot-bal)))) + (- lot-bal) lot-all-splits))) (lp1 tail (+ overpayment partial-amount) (cons (list s partial-amount derived?) opposing-splits)))))))