Am Samstag, 24. März 2007 03:11 schrieb Peter Selinger:
> Your patch posted on 2006-09-01 at
> http://bugzilla.gnome.org/show_bug.cgi?id=335101
> does indeed fix bug 335101, which is a duplicate of 410604.

Has been applied to SVN and is in 2.1.0. Thanks for the reminder.

> Your patch posted on 2006-06-07 at
> http://bugzilla.gnome.org/show_bug.cgi?id=131623
> indeed fixes bug 131623, which is a duplicate of 131626, 171801,
> 334775, 91661, 356077, 169946.

Unfortunately we forgot to apply this early enough. By now, the g-wrap -> swig 
conversion changed several variable names. I was able to adapt some paths but 
eventually I gave up when there was no  gnc:account-get-split-list in trunk 
any longer.  (Attached patch would be my current status against today's svn 
trunk.)

Anyone to finish this job, so that this nasty bug can eventually be closed as 
well? Thanks a lot.

Christian
Index: balance-sheet.scm
===================================================================
--- balance-sheet.scm	(Revision 15914)
+++ balance-sheet.scm	(Arbeitskopie)
@@ -405,6 +405,22 @@
        table
        (+ (* 2 tree-depth)
 	  (if (equal? tabbing 'canonically-tabbed) 1 0))))
+
+    ;; Get the value of all transactions (in transaction currency)
+    ;; in the given account before the given date
+    (define (get-account-value-at-date account to-date)
+      (let ((value (gnc:make-commodity-collector)))
+        (for-each
+         (lambda (split)
+           (let* ((parent (gnc-split-get-parent split))
+                  (currency (gnc-transaction-get-currency parent)))
+             (if (gnc:timepair-le (gnc-transaction-get-date-posted parent) to-date)
+                 (value 'add currency (gnc-split-get-value split)))))
+         (gnc-account-get-split-list account)
+         )
+        value
+        )
+      )
     
     ;;(gnc:warn "account names" liability-account-names)
     (gnc:html-document-set-title! 
@@ -425,6 +441,7 @@
 	
         ;; Get all the balances for each of the account types.
         (let* ((asset-balance #f)
+               (asset-basis #f)
                (neg-liability-balance #f) ;; credit balances are < 0
                (liability-balance #f)
                (neg-equity-balance #f)
@@ -434,7 +451,6 @@
                (unrealized-gain-collector #f)
                (total-equity-balance #f)
                (liability-plus-equity #f)
-	       (book-balance #f) ;; assets - liabilities - equity, norm 0
 	       
                ;; Create the account tables below where their
                ;; percentage time can be tracked.
@@ -450,6 +466,9 @@
 		(lambda (account)
 		  (gnc:account-get-comm-balance-at-date 
 		   account date-tp #f)))
+               (get-total-value-fn
+                (lambda (account)
+                  (get-account-value-at-date account date-tp)))
 	       )
 	  
 	  ;; If you ask me, any outstanding(TM) retained earnings and
@@ -461,6 +480,9 @@
 	  (set! asset-balance 
                 (gnc:accounts-get-comm-total-assets 
                  asset-accounts get-total-balance-fn))
+          (set! asset-basis
+                (gnc:accounts-get-comm-total-assets
+                 asset-accounts get-total-value-fn))
 	  (gnc:report-percent-done 6)
 	  ;; sum liabilities
 	  (set! neg-liability-balance
@@ -497,36 +519,10 @@
 	  ;; your selling it) and you have to reflect that on your
 	  ;; balance sheet.
 	  ;; 
-	  ;; I *think* a decrease in the value of a liability or
-	  ;; equity constitutes an unrealized loss.  I'm unsure about
-	  ;; that though....
-	  ;; 
-	  (set! book-balance (gnc:make-commodity-collector))
-	  (book-balance 'merge asset-balance #f)
-	  (book-balance 'merge neg-liability-balance #f)
-	  (book-balance 'merge neg-equity-balance #f)
-	  (book-balance 'merge neg-retained-earnings #f)
-          (set! unrealized-gain-collector (gnc:make-commodity-collector))
-          (let* ((weighted-fn
-                  (gnc:case-exchange-fn 'weighted-average
-                                        report-commodity date-tp))
-		 
-                 (value
-                  (gnc:gnc-monetary-amount
-                   (gnc:sum-collector-commodity book-balance
-                                                report-commodity
-                                                exchange-fn)))
-		 
-                 (cost
-                  (gnc:gnc-monetary-amount
-                   (gnc:sum-collector-commodity book-balance
-                                                report-commodity
-                                                weighted-fn)))
-		 
-                 (unrealized-gain (gnc-numeric-sub-fixed value cost)))
-	    
-            (unrealized-gain-collector 'add report-commodity unrealized-gain)
-	    )
+	  (set! unrealized-gain-collector (gnc:make-commodity-collector))
+	  (unrealized-gain-collector 'merge asset-balance #f)
+	  (unrealized-gain-collector 'minusmerge asset-basis #f)
+ 
 	  ;; calculate equity and liability+equity totals
 	  (set! total-equity-balance (gnc:make-commodity-collector))
 	  (total-equity-balance 'merge
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to