[trep-engine] add transaction filter exclude option

add boolean option which converts the transaction filter from
'include' to 'exclude'.
This commit is contained in:
Christopher Lam 2019-11-14 09:20:16 +08:00
parent 509c542a9a
commit 58258b9400
2 changed files with 25 additions and 3 deletions

View File

@ -89,6 +89,8 @@
(define optname-transaction-matcher (N_ "Transaction Filter"))
(define optname-transaction-matcher-regex
(N_ "Use regular expressions for transaction filter"))
(define optname-transaction-matcher-exclude
(N_ "Transaction Filter excludes matched strings"))
(define optname-reconcile-status (N_ "Reconcile Status"))
(define optname-void-transactions (N_ "Void Transactions"))
(define optname-closing-transactions (N_ "Closing transactions"))
@ -604,6 +606,13 @@ enable full POSIX regular expressions capabilities. '#work|#family' will match b
tags within description, notes or memo. ")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-transaction-matcher-exclude
"i3"
(_ "If this option is selected, transactions matching filter are excluded.")
#f))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-filter optname-reconcile-status
@ -1969,6 +1978,8 @@ be excluded from periodic reporting.")
(lambda () (make-regexp transaction-matcher))
(const 'invalid-transaction-regex))
'no-guile-regex-support)))
(transaction-filter-exclude?
(opt-val pagename-filter optname-transaction-matcher-exclude))
(reconcile-status-filter
(keylist-get-info reconcile-status-list
(opt-val pagename-filter optname-reconcile-status)
@ -2044,6 +2055,11 @@ be excluded from periodic reporting.")
(define (date-comparator? X Y)
(generic-less? X Y 'date 'none #t))
(define (transaction-filter-match split)
(or (match? (xaccTransGetDescription (xaccSplitGetParent split)))
(match? (xaccTransGetNotes (xaccSplitGetParent split)))
(match? (xaccSplitGetMemo split))))
(cond
((or (null? c_account_1)
(symbol? account-matcher-regexp)
@ -2129,9 +2145,9 @@ be excluded from periodic reporting.")
((include) (is-filter-member split c_account_2))
((exclude) (not (is-filter-member split c_account_2))))
(or (string-null? transaction-matcher)
(match? (xaccTransGetDescription trans))
(match? (xaccTransGetNotes trans))
(match? (xaccSplitGetMemo split)))
(if transaction-filter-exclude?
(not (transaction-filter-match split))
(transaction-filter-match split)))
(or (not custom-split-filter)
(custom-split-filter split)))))
splits))

View File

@ -349,6 +349,12 @@
'("-$23.00")
(get-row-col sxml -1 -1)))
(set-option! options "Filter" "Transaction Filter excludes matched strings" #t)
(let ((sxml (options->sxml options "negate transaction filter not.s?")))
(test-equal "transaction filter in bank to 'not.s?' and switch regex, sum = -$23.00"
'("$24.00")
(get-row-col sxml -1 -1)))
;; Test Reconcile Status Filters
(set! options (default-testing-options))
(set-option! options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 01 01 1969)))