Skip to content

Commit

Permalink
Merge Paolo Maero's 'money-out' into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Jun 12, 2023
2 parents 0d1ba1e + df6c775 commit 2e20b37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 16 additions & 3 deletions gnucash/report/reports/standard/advanced-portfolio.scm
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ by preventing negative stock balances.<br/>")
(trans-brokerage (gnc-numeric-zero))
(trans-shares (gnc-numeric-zero))
(shares-bought (gnc-numeric-zero))
(shares-sold (gnc-numeric-zero))
(trans-sold (gnc-numeric-zero))
(trans-bought (gnc-numeric-zero))
(trans-spinoff (gnc-numeric-zero))
Expand Down Expand Up @@ -570,8 +571,11 @@ by preventing negative stock balances.<br/>")
(gnc-numeric-add trans-bought split-value commod-currency-frac GNC-RND-ROUND))
(set! shares-bought
(gnc-numeric-add shares-bought split-units units-denom GNC-RND-ROUND)))
(set! trans-sold
(gnc-numeric-sub trans-sold split-value commod-currency-frac GNC-RND-ROUND)))))
(begin
(set! trans-sold
(gnc-numeric-sub trans-sold split-value commod-currency-frac GNC-RND-ROUND))
(set! shares-sold
(gnc-numeric-add shares-sold split-units units-denom GNC-RND-ROUND))))))

((split-account-type? s ACCT-TYPE-ASSET)
;; If all the asset accounts mentioned in the transaction are siblings of each other
Expand All @@ -594,7 +598,8 @@ by preventing negative stock balances.<br/>")
(gnc:debug "Income: " (gnc-numeric-to-string trans-income)
" Brokerage: " (gnc-numeric-to-string trans-brokerage)
" Shares traded: " (gnc-numeric-to-string trans-shares)
" Shares bought: " (gnc-numeric-to-string shares-bought))
" Shares bought: " (gnc-numeric-to-string shares-bought)
" Shares sold " (gnc-numeric-to-string shares-sold))
(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)
Expand Down Expand Up @@ -626,6 +631,14 @@ by preventing negative stock balances.<br/>")
(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))))

;; Add brokerage fees to trans-sold if not ignoring them and there are any
(if (and (not (eq? handle-brokerage-fees 'ignore-brokerage))
(gnc-numeric-positive-p trans-brokerage)
(gnc-numeric-positive-p trans-shares))
(let* ((fee-frac (gnc-numeric-div shares-sold trans-shares GNC-DENOM-AUTO GNC-DENOM-REDUCE))
(fees (gnc-numeric-mul trans-brokerage fee-frac commod-currency-frac GNC-RND-ROUND)))
(set! trans-sold (gnc-numeric-add trans-sold fees commod-currency-frac GNC-RND-ROUND))))

;; 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.
Expand Down
6 changes: 3 additions & 3 deletions gnucash/report/reports/standard/test/test-portfolios.scm
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@
(let ((sxml (options->sxml advanced-uuid options "basic average")))
(test-equal "advanced: average basis"
'("AAPL" "AAPL" "NASDAQ" "42.00" "$6.0000" "$484.88" "$252.00" "$800.00"
"$553.00" "$227.88" "-$232.88" "-$5.00" "-0.63%" "$4.00"
"$543.00" "$227.88" "-$232.88" "-$5.00" "-0.63%" "$4.00"
"$10.00" "-$1.00" "-0.13%")
(sxml->table-row-col sxml 1 1 #f)))

(set-option! options "General" "Basis calculation method" 'fifo-basis)
(let ((sxml (options->sxml advanced-uuid options "basic fifo")))
(test-equal "advanced: fifo basis"
'("AAPL" "AAPL" "NASDAQ" "42.00" "$6.0000" "$543.94" "$252.00" "$800.00"
"$553.00" "$286.94" "-$291.94" "-$5.00" "-0.63%" "$4.00" "$10.00"
"$543.00" "$286.94" "-$291.94" "-$5.00" "-0.63%" "$4.00" "$10.00"
"-$1.00" "-0.13%")
(sxml->table-row-col sxml 1 1 #f)))

(set-option! options "General" "Basis calculation method" 'filo-basis)
(let ((sxml (options->sxml advanced-uuid options "basic filo")))
(test-equal "advanced: filo basis"
'("AAPL" "AAPL" "NASDAQ" "42.00" "$6.0000" "$400.00" "$252.00" "$800.00"
"$553.00" "$143.00" "-$148.00" "-$5.00" "-0.63%" "$4.00" "$10.00"
"$543.00" "$143.00" "-$148.00" "-$5.00" "-0.63%" "$4.00" "$10.00"
"-$1.00" "-0.13%")
(sxml->table-row-col sxml 1 1 #f))))
(teardown)))

0 comments on commit 2e20b37

Please sign in to comment.