mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
improve split-remove-duplicates, combine filters
To use inbuilt list functions
This commit is contained in:
parent
3475a894f9
commit
cdb677633c
@ -1566,16 +1566,11 @@ for taxes paid on expenses, and type LIABILITY for taxes collected on sales.")
|
|||||||
;; ( map (lambda (acct) (gnc-account-get-full-name acct)) account-list))
|
;; ( map (lambda (acct) (gnc-account-get-full-name acct)) account-list))
|
||||||
|
|
||||||
(define (splits-filter-unique-transactions splits)
|
(define (splits-filter-unique-transactions splits)
|
||||||
(let ((have-trans-hash (make-hash-table)))
|
(define (same-txn? s1 s2)
|
||||||
(define (only-one-copy? split)
|
(define txn1 (xaccSplitGetParent s1))
|
||||||
(let* ((parent (xaccSplitGetParent split))
|
(define txn2 (xaccSplitGetParent s2))
|
||||||
(trans-guid (gncTransGetGUID parent)))
|
(xaccTransEqual txn1 txn2 #t #t #t #f))
|
||||||
(if (hash-ref have-trans-hash trans-guid #f)
|
(delete-duplicates! splits same-txn?))
|
||||||
#f ; already have a copy of this transaction
|
|
||||||
(begin
|
|
||||||
(hash-set! have-trans-hash trans-guid #t)
|
|
||||||
#t))))
|
|
||||||
(filter only-one-copy? splits)))
|
|
||||||
|
|
||||||
(define (is-filter-member split account-list)
|
(define (is-filter-member split account-list)
|
||||||
(let* ((txn (xaccSplitGetParent split))
|
(let* ((txn (xaccSplitGetParent split))
|
||||||
@ -1690,26 +1685,11 @@ for taxes paid on expenses, and type LIABILITY for taxes collected on sales.")
|
|||||||
|
|
||||||
;;(gnc:warn "Splits in trep-renderer:" splits)
|
;;(gnc:warn "Splits in trep-renderer:" splits)
|
||||||
|
|
||||||
;;(gnc:warn "Filter account names:" (get-other-account-names c_account_2))
|
; Combined Filter:
|
||||||
|
; - include/exclude splits to/from selected accounts
|
||||||
;;This should probably a cond or a case to allow for different filter types.
|
; - include only Invoices & Regular Transactions (i.e. remove Link & Payments)
|
||||||
;;(gnc:warn "Filter Mode: " filter-mode)
|
; - disallow Closing Transactions, and
|
||||||
(if (eq? filter-mode 'include)
|
; - substring/regex matcher for Description/Notes/Memo
|
||||||
(begin
|
|
||||||
;;(gnc:warn "Including Filter Accounts")
|
|
||||||
(set! splits (filter (lambda (split)
|
|
||||||
(is-filter-member split c_account_2))
|
|
||||||
splits))))
|
|
||||||
|
|
||||||
(if (eq? filter-mode 'exclude)
|
|
||||||
(begin
|
|
||||||
;;(gnc:warn "Excluding Filter Accounts")
|
|
||||||
(set! splits (filter (lambda (split)
|
|
||||||
(not (is-filter-member split c_account_2)))
|
|
||||||
splits))))
|
|
||||||
|
|
||||||
; Combines: Transaction Description/Notes/Memo matcher, include only
|
|
||||||
; invoices & regular transactions, and disallow closing txns.
|
|
||||||
(set! splits (filter
|
(set! splits (filter
|
||||||
(lambda (split)
|
(lambda (split)
|
||||||
(let* ((trans (xaccSplitGetParent split))
|
(let* ((trans (xaccSplitGetParent split))
|
||||||
@ -1718,7 +1698,9 @@ for taxes paid on expenses, and type LIABILITY for taxes collected on sales.")
|
|||||||
(if transaction-matcher-regexp
|
(if transaction-matcher-regexp
|
||||||
(regexp-exec transaction-matcher-regexp str)
|
(regexp-exec transaction-matcher-regexp str)
|
||||||
(string-contains str transaction-matcher)))))
|
(string-contains str transaction-matcher)))))
|
||||||
(and (member txn-type (list TXN-TYPE-NONE TXN-TYPE-INVOICE))
|
(and (if (eq? filter-mode 'include) (is-filter-member split c_account_2) #t)
|
||||||
|
(if (eq? filter-mode 'exclude) (not (is-filter-member split c_account_2)) #t)
|
||||||
|
(member txn-type (list TXN-TYPE-NONE TXN-TYPE-INVOICE))
|
||||||
(not (xaccTransGetIsClosingTxn trans))
|
(not (xaccTransGetIsClosingTxn trans))
|
||||||
(or (match? (xaccTransGetDescription trans))
|
(or (match? (xaccTransGetDescription trans))
|
||||||
(match? (xaccTransGetNotes trans))
|
(match? (xaccTransGetNotes trans))
|
||||||
|
Loading…
Reference in New Issue
Block a user