Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "Show long account names" option in Advanced Portfolio report #1997

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gnucash/report/html-utilities.scm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
(export gnc:report-anchor-text)
(export gnc:make-report-anchor)
(export gnc:html-account-anchor)
(export gnc:html-long-account-anchor)
(export gnc:html-split-anchor)
(export gnc:html-transaction-anchor)
(export gnc:html-transaction-doclink-anchor)
Expand Down Expand Up @@ -189,6 +190,14 @@
(xaccAccountGetName acct))
"")))

;; returns the long account name as html-text and anchor to the register.
(define (gnc:html-long-account-anchor acct)
(gnc:make-html-text (if (and acct (not (null? acct)))
(gnc:html-markup-anchor
(gnc:account-anchor-text acct)
(gnc-account-get-full-name acct))
"")))

(define (gnc:html-split-anchor split text)
(gnc:make-html-text (if (not (null? (xaccSplitGetAccount split)))
(gnc:html-markup-anchor
Expand Down
35 changes: 25 additions & 10 deletions gnucash/report/reports/standard/advanced-portfolio.scm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

(define optname-price-source (N_ "Price Source"))
(define optname-shares-digits (N_ "Share decimal places"))
(define optname-show-long-account-names (N_ "Show long account names"))
(define optname-zero-shares (N_ "Include accounts with no shares"))
(define optname-show-symbol (N_ "Show ticker symbols"))
(define optname-show-listing (N_ "Show listings"))
Expand Down Expand Up @@ -97,27 +98,32 @@ by preventing negative stock balances.<br/>")
(vector 'ignore-brokerage (N_ "Omit from report"))))

(gnc-register-simple-boolean-option options
gnc:pagename-display optname-show-symbol "a"
gnc:pagename-display optname-show-long-account-names "a"
(N_ "Show long (instead of short) account names.")
#f)

(gnc-register-simple-boolean-option options
gnc:pagename-display optname-show-symbol "b"
(N_ "Display the ticker symbols.")
#t)

(gnc-register-simple-boolean-option options
gnc:pagename-display optname-show-listing "b"
gnc:pagename-display optname-show-listing "c"
(N_ "Display exchange listings.")
#t)

(gnc-register-simple-boolean-option options
gnc:pagename-display optname-show-shares "c"
gnc:pagename-display optname-show-shares "d"
(N_ "Display numbers of shares in accounts.")
#t)

(gnc-register-number-range-option options
gnc:pagename-display optname-shares-digits
"d" (N_ "The number of decimal places to use for share numbers.") 2
"e" (N_ "The number of decimal places to use for share numbers.") 2
0 9 1)

(gnc-register-simple-boolean-option options
gnc:pagename-display optname-show-price "e"
gnc:pagename-display optname-show-price "f"
(N_ "Display share prices.")
#t)

Expand Down Expand Up @@ -381,6 +387,8 @@ by preventing negative stock balances.<br/>")
(unit-collector (gnc:account-get-comm-balance-at-date
current to-date #f))
(units (cadr (unit-collector 'getpair commodity #f)))
(show-long-account-names (get-option gnc:pagename-display
optname-show-long-account-names))

;; Counter to keep track of stuff
(brokeragecoll (gnc:make-commodity-collector))
Expand Down Expand Up @@ -408,6 +416,12 @@ by preventing negative stock balances.<br/>")
(drp-holding-amount (gnc-numeric-zero))
)

;; Gets the account name.
(define (account->name account)
(if show-long-account-names
(gnc-account-get-full-name account)
(xaccAccountGetName account)))

(define (my-exchange-fn fromunits tocurrency)
(if (and (gnc-commodity-equiv currency tocurrency)
(gnc-commodity-equiv (gnc:gnc-monetary-commodity fromunits) commodity))
Expand All @@ -429,7 +443,7 @@ by preventing negative stock balances.<br/>")
tocurrency)
(exchange-fn fromunits tocurrency)))

(gnc:debug "Starting account " (xaccAccountGetName current) ", initial price: "
(gnc:debug "Starting account " (account->name current) ", initial price: "
(and price
(gnc:monetary->string
(gnc:make-gnc-monetary
Expand Down Expand Up @@ -799,8 +813,7 @@ by preventing negative stock balances.<br/>")
;; the report even though it doesn't have a split in the account
;; being reported on.

(let ((parent-account (gnc-account-get-parent current))
(account-name (xaccAccountGetName current)))
(let ((parent-account (gnc-account-get-parent current)))
(if (and (not (null? parent-account))
(member (xaccAccountGetType parent-account) (list ACCT-TYPE-ASSET ACCT-TYPE-BANK))
(gnc-commodity-is-currency (xaccAccountGetCommodity parent-account)))
Expand All @@ -813,7 +826,7 @@ by preventing negative stock balances.<br/>")
(txn-date (xaccTransGetDate parent)))
(if (and (not (null? other-acct))
(<= txn-date to-date)
(string=? (xaccAccountGetName other-acct) account-name)
(string=? (account->name other-acct) (account->name current))
(gnc-commodity-is-currency (xaccAccountGetCommodity other-acct)))
;; This is a two split transaction where the other split is to an
;; account with the same name as the current account. If it's an
Expand Down Expand Up @@ -867,7 +880,9 @@ by preventing negative stock balances.<br/>")
(gnc:gnc-monetary-amount income)
currency-frac GNC-RND-ROUND)))

(activecols (list (gnc:html-account-anchor current)))
(activecols (list (if show-long-account-names
(gnc:html-long-account-anchor current)
(gnc:html-account-anchor current))))
)

;; If we're using the txn, warn the user
Expand Down