gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Fri Mar 29 13:49:50 EDT 2019
Updated via https://github.com/Gnucash/gnucash/commit/a4eb5b1a (commit)
via https://github.com/Gnucash/gnucash/commit/faf1b08c (commit)
from https://github.com/Gnucash/gnucash/commit/79d72fdc (commit)
commit a4eb5b1a591f9d02d817ca0544efc2ea96203556
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Mar 28 12:02:20 2019 +0800
[options] compact book-currency-acounting functions
diff --git a/libgnucash/app-utils/options.scm b/libgnucash/app-utils/options.scm
index b5ee3d2bf..9f9bf62e9 100644
--- a/libgnucash/app-utils/options.scm
+++ b/libgnucash/app-utils/options.scm
@@ -1464,10 +1464,10 @@ the option '~a'."))
(xaccAccountGetCommodity account)))))
(let* ((value (if (eq? 'book-currency default-radiobutton-value)
- (cons default-radiobutton-value
- (cons default-book-currency-value
- (cons default-cap-gains-policy-value '())))
- (cons default-radiobutton-value '())))
+ (list default-radiobutton-value
+ default-book-currency-value
+ default-cap-gains-policy-value)
+ (list default-radiobutton-value)))
(value->string (lambda ()
(string-append "'" (gnc:value->string
(car value)))))
@@ -1488,42 +1488,32 @@ the option '~a'."))
(set! value x)
(gnc:error "Illegal Radiobutton option set"))) ;;setter
(lambda () (if (eq? 'book-currency default-radiobutton-value)
- (cons default-radiobutton-value
- (cons default-book-currency-value
- (cons default-cap-gains-policy-value
- (cons '() '()))))
- (cons default-radiobutton-value '()))) ;; default-getter
+ (list default-radiobutton-value
+ default-book-currency-value
+ default-cap-gains-policy-value)
+ (list default-radiobutton-value))) ;; default-getter
(gnc:restore-form-generator value->string)
(lambda (b p) ;; scm->kvp
- (if (eq? 'book-currency (car value))
- (begin
- ;; Currency = selected currency
- (qof-book-set-option
- b
- (currency->scm (cadr value))
- book-currency-path)
- ;; Default Gains Policy = selected policy
- (qof-book-set-option
- b
- (symbol->string (caddr value))
- gains-policy-path)
- ;; Default Gains Account = if selected, selected account
- (if (car (cdddr value))
- (qof-book-set-option
- b
- (car (cdddr value))
- gains-loss-account-path)))
- (if (eq? 'trading (car value))
- ;; Use Trading Accounts = "t"
- (qof-book-set-option b "t" trading-accounts-path))))
+ (case (car value)
+ ((book-currency)
+ ;; Currency = selected currency
+ (qof-book-set-option b (currency->scm (cadr value))
+ book-currency-path)
+ ;; Default Gains Policy = selected policy
+ (qof-book-set-option b (symbol->string (caddr value))
+ gains-policy-path)
+ ;; Default Gains Account = if selected, selected account
+ (if (car (cdddr value))
+ (qof-book-set-option b (car (cdddr value))
+ gains-loss-account-path)))
+ ((trading)
+ ;; Use Trading Accounts = "t"
+ (qof-book-set-option b "t" trading-accounts-path))))
(lambda (b p) ;; kvp->scm
(let* ((trading-option-path-kvp?
- (qof-book-get-option
- b trading-accounts-path))
- (trading? (if (and trading-option-path-kvp?
- (string=? "t" trading-option-path-kvp?))
- #t
- #f))
+ (qof-book-get-option b trading-accounts-path))
+ (trading? (and trading-option-path-kvp?
+ (string=? "t" trading-option-path-kvp?)))
(book-currency #f)
(cap-gains-policy #f)
(gains-loss-account-guid #f)
@@ -1573,25 +1563,26 @@ the option '~a'."))
(string->symbol cap-gains-policy)
gains-loss-account-guid)
'())))
- (set! value (cons 'neither '())))))
+ (set! value (list 'neither)))))
(lambda (x) ;; value validator
- (if (list? x)
- (if (legal-val (car x) ok-radiobutton-values)
- (if (eq? 'book-currency (car x))
- (if (currency? (currency->scm (cadr x)))
- (if (gnc-valid-policy-name (symbol->string (caddr x)))
- (if (car(cdddr x))
- (if (valid-gains-loss-account?
- (currency->scm (cadr x))
- (car(cdddr x)))
- (list #t x)
- (list #f "gains-loss-account-option: illegal value"))
- (list #t x)) ;; must be valid if specified, otherwise OK
- (list #f "cap-gains-policy-option: illegal value"))
- (list #f "currency-option: illegal value"))
- (list #t x))
- (list #f "radiobutton-option: illegal choice"))
- (list #f "value not a list")))
+ (cond
+ ((not (list? x))
+ (list #f "value not a list"))
+ ((not (legal-val (car x) ok-radiobutton-values))
+ (list #f "radiobutton-option: illegal choice"))
+ ((not (eq? 'book-currency (car x)))
+ (list #t x))
+ ((not (currency? (currency->scm (cadr x))))
+ (list #f "currency-option: illegal value"))
+ ((not (gnc-valid-policy-name (symbol->string (caddr x))))
+ (list #f "cap-gains-policy-option: illegal value"))
+ ((not (car (cdddr x)))
+ (list #t x))
+ ((not (valid-gains-loss-account? (currency->scm (cadr x))
+ (car (cdddr x))))
+ (list #f "gains-loss-account-option: illegal value"))
+ (else
+ (list #t x))))
(vector book-currency-documentation-string
default-book-currency-value
default-cap-gains-policy-documentation-string
commit faf1b08cecf36e006c46878af36a6438341375e5
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Mar 28 11:48:41 2019 +0800
[options] compact valid-gains-loss-account?
diff --git a/libgnucash/app-utils/options.scm b/libgnucash/app-utils/options.scm
index a05a719fd..b5ee3d2bf 100644
--- a/libgnucash/app-utils/options.scm
+++ b/libgnucash/app-utils/options.scm
@@ -1449,36 +1449,19 @@ the option '~a'."))
(currency-lookup currency))
(define (valid-gains-loss-account? book-currency gains-loss-account-guid)
- ;; xaccAccountLookup returns Account if guid valid otherwise NULL; also must
- ;; be in book-currency, income or expense, and not placeholder nor hidden
+ ;; xaccAccountLookup returns Account if guid valid otherwise NULL; also must
+ ;; be in book-currency, income or expense, and not placeholder nor hidden
(let* ((account (xaccAccountLookup gains-loss-account-guid
- (gnc-get-current-book)))
- (hidden? (if account
- (xaccAccountIsHidden account)
- #t))
- (placeholder? (if account
- (xaccAccountGetPlaceholder account)
- #t))
- (account-type (if account
- (xaccAccountGetType account)
- #f))
- (income-or-expense? (if (and account account-type)
- (or (= ACCT-TYPE-INCOME account-type)
- (= ACCT-TYPE-EXPENSE account-type))
- #f))
- (commodity-eq-book-curr? (if account
- (gnc-commodity-equal
- (currency-lookup book-currency)
- (xaccAccountGetCommodity account))
- #f))
- )
- (if (and account
- (not hidden?)
- (not placeholder?)
- income-or-expense?
- commodity-eq-book-curr?)
- #t
- #f)))
+ (gnc-get-current-book))))
+ (and account
+ (not (null? account))
+ (not (xaccAccountIsHidden account))
+ (not (xaccAccountGetPlaceholder account))
+ (memv (xaccAccountGetType account)
+ (list ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE))
+ (gnc-commodity-equal
+ (currency-lookup book-currency)
+ (xaccAccountGetCommodity account)))))
(let* ((value (if (eq? 'book-currency default-radiobutton-value)
(cons default-radiobutton-value
Summary of changes:
libgnucash/app-utils/options.scm | 140 ++++++++++++++++-----------------------
1 file changed, 57 insertions(+), 83 deletions(-)
More information about the gnucash-changes
mailing list