Patch: Advanced Portfolio report and capital gain

Linas Vepstas linas at linas.org
Sat Oct 11 00:46:21 CDT 2003


was this patch applied? I didn't see it go by

On Sat, Sep 27, 2003 at 06:11:21PM +0200, Frank Pavageau was heard to remark:
> 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_

> --- 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)))

> _______________________________________________
> gnucash-patches mailing list
> gnucash-patches at lists.gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-patches


-- 
pub  1024D/01045933 2001-02-01 Linas Vepstas (Labas!) <linas at linas.org>
PGP Key fingerprint = 8305 2521 6000 0B5E 8984  3F54 64A9 9A82 0104 5933


More information about the gnucash-patches mailing list