gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Feb 8 10:46:43 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/19db1dae (commit)
	 via  https://github.com/Gnucash/gnucash/commit/7cbe367c (commit)
	 via  https://github.com/Gnucash/gnucash/commit/70d8acc7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/1ccea05b (commit)



commit 19db1daed68a1b9d2478066f10da70b7bdf0f69d
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Feb 8 18:20:23 2020 +0800

    Bug 797419 - equity-statement unrealized-gain calculator uses weighted-average
    
    for consistency. all other unrealized-gain calculators use average-cost.

diff --git a/gnucash/report/standard-reports/equity-statement.scm b/gnucash/report/standard-reports/equity-statement.scm
index 85ad4cc85..2639a8e2e 100644
--- a/gnucash/report/standard-reports/equity-statement.scm
+++ b/gnucash/report/standard-reports/equity-statement.scm
@@ -283,12 +283,12 @@
 	 )
 
     (define (unrealized-gains-at-date book-balance exchange-fn date)
-      (define weighted-fn
-	(gnc:case-exchange-fn 'weighted-average report-commodity date))
+      (define cost-fn
+	(gnc:case-exchange-fn 'average-cost report-commodity date))
       (gnc:monetaries-add
        (gnc:sum-collector-commodity book-balance report-commodity exchange-fn)
        (gnc:monetary-neg
-        (gnc:sum-collector-commodity book-balance report-commodity weighted-fn))))
+        (gnc:sum-collector-commodity book-balance report-commodity cost-fn))))
 
     (define (get-start-balance-fn account)
       (gnc:account-get-comm-balance-at-date account start-date #f))
diff --git a/gnucash/report/standard-reports/test/test-equity-statement.scm b/gnucash/report/standard-reports/test/test-equity-statement.scm
index 610a58c2f..f42c40dd4 100644
--- a/gnucash/report/standard-reports/test/test-equity-statement.scm
+++ b/gnucash/report/standard-reports/test/test-equity-statement.scm
@@ -108,13 +108,13 @@
         (sxml->table-row-col sxml 1 5 #f))
 
       (test-equal "unrealized"
-        '("Unrealized Losses" "$0.25")
+        '("Unrealized Losses" "$1.00")
         (sxml->table-row-col sxml 1 6 #f))
 
       (test-equal "inc/dec in capital"
-        '("Increase in capital" "$3,086.75")
+        '("Increase in capital" "$3,086.00")
         (sxml->table-row-col sxml 1 7 #f))
 
       (test-equal "capital end"
-        '("Capital, 01/01/05" "$3,115.75")
+        '("Capital, 01/01/05" "$3,115.00")
         (sxml->table-row-col sxml 1 8 #f)))))

commit 7cbe367cafe531f295b05bb4a1a07f3e3309ea35
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Feb 8 17:37:43 2020 +0800

    [new-owner-report] LHS invoice->payment LINK/PAYMENT merge
    
    * invoice->payment LINK or PAYMENT txns are handled identically. Merge.
    * reorder definitions in document handler.
    * rename variable 'invoice' to 'document'; invoice was clashing with
      outer variable. This fixes a credit-note negation bug.

diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm
index 49ce284bf..81720a62a 100644
--- a/gnucash/report/business-reports/new-owner-report.scm
+++ b/gnucash/report/business-reports/new-owner-report.scm
@@ -581,14 +581,6 @@
                                (gncTransGetGUID lot-txn))
                               result))))
 
-               ;; this payment peer is non-document, accumulate it.
-               ((not (memv (xaccAccountGetType
-                            (xaccSplitGetAccount (car lot-txn-splits)))
-                           (list ACCT-TYPE-RECEIVABLE ACCT-TYPE-PAYABLE)))
-                (lp1 (cdr lot-txn-splits)
-                     (cons (car lot-txn-splits) non-document)
-                     result))
-
                ;; this payment's peer split has same sign as the
                ;; payment split. ignore.
                ((sign-equal? (xaccSplitGetAmount (car lot-txn-splits))
@@ -599,11 +591,10 @@
                ;; reducing split.
                ((lot-split->posting-split (car lot-txn-splits)) =>
                 (lambda (posting-split)
-                  (let ((lot-txn-split (car lot-txn-splits))
-                        (invoice (gncInvoiceGetInvoiceFromTxn
-                                  (xaccSplitGetParent posting-split)))
-                        (neg (not (gncInvoiceGetIsCreditNote invoice)))
-                        (posting-txn (xaccSplitGetParent posting-split)))
+                  (let* ((lot-txn-split (car lot-txn-splits))
+                         (posting-txn (xaccSplitGetParent posting-split))
+                         (document (gncInvoiceGetInvoiceFromTxn posting-txn))
+                         (neg (gncInvoiceGetIsCreditNote document)))
                     (lp1 (cdr lot-txn-splits)
                          non-document
                          (cons (make-link-data
@@ -613,15 +604,13 @@
                                 (splits->desc (list posting-split))
                                 (gnc:make-html-text (split->anchor lot-split neg))
                                 (gnc:make-html-text (split->anchor posting-split neg))
-                                (gncInvoiceReturnGUID invoice))
+                                (gncInvoiceReturnGUID document))
                                result)))))
 
                ;; this payment's peer APAR split can't find
                ;; document. this likely is an old style link txn. RHS
                ;; show transaction only.
                (else
-                (gnc:warn (car lot-txn-splits) " in APAR but can't find "
-                          "owner; is likely an old-style link transaction.")
                 (lp1 (cdr lot-txn-splits)
                      (cons (car lot-txn-splits) non-document)
                      result))))))))))

