gnucash master: Multiple changes pushed
Mike Alexander
mta at code.gnucash.org
Wed Feb 19 17:19:39 EST 2014
Updated via https://github.com/Gnucash/gnucash/commit/b032a33b (commit)
via https://github.com/Gnucash/gnucash/commit/b2f2f252 (commit)
via https://github.com/Gnucash/gnucash/commit/3aacd3a1 (commit)
from https://github.com/Gnucash/gnucash/commit/00e32182 (commit)
commit b032a33b03162e73de19e740a9c5de7a9cbdc758
Author: Mike Alexander <mta at umich.edu>
Date: Wed Feb 19 01:22:48 2014 -0500
Count money used in a spin-off as money out of the stock account.
diff --git a/src/report/standard-reports/advanced-portfolio.scm b/src/report/standard-reports/advanced-portfolio.scm
index 4ff6ddf..7a97340 100644
--- a/src/report/standard-reports/advanced-portfolio.scm
+++ b/src/report/standard-reports/advanced-portfolio.scm
@@ -546,6 +546,7 @@
(shares-bought (gnc-numeric-zero))
(trans-sold (gnc-numeric-zero))
(trans-bought (gnc-numeric-zero))
+ (trans-spinoff (gnc-numeric-zero))
(trans-drp-residual (gnc-numeric-zero))
(trans-drp-account #f))
@@ -581,12 +582,17 @@
(set! trans-shares (gnc-numeric-add trans-shares (gnc-numeric-abs split-units)
units-denom GNC-RND-ROUND))
(if (gnc-numeric-zero-p split-units)
- (if (and (not (gnc-numeric-zero-p split-value))
- (not (spin-off? s current)))
- ;; Gain/loss split (amount zero and value non-zero). There will be
- ;; a corresponding income split that will incorrectly be added to trans-income
- ;; Fix that by subtracting it here
- (set! trans-income (gnc-numeric-sub trans-income split-value commod-currency-frac GNC-RND-ROUND)))
+ (if (spin-off? s current)
+ ;; Count money used in a spin off as money out
+ (if (gnc-numeric-negative-p split-value)
+ (set! trans-spinoff (gnc-numeric-sub trans-spinoff split-value
+ commod-currency-frac GNC-RND-ROUND)))
+ (if (not (gnc-numeric-zero-p split-value))
+ ;; Gain/loss split (amount zero, value non-zero, and not spinoff). There will be
+ ;; a corresponding income split that will incorrectly be added to trans-income
+ ;; Fix that by subtracting it here
+ (set! trans-income (gnc-numeric-sub trans-income split-value
+ commod-currency-frac GNC-RND-ROUND))))
;; Non-zero amount, add the value to the sale or purchase total.
(if (gnc-numeric-positive-p split-value)
(begin
@@ -622,6 +628,7 @@
" Shares bought: " (gnc-numeric-to-string shares-bought))
(gnc:debug " Value sold: " (gnc-numeric-to-string trans-sold)
" Value purchased: " (gnc-numeric-to-string trans-bought)
+ " Spinoff value " (gnc-numeric-to-string trans-spinoff)
" Trans DRP residual: " (gnc-numeric-to-string trans-drp-residual))
;; We need to calculate several things for this transaction:
@@ -632,7 +639,7 @@
;; 4. Money in to the account: this is the value of shares bought
;; except those purchased with reinvested income
;; 5. Money out: the money received by disposing of shares. This
- ;; is in trans-sold
+ ;; is in trans-sold plus trans-spinoff
;; 6. Brokerage fees: this is in trans-brokerage
;; Income
@@ -699,6 +706,7 @@
(moneyincoll 'add commod-currency trans-bought)
(moneyoutcoll 'add commod-currency trans-sold)
+ (moneyoutcoll 'add commod-currency trans-spinoff)
;; Look at splits again to handle changes in basis and realized gains
(for-each
commit b2f2f25202e6cda09b8e8edb1e99e405c141165e
Author: Mike Alexander <mta at umich.edu>
Date: Wed Feb 19 01:00:35 2014 -0500
Exclude income transfered to an asset account and back again from money in.
diff --git a/src/report/standard-reports/advanced-portfolio.scm b/src/report/standard-reports/advanced-portfolio.scm
index 02985ee..4ff6ddf 100644
--- a/src/report/standard-reports/advanced-portfolio.scm
+++ b/src/report/standard-reports/advanced-portfolio.scm
@@ -444,6 +444,10 @@
(basis-list '())
;; setup an alist for the splits we've already seen.
(seen_trans '())
+ ;; Account used to hold remainders from income reinvestments and
+ ;; running total of amount moved there
+ (drp-holding-account #f)
+ (drp-holding-amount (gnc-numeric-zero))
)
(define (my-exchange-fn fromunits tocurrency)
@@ -542,8 +546,8 @@
(shares-bought (gnc-numeric-zero))
(trans-sold (gnc-numeric-zero))
(trans-bought (gnc-numeric-zero))
- (trans-moneyin (gnc-numeric-zero))
- (trans-moneyout (gnc-numeric-zero)))
+ (trans-drp-residual (gnc-numeric-zero))
+ (trans-drp-account #f))
(gnc:debug "Transaction " (xaccTransGetDescription parent))
;; Add this transaction to the list of processed transactions so we don't
@@ -567,9 +571,7 @@
;; in the stock account in which case it's a stock donation to charity.
(if (not (same-account? current (xaccSplitGetAccount (xaccSplitGetOtherSplit s))))
(set! trans-brokerage
- (gnc-numeric-add trans-brokerage split-value commod-currency-frac GNC-RND-ROUND))
- (set! trans-moneyout
- (gnc-numeric-add trans-moneyout split-value commod-currency-frac GNC-RND-ROUND))))
+ (gnc-numeric-add trans-brokerage split-value commod-currency-frac GNC-RND-ROUND))))
((split-account-type? s ACCT-TYPE-INCOME)
(set! trans-income (gnc-numeric-sub trans-income split-value
@@ -595,16 +597,21 @@
(set! trans-sold
(gnc-numeric-sub trans-sold split-value commod-currency-frac GNC-RND-ROUND)))))
- ((or (split-account-type? s ACCT-TYPE-BANK)
- (split-account-type? s ACCT-TYPE-CASH)
- (split-account-type? s ACCT-TYPE-ASSET)
- (split-account-type? s ACCT-TYPE-STOCK)
- (split-account-type? s ACCT-TYPE-MUTUAL))
- (if (gnc-numeric-positive-p split-value)
- (set! trans-moneyout
- (gnc-numeric-add trans-moneyout split-value commod-currency-frac GNC-RND-ROUND))
- (set! trans-moneyin
- (gnc-numeric-sub trans-moneyin split-value commod-currency-frac GNC-RND-ROUND)))))
+ ((split-account-type? s ACCT-TYPE-ASSET)
+ ;; If all the asset accounts mentioned in the transaction are siblings of each other
+ ;; keep track of the money transfered to them if it is in the correct currency
+ (if (not trans-drp-account)
+ (begin
+ (set! trans-drp-account (xaccSplitGetAccount s))
+ (if (gnc-commodity-equiv commod-currency (xaccAccountGetCommodity trans-drp-account))
+ (set! trans-drp-residual split-value)
+ (set! trans-drp-account 'none)))
+ (if (not (eq? trans-drp-account 'none))
+ (if (or (parent-or-sibling? trans-drp-account (xaccSplitGetAccount s))
+ (parent-or-sibling? (xaccSplitGetAccount s) trans-drp-account))
+ (set! trans-drp-residual (gnc-numeric-add trans-drp-residual split-value
+ commod-currency-frac GNC-RND-ROUND))
+ (set! trans-drp-account 'none))))))
))
(xaccTransGetSplitList parent)
)
@@ -615,8 +622,7 @@
" Shares bought: " (gnc-numeric-to-string shares-bought))
(gnc:debug " Value sold: " (gnc-numeric-to-string trans-sold)
" Value purchased: " (gnc-numeric-to-string trans-bought)
- " Money in: " (gnc-numeric-to-string trans-moneyin)
- " Money out: " (gnc-numeric-to-string trans-moneyout))
+ " Trans DRP residual: " (gnc-numeric-to-string trans-drp-residual))
;; We need to calculate several things for this transaction:
;; 1. Total income: this is already in trans-income
@@ -643,25 +649,53 @@
(let* ((fee-frac (gnc-numeric-div shares-bought trans-shares GNC-DENOM-AUTO GNC-RND-ROUND))
(fees (gnc-numeric-mul trans-brokerage fee-frac commod-currency-frac GNC-RND-ROUND)))
(set! trans-bought (gnc-numeric-add trans-bought fees commod-currency-frac GNC-RND-ROUND))))
-
- ;; Calculate income that might have been reinvested. If there is no income
- ;; then none of it was reinvested
- (if (gnc-numeric-positive-p trans-income)
- (let* ((income-reinvested (gnc-numeric-sub trans-moneyin trans-moneyout
- commod-currency-frac GNC-RND-ROUND)))
- (if (gnc-numeric-negative-p income-reinvested)
- ;; More went out than in, some may not have been reinvested
- (set! income-reinvested (gnc-numeric-add trans-income income-reinvested
- commod-currency-frac GNC-RND-ROUND))
- ;; It was all potentially reinvested
- (set! income-reinvested trans-income))
- ;; Adjust trans-bought to not include reinvested income
- (set! trans-bought (gnc-numeric-sub trans-bought income-reinvested commod-currency-frac GNC-RND-ROUND))
- ;; You can't reinvest more than you purchases.
- (if (gnc-numeric-negative-p trans-bought)
- (set! trans-bought (gnc-numeric-zero)))
- (gnc:debug "Adjusted trans-bought " (gnc-numeric-to-string trans-bought)
- " income-reinvested " (gnc-numeric-to-string income-reinvested))))
+
+ ;; Update the running total of the money in the DRP residual account. This is relevant
+ ;; if this is a reinvestment transaction (both income and purchase) and there seems to
+ ;; asset accounts used to hold excess income.
+ (if (and trans-drp-account
+ (not (eq? trans-drp-account 'none))
+ (gnc-numeric-positive-p trans-income)
+ (gnc-numeric-positive-p trans-bought))
+ (if (not drp-holding-account)
+ (begin
+ (set! drp-holding-account trans-drp-account)
+ (set! drp-holding-amount trans-drp-residual))
+ (if (and (not (eq? drp-holding-account 'none))
+ (or (parent-or-sibling? trans-drp-account drp-holding-account)
+ (parent-or-sibling? drp-holding-account trans-drp-account)))
+ (set! drp-holding-amount (gnc-numeric-add drp-holding-amount trans-drp-residual
+ commod-currency-frac GNC-RND-ROUND))
+ (begin
+ ;; Wrong account (or no account), assume there isn't a DRP holding account
+ (set! drp-holding-account 'none)
+ (set trans-drp-residual (gnc-numeric-zero))
+ (set! drp-holding-amount (gnc-numeric-zero))))))
+
+ ;; Set trans-bought to the amount of money moved in to the account which was used to
+ ;; purchase more shares. If this is not a DRP transaction then all money used to purchase
+ ;; shares is money in.
+ (if (and (gnc-numeric-positive-p trans-income)
+ (gnc-numeric-positive-p trans-bought))
+ (begin
+ (set! trans-bought (gnc-numeric-sub trans-bought trans-income
+ commod-currency-frac GNC-RND-ROUND))
+ (set! trans-bought (gnc-numeric-add trans-bought trans-drp-residual
+ commod-currency-frac GNC-RND-ROUND))
+ (set! trans-bought (gnc-numeric-sub trans-bought drp-holding-amount
+ commod-currency-frac GNC-RND-ROUND))
+ ;; If the DRP holding account balance is negative, adjust it by the amount
+ ;; used in this transaction
+ (if (and (gnc-numeric-negative-p drp-holding-amount)
+ (gnc-numeric-positive-p trans-bought))
+ (set! drp-holding-amount (gnc-numeric-add drp-holding-amount trans-bought
+ commod-currency-frac GNC-RND-ROUND)))
+ ;; Money in is never more than amount spent to purchase shares
+ (if (gnc-numeric-negative-p trans-bought)
+ (set! trans-bought (gnc-numeric-zero)))))
+
+ (gnc:debug "Adjusted trans-bought " (gnc-numeric-to-string trans-bought)
+ " DRP holding account " (gnc-numeric-to-string drp-holding-amount))
(moneyincoll 'add commod-currency trans-bought)
(moneyoutcoll 'add commod-currency trans-sold)
commit 3aacd3a1f7dfc77637a7f62d90fa42db615bb7e6
Author: Mike Alexander <mta at umich.edu>
Date: Tue Feb 18 21:42:36 2014 -0500
Remove the "ignore parent or sibling" option entirely.
It is unlikely to come back and interferes with other changes I want to make.
diff --git a/src/report/standard-reports/advanced-portfolio.scm b/src/report/standard-reports/advanced-portfolio.scm
index c5d4897..02985ee 100644
--- a/src/report/standard-reports/advanced-portfolio.scm
+++ b/src/report/standard-reports/advanced-portfolio.scm
@@ -47,7 +47,6 @@
(define optname-basis-method (N_ "Basis calculation method"))
(define optname-prefer-pricelist (N_ "Set preference for price list data"))
(define optname-brokerage-fees (N_ "How to report brokerage fees"))
-(define optname-ignore-parent-and-sibling-transfers (N_ "Ignore money moved to parent and sibling accounts"))
;; To avoid overflows in our calculations, define a denominator for prices and unit values
(define price-denom 100000000)
@@ -118,12 +117,6 @@
(N_ "Ignore brokerage fees entirely."))
)))
-;; (add-option
-;; (gnc:make-simple-boolean-option
-;; gnc:pagename-general optname-ignore-parent-and-sibling-transfers "h"
-;; (N_ "Money moved from or to a parent or sibling account is not counted as money in or out")
-;; #f))
-
(gnc:register-option
options
(gnc:make-simple-boolean-option
@@ -409,7 +402,7 @@
currency price-fn exchange-fn price-source
include-empty show-symbol show-listing show-shares show-price
basis-method prefer-pricelist handle-brokerage-fees
- ignore-parent-and-siblings total-basis total-value
+ total-basis total-value
total-moneyin total-moneyout total-income total-gain
total-ugain total-brokerage)
@@ -608,14 +601,10 @@
(split-account-type? s ACCT-TYPE-STOCK)
(split-account-type? s ACCT-TYPE-MUTUAL))
(if (gnc-numeric-positive-p split-value)
- (if (or (not ignore-parent-and-siblings)
- (not (parent-or-sibling? (xaccSplitGetAccount s) current)))
- (set! trans-moneyout
- (gnc-numeric-add trans-moneyout split-value commod-currency-frac GNC-RND-ROUND)))
- (if (or (not ignore-parent-and-siblings)
- (not (parent-or-sibling? (xaccSplitGetAccount s) current)))
- (set! trans-moneyin
- (gnc-numeric-sub trans-moneyin split-value commod-currency-frac GNC-RND-ROUND))))))
+ (set! trans-moneyout
+ (gnc-numeric-add trans-moneyout split-value commod-currency-frac GNC-RND-ROUND))
+ (set! trans-moneyin
+ (gnc-numeric-sub trans-moneyin split-value commod-currency-frac GNC-RND-ROUND)))))
))
(xaccTransGetSplitList parent)
)
@@ -917,9 +906,6 @@
optname-prefer-pricelist))
(handle-brokerage-fees (get-option gnc:pagename-general
optname-brokerage-fees))
-;; (ignore-parent-and-siblings (get-option gnc:pagename-general
-;; optname-ignore-parent-and-sibling-transfers))
- (ignore-parent-and-siblings #f)
(total-basis (gnc:make-commodity-collector))
(total-value (gnc:make-commodity-collector))
@@ -1005,7 +991,7 @@
(table-add-stock-rows
table accounts to-date currency price-fn exchange-fn price-source
include-empty show-symbol show-listing show-shares show-price basis-method
- prefer-pricelist handle-brokerage-fees ignore-parent-and-siblings
+ prefer-pricelist handle-brokerage-fees
total-basis total-value total-moneyin total-moneyout
total-income total-gain total-ugain total-brokerage)
Summary of changes:
src/report/standard-reports/advanced-portfolio.scm | 146 ++++++++++++---------
1 file changed, 87 insertions(+), 59 deletions(-)
More information about the gnucash-changes
mailing list