Enhance account filter to a regex

This commit will enhance the account fullname filter to full regex matching capabilities. Will allow complex account fullname queries e.g. "Car|Flights|Travel"
This commit is contained in:
christopherlam 2017-10-24 12:59:25 +08:00 committed by Christopher Lam
parent b74c0bedfd
commit d077400ba8

View File

@ -37,6 +37,7 @@
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing. (use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
(use-modules (srfi srfi-1)) (use-modules (srfi srfi-1))
(use-modules (srfi srfi-13)) (use-modules (srfi srfi-13))
(use-modules (ice-9 regex))
(use-modules (gnucash gnc-module)) (use-modules (gnucash gnc-module))
(use-modules (gnucash gettext)) (use-modules (gnucash gettext))
(use-modules (gnucash printf)) (use-modules (gnucash printf))
@ -695,10 +696,10 @@ accounts must be of type ASSET for taxes paid on expenses, and type LIABILITY fo
(gnc:register-trep-option (gnc:register-trep-option
(gnc:make-string-option (gnc:make-string-option
gnc:pagename-accounts (N_ "Account Substring") gnc:pagename-accounts (N_ "Account Matcher")
"b15" (N_ "Match only above accounts whose fullname contains substring e.g. ':Travel' will \ "b15" (N_ "Match only above accounts whose fullname matches regex e.g. ':Travel' will \
match Expenses:Travel:Holiday and Expenses:Business:Travel. Can be left blank, which will \ match Expenses:Travel:Holiday and Expenses:Business:Travel. 'Car|Flights' will match both \
disable the substring filter. This filter is case-sensitive.") Expenses:Car and Expenses:Flights. It can be left blank, which will disable the matcher.")
"")) ""))
(gnc:register-trep-option (gnc:register-trep-option
@ -1587,10 +1588,10 @@ for taxes paid on expenses, and type LIABILITY for taxes collected on sales.")
(let* ((document (gnc:make-html-document)) (let* ((document (gnc:make-html-document))
(c_account_0 (opt-val gnc:pagename-accounts "Accounts")) (c_account_0 (opt-val gnc:pagename-accounts "Accounts"))
(c_account_substring (opt-val gnc:pagename-accounts "Account Substring")) (c_account_matcher (opt-val gnc:pagename-accounts "Account Matcher"))
(c_account_1 (filter (c_account_1 (filter
(lambda (acc) (lambda (acc)
(string-contains (gnc-account-get-full-name acc) c_account_substring)) (string-match c_account_matcher (gnc-account-get-full-name acc)))
c_account_0)) c_account_0))
(c_account_2 (opt-val gnc:pagename-accounts "Filter By...")) (c_account_2 (opt-val gnc:pagename-accounts "Filter By..."))
(tax-accounts (opt-val gnc:pagename-accounts "Tax Accounts")) (tax-accounts (opt-val gnc:pagename-accounts "Tax Accounts"))