From 58258b94002226ca635a327b945ab340fb7d4acc Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 14 Nov 2019 09:20:16 +0800 Subject: [PATCH] [trep-engine] add transaction filter exclude option add boolean option which converts the transaction filter from 'include' to 'exclude'. --- gnucash/report/report-system/trep-engine.scm | 22 ++++++++++++++++--- .../test/test-transaction.scm | 6 +++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gnucash/report/report-system/trep-engine.scm b/gnucash/report/report-system/trep-engine.scm index 7509a40ad8..5e83d506d0 100644 --- a/gnucash/report/report-system/trep-engine.scm +++ b/gnucash/report/report-system/trep-engine.scm @@ -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)) diff --git a/gnucash/report/standard-reports/test/test-transaction.scm b/gnucash/report/standard-reports/test/test-transaction.scm index b1a75d1620..50f43efda1 100644 --- a/gnucash/report/standard-reports/test/test-transaction.scm +++ b/gnucash/report/standard-reports/test/test-transaction.scm @@ -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)))