Skip to content

Commit

Permalink
Merge branch 'maint-trep-case-insensitive' PR #719
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed May 12, 2020
2 parents ebd9db8 + b4d7386 commit 57fe051
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
16 changes: 16 additions & 0 deletions gnucash/report/reports/standard/test/test-transaction.scm
Expand Up @@ -355,6 +355,22 @@
'("$24.00")
(get-row-col sxml -1 -1)))

(set-option! options "Filter" "Transaction Filter excludes matched strings" #f)
(set-option! options "Filter" "Use regular expressions for transaction filter" #f)
(set-option! options "Filter" "Transaction Filter is case insensitive" #t)
(set-option! options "Filter" "Transaction Filter" "dEsC-3")
(let ((sxml (options->sxml options "transaction filter insensitive")))
(test-equal "transaction filter case insensitive"
'("$29.00")
(get-row-col sxml -1 -1)))

(set-option! options "Filter" "Use regular expressions for transaction filter" #t)
(set-option! options "Filter" "Transaction Filter" "NoT.S?")
(let ((sxml (options->sxml options "transaction filter regex case insensitive")))
(test-equal "transaction filter regex case insensitive"
'("-$23.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)))
Expand Down
29 changes: 24 additions & 5 deletions gnucash/report/trep-engine.scm
Expand Up @@ -92,6 +92,8 @@
(N_ "Use regular expressions for transaction filter"))
(define optname-transaction-matcher-exclude
(N_ "Transaction Filter excludes matched strings"))
(define optname-transaction-matcher-caseinsensitive
(N_ "Transaction Filter is case insensitive"))
(define optname-reconcile-status (N_ "Reconcile Status"))
(define optname-void-transactions (N_ "Void Transactions"))
(define optname-closing-transactions (N_ "Closing transactions"))
Expand Down Expand Up @@ -614,6 +616,13 @@ tags within description, notes or memo. ")
(_ "If this option is selected, transactions matching filter are excluded.")
#f))

(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-transaction-matcher-caseinsensitive
"i4"
(_ "If this option is selected, transactions matching filter is not case sensitive.")
#f))

(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-filter optname-reconcile-status
Expand Down Expand Up @@ -1985,11 +1994,16 @@ be excluded from periodic reporting.")
(gnc:date-option-absolute-time
(opt-val gnc:pagename-general optname-enddate))))
(transaction-matcher (opt-val pagename-filter optname-transaction-matcher))
(transaction-filter-case-insensitive?
(opt-val pagename-filter optname-transaction-matcher-caseinsensitive))
(transaction-matcher-regexp
(and (opt-val pagename-filter optname-transaction-matcher-regex)
(if (defined? 'make-regexp)
(catch 'regular-expression-syntax
(lambda () (make-regexp transaction-matcher))
(lambda ()
(if transaction-filter-case-insensitive?
(make-regexp transaction-matcher regexp/icase)
(make-regexp transaction-matcher)))
(const 'invalid-transaction-regex))
'no-guile-regex-support)))
(transaction-filter-exclude?
Expand Down Expand Up @@ -2025,12 +2039,17 @@ be excluded from periodic reporting.")
(eq? (opt-val gnc:pagename-display (N_ "Amount"))
'single)))
(infobox-display (opt-val gnc:pagename-general optname-infobox-display))
(match? (lambda (str)
(if transaction-matcher-regexp
(regexp-exec transaction-matcher-regexp str)
(string-contains str transaction-matcher))))
(query (qof-query-create-for-splits)))

(define (match? str)
(cond
(transaction-matcher-regexp
(regexp-exec transaction-matcher-regexp str))
(transaction-filter-case-insensitive?
(string-contains-ci str transaction-matcher))
(else
(string-contains str transaction-matcher))))

(define (generic-less? split-X split-Y sortkey date-subtotal-key ascend?)
;; compare splits X and Y, whereby
;; sortkey and date-subtotal-key specify the options used
Expand Down

0 comments on commit 57fe051

Please sign in to comment.