[trep-engine] account name filter can exclude filtered string

This commit is contained in:
Christopher Lam 2022-02-08 20:07:05 +08:00
parent 331a394795
commit 616658dbe9
2 changed files with 34 additions and 8 deletions

View File

@ -330,6 +330,21 @@
'("$31.00") '("$31.00")
(get-row-col sxml -1 -1))) (get-row-col sxml -1 -1)))
;; Filter Account Name Filters
(set-option! options "Filter" "Account Name Filter excludes matched strings"
#t)
(let ((sxml (options->sxml options "accounts filter exclude expen.es regex")))
(test-equal "account name filter to 'expen.es, regex, negated', sum = -$31.00"
'("-$31.00")
(get-row-col sxml -1 -1)))
(set-option! options "Filter" "Use regular expressions for account name filter"
#f)
(let ((sxml (options->sxml options "accounts filter exclude expen.es")))
(test-equal "account name filter to 'expen.es, negated', sum = $0.00"
'("$0.00")
(get-row-col sxml -1 -1)))
;; Test Transaction Filters ;; Test Transaction Filters
(set! options (default-testing-options)) (set! options (default-testing-options))
(set-option! options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 01 01 1969))) (set-option! options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 01 01 1969)))

View File

@ -110,6 +110,8 @@
(define optname-account-matcher (N_ "Account Name Filter")) (define optname-account-matcher (N_ "Account Name Filter"))
(define optname-account-matcher-regex (define optname-account-matcher-regex
(N_ "Use regular expressions for account name filter")) (N_ "Use regular expressions for account name filter"))
(define optname-account-matcher-exclude
(N_ "Account Name Filter excludes matched strings"))
(define optname-transaction-matcher (N_ "Transaction Filter")) (define optname-transaction-matcher (N_ "Transaction Filter"))
(define optname-transaction-matcher-regex (define optname-transaction-matcher-regex
(N_ "Use regular expressions for transaction filter")) (N_ "Use regular expressions for transaction filter"))
@ -582,6 +584,12 @@ Expenses:Car and Expenses:Flights. Use a period (.) to match a single character
'20../.' will match 'Travel 2017/1 London'. ") '20../.' will match 'Travel 2017/1 London'. ")
#f)) #f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-account-matcher-exclude "a7"
(G_ "If this option is selected, accounts matching filter are excluded.")
#f))
(gnc:register-trep-option (gnc:register-trep-option
(gnc:make-string-option (gnc:make-string-option
pagename-filter optname-transaction-matcher pagename-filter optname-transaction-matcher
@ -1987,6 +1995,7 @@ warning will be removed in GnuCash 5.0"))
(let* ((document (gnc:make-html-document)) (let* ((document (gnc:make-html-document))
(account-matcher (opt-val pagename-filter optname-account-matcher)) (account-matcher (opt-val pagename-filter optname-account-matcher))
(account-matcher-neg (opt-val pagename-filter optname-account-matcher-exclude))
(account-matcher-regexp (account-matcher-regexp
(and (opt-val pagename-filter optname-account-matcher-regex) (and (opt-val pagename-filter optname-account-matcher-regex)
(if (defined? 'make-regexp) (if (defined? 'make-regexp)
@ -1996,14 +2005,16 @@ warning will be removed in GnuCash 5.0"))
'no-guile-regex-support))) 'no-guile-regex-support)))
(c_account_0 (or custom-source-accounts (c_account_0 (or custom-source-accounts
(opt-val gnc:pagename-accounts optname-accounts))) (opt-val gnc:pagename-accounts optname-accounts)))
(c_account_1 (filter (acct? (lambda (acc)
(lambda (acc) (if (regexp? account-matcher-regexp)
(if (regexp? account-matcher-regexp) (regexp-exec account-matcher-regexp
(regexp-exec account-matcher-regexp (gnc-account-get-full-name acc))
(gnc-account-get-full-name acc)) (string-contains (gnc-account-get-full-name acc)
(string-contains (gnc-account-get-full-name acc) account-matcher))))
account-matcher))) (c_account_1 (if (string-null? account-matcher)
c_account_0)) c_account_0
(filter (if account-matcher-neg (negate acct?) acct?)
c_account_0)))
(c_account_2 (opt-val gnc:pagename-accounts optname-filterby)) (c_account_2 (opt-val gnc:pagename-accounts optname-filterby))
(filter-mode (opt-val gnc:pagename-accounts optname-filtertype)) (filter-mode (opt-val gnc:pagename-accounts optname-filtertype))
(begindate (gnc:time64-start-day-time (begindate (gnc:time64-start-day-time