Patch: Advanced Portfolio report and capital gain

Frank Pavageau frankpavageau at wanadoo.fr
Sat Sep 27 19:11:21 CDT 2003


Hi.

Here is a patch against CVS to correct a problem with the Advanced
Portfolio report regarding capital gain : when you sell stock and make
a profit, the documentation [1] says to enter a split transaction like
this

                      Nb of shares   Share price   Total Buy   Total Sell
Asset:Bank                                         NET_SALE
Asset:Stocks:SYMBOL   -NB_SHARES     SELL_PRICE                GROSS_SALE
Asset:Stocks:SYMBOL                                PROFIT
Income:Capital Gains                                           PROFIT
Expenses:Commisions                                COMMISSION

which has the stock asset twice, including one with 0 shares.

Without the patch, the Advanced Portfolio report adds all the values
regarding the stock asset to the Money Out or Money In sums, depending
on the direction of the transaction. This means that if you sell all
your stock shares, you always end up with a gain of 0 (GROSS_SALE -
PROFIT - GROSS_BUY).

The patch just checks that the number of shares is not 0 before adding
the value to the Money Out or Money In sum.

BTW, I've checked bugzilla, I don't think there's a bug filed for that
problem.

Frank

[1] http://www.gnucash.org/docs/v1.8/C/gnucash-guide/invest_sell1.html
-- 
Ankh-Morpork had dallied with many forms of government and had ended up
with that form of democracy known as One Man, One Vote. The Patrician was
the Man; he had the Vote.
	Terry Pratchett, _Mort_
-------------- next part --------------
--- src/report/standard-reports/advanced-portfolio.scm	21 May 2003 17:58:31 -0000	1.7
+++ src/report/standard-reports/advanced-portfolio.scm	27 Sep 2003 15:39:21 -0000
@@ -176,27 +176,29 @@
                          (lambda (s)
                            (cond
                              ((same-split? s split) 
-			      (unitscoll 'add commodity (gnc:split-get-amount s)) ;; Is the stock transaction?
 			      ;; (gnc:debug "amount" (gnc:numeric-to-double (gnc:split-get-amount s)) )
-			      (if (< 0 (gnc:numeric-to-double
-					(gnc:split-get-amount s)))
-				  (set! totalunits
-					(+ totalunits
-					   (gnc:numeric-to-double (gnc:split-get-amount s)))))
-			      (set! totalunityears
-				    (+ totalunityears 
-				       (* (gnc:numeric-to-double (gnc:split-get-amount s)) 
-					  (gnc:date-year-delta 
-					   (car (gnc:transaction-get-date-posted parent))
-					   (current-time))))) 
-			      (cond 
-			       ((gnc:numeric-negative-p (gnc:split-get-value s))
-				(moneyoutcoll
-				 'add currency
-				 (gnc:numeric-neg (gnc:split-get-value s))))
-			       (else (moneyincoll 
-				      'add currency
-				      (gnc:numeric-neg (gnc:split-get-value s))))))
+                              (cond
+                                ((not (gnc:numeric-zero-p (gnc:split-get-amount s)))
+                                 (unitscoll 'add commodity (gnc:split-get-amount s)) ;; Is the stock transaction?
+                                 (if (< 0 (gnc:numeric-to-double
+                                           (gnc:split-get-amount s)))
+                                     (set! totalunits
+                                           (+ totalunits
+                                              (gnc:numeric-to-double (gnc:split-get-amount s)))))
+                                 (set! totalunityears
+                                       (+ totalunityears 
+                                          (* (gnc:numeric-to-double (gnc:split-get-amount s)) 
+                                             (gnc:date-year-delta 
+                                              (car (gnc:transaction-get-date-posted parent))
+                                              (current-time))))) 
+                                 (cond 
+                                  ((gnc:numeric-negative-p (gnc:split-get-value s))
+                                   (moneyoutcoll
+                                    'add currency
+                                    (gnc:numeric-neg (gnc:split-get-value s))))
+                                  (else (moneyincoll 
+                                         'add currency
+                                         (gnc:numeric-neg (gnc:split-get-value s))))))))
 
                              ((split-account-type? s 'expense)
 			      (brokeragecoll 'add currency (gnc:split-get-value s)))


More information about the gnucash-patches mailing list