From 34ed91eac969a3fb5cff8802a38293abeedc6ba6 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sun, 29 Jan 2023 22:50:44 +0100 Subject: [PATCH] =?UTF-8?q?Bug=C2=A0798734=20-=20Aging=20Reports=20don't?= =?UTF-8?q?=20handle=20mixed=20currency=20payments=20and=20invoices=20with?= =?UTF-8?q?out=20Trading=20Accounts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revisit the fix. It still made assumptions about the way payment transactions were created. It can now handle payment transaction either in the payment account currency or in the post account currency. --- gnucash/report/report-utilities.scm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm index 79d3131f89..eaf42e5eef 100644 --- a/gnucash/report/report-utilities.scm +++ b/gnucash/report/report-utilities.scm @@ -987,7 +987,7 @@ query instead.") (define (not-APAR? s) (not (xaccAccountIsAPARType (xaccAccountGetType (xaccSplitGetAccount s))))) ;; analyse a payment transaction and return a 3-element vector: -;; (vector invoices opposing-splits overpayment) +;; (vector invoices overpayment opposing-splits) ;; ;; invoices: a list of (cons invoice inv-APAR-split) ;; opposing-splits: a list of (list pmt-APAR-split partial-amount derived?) @@ -995,6 +995,8 @@ query instead.") ;; amount does not match the transaction amount ;; overpayment: a number indicating overpayment amount (define (gnc:payment-txn->payment-info txn) +(let* ((apar-split (xaccTransGetFirstAPARAcctSplit txn #t)) + (apar-acct (xaccSplitGetAccount apar-split))) (let lp ((splits (xaccTransGetSplitList txn)) (invoices '()) (overpayment 0) @@ -1002,7 +1004,8 @@ query instead.") (match splits (() (vector invoices opposing-splits overpayment)) (((? not-APAR? split) . rest) - (lp rest invoices (+ overpayment (xaccSplitGetValue split)) + (gnc:msg "next " (gnc:strify split) " overpayment " (+ overpayment (xaccSplitConvertAmount split apar-acct))) + (lp rest invoices (+ overpayment (xaccSplitConvertAmount split apar-acct)) opposing-splits)) ((split . rest) (let* ((lot (xaccSplitGetLot split)) @@ -1017,22 +1020,24 @@ query instead.") (((? split=?) . tail) (lp1 tail overpayment opposing-splits)) ((s . tail) (let* ((lot-bal (gnc-lot-get-balance lot)) - (lot-bal (if (sign-equal? lot-bal (xaccSplitGetValue s)) + (lot-bal (if (sign-equal? lot-bal (xaccSplitConvertAmount s apar-acct)) 0 lot-bal)) (derived? (not (zero? lot-bal))) (partial-amount (fold (lambda (a b) - (if (equal? s a) b (+ b (xaccSplitGetValue a)))) + (if (equal? s a) b (+ b (xaccSplitConvertAmount a apar-acct)))) (- lot-bal) lot-all-splits))) + (gnc:msg "next " (gnc:strify s) " overpayment " (+ overpayment partial-amount)) (lp1 tail (+ overpayment partial-amount) (cons (list s partial-amount derived?) opposing-splits))))))) (inv + (gnc:msg "next " (gnc:strify split) " overpayment " (+ overpayment (xaccSplitConvertAmount split apar-acct))) (lp rest (cons (cons inv split) invoices) - (+ overpayment (xaccSplitGetValue split)) - opposing-splits)))))))) + (+ overpayment (xaccSplitConvertAmount split apar-acct)) + opposing-splits))))))))) ;; create a stepped list, then add a date in the infinite future for ;; the "current" bucket @@ -1046,7 +1051,7 @@ query instead.") (define-public (gnc:owner-splits->aging-list splits num-buckets to-date date-type receivable?) (gnc:msg "processing " (qof-print-date to-date) " date-type " date-type - "receivable? " receivable?) + " receivable? " receivable?) (let ((bucket-dates (make-extended-interval-list to-date (- num-buckets 3))) (buckets (make-vector num-buckets 0))) (define (addbucket! idx amt) @@ -1064,10 +1069,11 @@ query instead.") (xaccSplitGetParent (car splits)))) (lot (gncInvoiceGetPostedLot invoice)) (lot-splits (gnc-lot-get-split-list lot)) + (apar-acct (gncInvoiceGetPostedAcc invoice)) (bal (fold (lambda (a b) (if (<= (xaccTransGetDate (xaccSplitGetParent a)) to-date) - (+ (xaccSplitGetValue a) b) + (+ (xaccSplitConvertAmount a apar-acct) b) b)) 0 lot-splits)) (bal (if receivable? bal (- bal)))