commit 70d8acc7acf25f4df69afc379260ba9870d9633a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Feb 8 16:21:20 2020 +0800

    [test-new-owner-report] add tests for "$120 to partially repay"

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 bbb15543b..30beb02ab 100644
--- a/gnucash/report/business-reports/test/test-new-owner-report.scm
+++ b/gnucash/report/business-reports/test/test-new-owner-report.scm
@@ -160,7 +160,7 @@
         (set-option! options "General" "From"
                      (cons 'absolute (gnc-dmy2time64 1 1 1980)))
         (set-option! options "General" "To"
-                     (cons 'absolute (gnc-dmy2time64 1 7 1980)))
+                     (cons 'absolute (gnc-dmy2time64 1 7 1981)))
         (set-option! options "Display Columns" "Links" 'detailed)
         options))
 
@@ -181,7 +181,7 @@
     (let ((new-cn (add-invoice (gnc-dmy2time64 22 06 1980) -3 "CN")))
       (gncInvoiceSetIsCreditNote new-cn #t))
 
-    ;; inv $11.50, 2 payments
+    ;; inv $28, CN $27, Bank $1
     (let* ((inv (add-invoice (gnc-dmy2time64 24 06 1980) 28 "$28.00"))
            (CN (add-invoice (gnc-dmy2time64 25 06 1980) -27 "$27.00"))
            (inv-lot (gncInvoiceGetPostedLot inv))
@@ -198,6 +198,29 @@
        (list (create-split-for-lot AR -27 inv-lot)
              (create-split-for-lot AR 27 CN-lot))))
 
+    ;; refund $120 to partially repay
+    (let ((lot1 (gnc-lot-new (gnc-get-current-book)))
+          (lot2 (gnc-lot-new (gnc-get-current-book))))
+
+      (gncOwnerAttachToLot owner-1 lot1)
+      (gncOwnerAttachToLot owner-1 lot2)
+
+      (create-multisplit
+       28 06 1980 "payment" TXN-TYPE-PAYMENT
+       (list (create-split-for-lot AR  -120 lot1)
+             (create-split-for-lot AR   -40 lot2)
+             (create-split-for-lot Bank 160 #f)))
+
+      (create-multisplit
+       29 06 1980 "payment" TXN-TYPE-PAYMENT
+       (list (create-split-for-lot AR    120 lot1)
+             (create-split-for-lot Bank -120 #f)))
+
+      (create-multisplit
+       30 06 1980 "payment" TXN-TYPE-PAYMENT
+       (list (create-split-for-lot AR    50 lot2)
+             (create-split-for-lot Bank -50 #f))))
+
     (display "new-owner-report tests:\n")
     (test-begin "new-customer-report")
     (let* ((options (default-testing-options owner-1 (get-acct "AR-USD")))
@@ -206,8 +229,8 @@
         '("Customer History" "Linked Details" "1980-01-13" "1980-01-13"
           "Invoice" "$11.50" "$11.50" "1980-03-18" "Payment" "inv >90 payment"
           "$11.50" "pay only $1.50" "$1.50" "$1.50" "Pre-Payment" "Current"
-          "0-30 days" "31-60 days" "61-90 days" "91+ days" "Total" "$0.00"
-          "$0.00" "-$3.00" "$6.75" "$0.00" "$8.00" "$11.75")
+          "0-30 days" "31-60 days" "61-90 days" "91+ days" "Total" "$20.00"
+          "$0.00" "$0.00" "$0.00" "$0.00" "$11.75" "$31.75")
         ((sxpath `(// (table 3) // (tr 1) // *text*)) sxml))
       (test-equal "line 2"
         '("Date" "Due Date" "Reference" "Type" "Description" "Invoice"
@@ -248,5 +271,30 @@
       (test-equal "line 11"
         '("1980-06-26" "Payment" "$11.75" "1980-06-24" "Invoice" "$1.00"
           "$1.00" "$28.00")
-        ((sxpath `(// (table 3) // (tr 11) // *text*)) sxml)))
+        ((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"
+          "$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")
+        ((sxpath `(// (table 3) // (tr 13) // *text*)) sxml))
+      (test-equal "line 14"
+        '("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"
+          "$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"
+          "$50.00" "-$40.00" "-$40.00")
+        ((sxpath `(// (table 3) // (tr 16) // *text*)) sxml))
+      (test-equal "line 17"
+        '("Pre-Payment" "-$10.00")
+        ((sxpath `(// (table 3) // (tr 17) // *text*)) sxml))
+
+      )
     (test-end "new-customer-report")))



Summary of changes:
 .../report/business-reports/new-owner-report.scm   | 21 ++------
 .../test/test-new-owner-report.scm                 | 58 ++++++++++++++++++++--
 .../report/standard-reports/equity-statement.scm   |  6 +--
 .../test/test-equity-statement.scm                 |  6 +--
 4 files changed, 64 insertions(+), 27 deletions(-)



More information about the gnucash-changes mailing list