TR: rename some variable names to be more descriptive

The previous names were remnants of old transaction.scm and were not
exactly consistent. Use more descriptive names.

The only user-visible change is elimination of <br/> in the
common-currency account header, because this will be sanitized.  The
table col-headers cannot unfortunately accept a (gnc:make-html-text)
object therefore we cannot add <br/> at all. I vote to display
e.g. "Debit (USD)" instead.
This commit is contained in:
Christopher Lam 2018-05-03 21:59:22 +08:00
parent ac510d13be
commit d68ccc3306
2 changed files with 38 additions and 42 deletions

View File

@ -354,7 +354,7 @@
(set-option! options "Sorting" "Secondary Subtotal for Date Key" 'monthly) (set-option! options "Sorting" "Secondary Subtotal for Date Key" 'monthly)
(let ((sxml (options->sxml options "test basic column headers, and original currency"))) (let ((sxml (options->sxml options "test basic column headers, and original currency")))
(test-equal "default headers, indented, includes common-currency" (test-equal "default headers, indented, includes common-currency"
'(" " " " "Date" "Num" "Description" "Memo/Notes" "Account" "Amount" "USD" "Amount") '(" " " " "Date" "Num" "Description" "Memo/Notes" "Account" "Amount (USD)" "Amount")
(get-row-col sxml 0 #f)) (get-row-col sxml 0 #f))
(test-equal "grand total present, no blank cells, and is $2,280 in both common-currency and original-currency" (test-equal "grand total present, no blank cells, and is $2,280 in both common-currency and original-currency"
'("Grand Total" "$2,280.00" "$2,280.00") '("Grand Total" "$2,280.00" "$2,280.00")
@ -614,7 +614,7 @@
(let* ((sxml (options->sxml options "single column, with original currency headers"))) (let* ((sxml (options->sxml options "single column, with original currency headers")))
(test-equal "single amount column, with original currency headers" (test-equal "single amount column, with original currency headers"
(list "Date" "Num" "Description" "Memo/Notes" "Account" (list "Date" "Num" "Description" "Memo/Notes" "Account"
"Amount" "USD" "Amount") "Amount (USD)" "Amount")
(get-row-col sxml 0 #f))) (get-row-col sxml 0 #f)))
(set-option! options "Display" "Amount" 'double) (set-option! options "Display" "Amount" 'double)
@ -631,7 +631,7 @@
;; output here too. ;; output here too.
(test-equal "dual amount headers" (test-equal "dual amount headers"
(list "Date" "Num" "Description" "Memo/Notes" "Account" "Transfer from/to" (list "Date" "Num" "Description" "Memo/Notes" "Account" "Transfer from/to"
"Debit" "USD" "Credit" "USD" "Debit" "Credit") "Debit (USD)" "Credit (USD)" "Debit" "Credit")
(get-row-col sxml 0 #f)) (get-row-col sxml 0 #f))
(test-equal "Account Name and Code displayed" (test-equal "Account Name and Code displayed"
(list "01-GBP Root.Asset.GBP Bank") (list "01-GBP Root.Asset.GBP Bank")
@ -693,7 +693,7 @@
(let* ((sxml (options->sxml options "dual columns"))) (let* ((sxml (options->sxml options "dual columns")))
(test-equal "dual amount column, with original currency headers" (test-equal "dual amount column, with original currency headers"
(list "Date" "Num" "Description" "Memo/Notes" "Account" (list "Date" "Num" "Description" "Memo/Notes" "Account"
"Debit" "USD" "Credit" "USD" "Debit" "Credit") "Debit (USD)" "Credit (USD)" "Debit" "Credit")
(get-row-col sxml 0 #f)) (get-row-col sxml 0 #f))
(test-equal "dual amount column, grand totals available" (test-equal "dual amount column, grand totals available"
(list "Grand Total" " " " " " " " " "$2,280.00" "$2,280.00") (list "Grand Total" " " " " " " " " "$2,280.00" "$2,280.00")

View File

@ -1156,48 +1156,42 @@ be excluded from periodic reporting.")
(define default-calculated-cells (define default-calculated-cells
(letrec (letrec
((damount (lambda (s) (if (gnc:split-voided? s) ((split-amount (lambda (s) (if (gnc:split-voided? s)
(xaccSplitVoidFormerAmount s) (xaccSplitVoidFormerAmount s)
(xaccSplitGetAmount s)))) (xaccSplitGetAmount s))))
(trans-date (lambda (s) (xaccTransGetDate (xaccSplitGetParent s)))) (split-currency (lambda (s) (xaccAccountGetCommodity (xaccSplitGetAccount s))))
(currency (lambda (s) (xaccAccountGetCommodity (xaccSplitGetAccount s)))) (row-currency (lambda (s) (if (column-uses? 'common-currency)
(report-currency (lambda (s) (if (column-uses? 'common-currency) (opt-val gnc:pagename-general optname-currency)
(opt-val gnc:pagename-general optname-currency) (split-currency s))))
(currency s))))
(friendly-debit (lambda (a) (gnc:get-debit-string (xaccAccountGetType a)))) (friendly-debit (lambda (a) (gnc:get-debit-string (xaccAccountGetType a))))
(friendly-credit (lambda (a) (gnc:get-credit-string (xaccAccountGetType a)))) (friendly-credit (lambda (a) (gnc:get-credit-string (xaccAccountGetType a))))
(header-commodity (lambda (str) (header-commodity (lambda (str)
(string-append (string-append
str str
(if (column-uses? 'common-currency) (if (column-uses? 'common-currency)
(string-append (format #f " (~a)"
"<br />" (gnc-commodity-get-mnemonic
(gnc-commodity-get-mnemonic (opt-val gnc:pagename-general optname-currency)))
(opt-val gnc:pagename-general optname-currency)))
"")))) ""))))
(convert (lambda (s num) ;; For conversion to row-currency. Use midday as the
(gnc:exchange-by-pricedb-nearest ;; transaction time so it matches a price on the same day.
(gnc:make-gnc-monetary (currency s) num) ;; Otherwise it uses midnight which will likely match a
(report-currency s) ;; price on the previous day
;; Use midday as the transaction time so it matches a price (converted-amount (lambda (s) (gnc:exchange-by-pricedb-nearest
;; on the same day. Otherwise it uses midnight which will (gnc:make-gnc-monetary (split-currency s) (split-amount s))
;; likely match a price on the previous day (row-currency s)
(time64CanonicalDayTime (trans-date s))))) (time64CanonicalDayTime
(split-value (lambda (s) (convert s (damount s)))) ; used for correct debit/credit (xaccTransGetDate (xaccSplitGetParent s))))))
(amount (lambda (s) (split-value s))) (converted-debit-amount (lambda (s) (and (positive? (split-amount s))
(debit-amount (lambda (s) (and (positive? (gnc:gnc-monetary-amount (split-value s))) (converted-amount s))))
(split-value s)))) (converted-credit-amount (lambda (s) (and (not (positive? (split-amount s)))
(credit-amount (lambda (s) (if (positive? (gnc:gnc-monetary-amount (split-value s))) (gnc:monetary-neg (converted-amount s)))))
#f (original-amount (lambda (s) (gnc:make-gnc-monetary (split-currency s) (split-amount s))))
(gnc:monetary-neg (split-value s))))) (original-debit-amount (lambda (s) (and (positive? (split-amount s))
(original-amount (lambda (s) (gnc:make-gnc-monetary (currency s) (damount s)))) (original-amount s))))
(original-debit-amount (lambda (s) (if (positive? (damount s)) (original-credit-amount (lambda (s) (and (not (positive? (split-amount s)))
(original-amount s) (gnc:monetary-neg (original-amount s)))))
#f))) (running-balance (lambda (s) (gnc:make-gnc-monetary (split-currency s) (xaccSplitGetBalance s)))))
(original-credit-amount (lambda (s) (if (positive? (damount s))
#f
(gnc:monetary-neg (original-amount s)))))
(running-balance (lambda (s) (gnc:make-gnc-monetary (currency s) (xaccSplitGetBalance s)))))
(append (append
;; each column will be a vector ;; each column will be a vector
;; (vector heading ;; (vector heading
@ -1207,17 +1201,19 @@ be excluded from periodic reporting.")
;; start-dual-column? ;; #t for the debit side of a dual column (i.e. debit/credit) ;; start-dual-column? ;; #t for the debit side of a dual column (i.e. debit/credit)
;; ;; which means the next column must be the credit side ;; ;; which means the next column must be the credit side
;; friendly-heading-fn ;; (friendly-heading-fn account) to retrieve friendly name for account debit/credit ;; friendly-heading-fn ;; (friendly-heading-fn account) to retrieve friendly name for account debit/credit
(if (column-uses? 'amount-single) (if (column-uses? 'amount-single)
(list (vector (header-commodity (_ "Amount")) (list (vector (header-commodity (_ "Amount"))
amount #t #t #f converted-amount #t #t #f
(lambda (a) ""))) (lambda (a) "")))
'()) '())
(if (column-uses? 'amount-double) (if (column-uses? 'amount-double)
(list (vector (header-commodity (_ "Debit")) (list (vector (header-commodity (_ "Debit"))
debit-amount #f #t #t converted-debit-amount #f #t #t
friendly-debit) friendly-debit)
(vector (header-commodity (_ "Credit")) (vector (header-commodity (_ "Credit"))
credit-amount #f #t #f converted-credit-amount #f #t #f
friendly-credit)) friendly-credit))
'()) '())