From 09d3e953792d5272790710acf31f553800a6ad52 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 9 Feb 2020 09:54:25 +0800 Subject: [PATCH] [new-owner-report] if Payment amount is negative, label "Refund" and add logic to properly handle AP/AR negation rules --- .../business-reports/new-owner-report.scm | 16 ++++++++------- .../test/test-new-owner-report.scm | 20 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm index a3b0924d19..87e013ec1b 100644 --- a/gnucash/report/business-reports/new-owner-report.scm +++ b/gnucash/report/business-reports/new-owner-report.scm @@ -274,12 +274,14 @@ (let ((inv (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot split)))) (gnc:make-html-text (invoice->anchor inv))))))) -(define (split->type-str split) +(define (split->type-str split payable?) (let* ((txn (xaccSplitGetParent split)) + (amt (xaccSplitGetAmount split)) + (refund? (if payable? (< amt 0) (> amt 0))) (invoice (gncInvoiceGetInvoiceFromTxn txn))) (cond ((txn-is-invoice? txn) (gncInvoiceGetTypeString invoice)) - ((txn-is-payment? txn) (_ "Payment")) + ((txn-is-payment? txn) (if refund? (_ "Refund") (_ "Payment"))) ((txn-is-link? txn) (_ "Link")) (else (_ "Unknown"))))) @@ -573,7 +575,7 @@ (cons (make-link-data (qof-print-date (xaccTransGetDate lot-txn)) (split->reference lot-split) - (split->type-str lot-split) + (split->type-str lot-split payable?) (splits->desc non-document) (gnc:make-html-text (split->anchor lot-split #t)) (list->cell @@ -600,7 +602,7 @@ (cons (make-link-data (qof-print-date (xaccTransGetDate posting-txn)) (split->reference posting-split) - (split->type-str posting-split) + (split->type-str posting-split payable?) (splits->desc (list posting-split)) (gnc:make-html-text (split->anchor lot-split neg)) (gnc:make-html-text (split->anchor posting-split neg)) @@ -689,7 +691,7 @@ (make-link-data (qof-print-date (xaccTransGetDate (xaccSplitGetParent s))) (split->reference s) - (split->type-str s) + (split->type-str s payable?) (splits->desc (list s)) (gnc:make-html-text (split->anchor s #f)) (gnc:make-html-text (split->anchor s #f)) @@ -771,7 +773,7 @@ (add-row table odd-row? used-columns date (gncInvoiceGetDateDue invoice) (split->reference split) - (split->type-str split) + (split->type-str split payable?) (splits->desc (list split)) currency (+ total value) (and (>= orig-value 0) (amount->anchor split orig-value)) @@ -800,7 +802,7 @@ (add-row table odd-row? used-columns date #f (split->reference split) - (split->type-str split) + (split->type-str split payable?) (splits->desc (xaccTransGetAPARAcctSplitList txn #t)) currency (+ total value) (and (>= orig-value 0) (amount->anchor split orig-value)) diff --git a/gnucash/report/business-reports/test/test-new-owner-report.scm b/gnucash/report/business-reports/test/test-new-owner-report.scm index 30beb02ab8..f28676b65a 100644 --- a/gnucash/report/business-reports/test/test-new-owner-report.scm +++ b/gnucash/report/business-reports/test/test-new-owner-report.scm @@ -274,25 +274,25 @@ ((sxpath `(// (table 3) // (tr 11) // *text*)) sxml)) ;; tests for refund $120 to partially repay - (test-equal "line 12" - '("1980-06-28" "Payment" "-$148.25" "1980-06-30" "Payment" + (test-equal "line 12 refund $120 to partially repay" + '("1980-06-28" "Payment" "-$148.25" "1980-06-30" "Refund" "$160.00" "$50.00" "$50.00") ((sxpath `(// (table 3) // (tr 12) // *text*)) sxml)) - (test-equal "line 13" - '("1980-06-29" "Payment" "$120.00" "$120.00") + (test-equal "line 13 refund $120 to partially repay" + '("1980-06-29" "Refund" "$120.00" "$120.00") ((sxpath `(// (table 3) // (tr 13) // *text*)) sxml)) - (test-equal "line 14" + (test-equal "line 14 refund $120 to partially repay" '("Pre-Payment" "-$10.00") ((sxpath `(// (table 3) // (tr 14) // *text*)) sxml)) - (test-equal "line 15" - '("1980-06-29" "Payment" "-$28.25" "1980-06-28" "Payment" + (test-equal "line 15 refund $120 to partially repay" + '("1980-06-29" "Refund" "-$28.25" "1980-06-28" "Payment" "$120.00" "-$120.00" "-$120.00") ((sxpath `(// (table 3) // (tr 15) // *text*)) sxml)) - (test-equal "line 16" - '("1980-06-30" "Payment" "$21.75" "1980-06-28" "Payment" + (test-equal "line 16 refund $120 to partially repay" + '("1980-06-30" "Refund" "$21.75" "1980-06-28" "Payment" "$50.00" "-$40.00" "-$40.00") ((sxpath `(// (table 3) // (tr 16) // *text*)) sxml)) - (test-equal "line 17" + (test-equal "line 17 refund $120 to partially repay" '("Pre-Payment" "-$10.00") ((sxpath `(// (table 3) // (tr 17) // *text*)) sxml))