From a3ebd93acddd7f322464f9869a95646d8b4273e0 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Wed, 1 Jan 2020 08:18:14 +0700 Subject: [PATCH] [new-owner-report] fix LHS and RHS description INV/PMT txns both derive DESCRIPTION from invoice-posting / payment txn's ASSET/LIABILITY splits->memos This seems to produce consistent results in all circumstances. If a payment txn is modified so that it is funded from >1 asset/liability split, it will concat unique transfer splits memos. eg. payment transaction Asset:USDBank -$100 memo "100 USD" Asset:GBPBank -$100 memo "70 GBP" A/Payable +$200 memo "orig-memo" The Payment Description will be "100 USD, 70 GBP" --- .../business-reports/new-owner-report.scm | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm index fc337e8c04..8e0217571a 100644 --- a/gnucash/report/business-reports/new-owner-report.scm +++ b/gnucash/report/business-reports/new-owner-report.scm @@ -278,8 +278,20 @@ (compose (negate xaccAccountIsAPARType) xaccAccountGetType xaccSplitGetAccount) (xaccTransGetSplitList txn))) -(define (split->desc split) - (gnc:html-string-sanitize (xaccSplitGetMemo split))) +(define (txn->assetliab-splits txn) + (filter + (compose xaccAccountIsAssetLiabType xaccAccountGetType xaccSplitGetAccount) + (xaccTransGetSplitList txn))) + +(define (splits->desc splits) + (let lp ((splits splits) (result '())) + (if (null? splits) + (gnc:html-string-sanitize (string-join result ", ")) + (lp (cdr splits) + (let ((memo (xaccSplitGetMemo (car splits)))) + (if (or (string-null? memo) (member memo result)) + result + (cons memo result))))))) (define (make-aging-table splits to-date payable? date-type currency) (let ((table (gnc:make-html-table)) @@ -480,7 +492,7 @@ (qof-print-date (xaccTransGetDate pmt-txn)) (split->reference tfr-split) (split->type-str tfr-split) - (split->desc tfr-split) + (splits->desc (list tfr-split)) (gnc:make-html-text (gnc:html-markup-anchor (gnc:split-anchor-text (txn->transfer-split pmt-txn)) @@ -492,7 +504,7 @@ (qof-print-date (xaccTransGetDate posting-txn)) (split->reference posting-split) (split->type-str posting-split) - (split->desc posting-split) + (splits->desc (list posting-split)) (gnc:make-html-text (gnc:html-markup-anchor (gnc:split-anchor-text (txn->transfer-split posting-txn)) @@ -617,7 +629,8 @@ (gnc:make-gnc-monetary currency overpayment)) result))))) ((inv . rest) - (let ((tfr-split (txn->transfer-split (gncInvoiceGetPostedTxn inv)))) + (let* ((tfr-txn (gncInvoiceGetPostedTxn inv)) + (tfr-split (txn->transfer-split tfr-txn))) (lp rest (cons (make-link-data (qof-print-date (gncInvoiceGetDatePosted inv)) @@ -626,7 +639,7 @@ (gnc:invoice-anchor-text inv) (gncInvoiceGetID inv))) (gncInvoiceGetTypeString inv) - (xaccSplitGetMemo tfr-split) + (splits->desc (txn->assetliab-splits tfr-txn)) (gnc:make-html-text (gnc:html-markup-anchor (gnc:split-anchor-text tfr-split) @@ -718,7 +731,11 @@ table odd-row? used-columns date (invoice->due-date invoice) (split->reference split) (split->type-str split) - (split->desc split) currency (+ total value) + (splits->desc + (cond + ((txn-is-invoice? txn) (list split)) + ((txn-is-payment? txn) (txn->assetliab-splits txn)))) + currency (+ total value) (and (>= value 0) value) (and (< value 0) value) (invoice->sale invoice) (invoice->tax invoice) (txn->transfer-split txn)