[qif-guess-map] use (ice-9 match), and compact functions

This commit is contained in:
Christopher Lam 2020-02-29 21:22:11 +08:00
parent 890c96ce23
commit 11689e2a4d

View File

@ -25,6 +25,7 @@
(use-modules (srfi srfi-13)) (use-modules (srfi srfi-13))
(use-modules (ice-9 match))
(define GNC-BANK-TYPE 0) (define GNC-BANK-TYPE 0)
(define GNC-CASH-TYPE 1) (define GNC-CASH-TYPE 1)
@ -227,24 +228,21 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:read-securities security-list) (define (qif-import:read-securities security-list)
(let ((table (make-hash-table 20))) (let ((table (make-hash-table))
(comm-table (gnc-commodity-table-get-table (gnc-get-current-book))))
(for-each (for-each
(lambda (entry) (match-lambda
(if (and (list? entry) ((name ns mnemonic)
(= 3 (length entry))) ;; The saved information about each security mapping is a
;; The saved information about each security mapping is a ;; list of three items: the QIF name, and the GnuCash
;; list of three items: the QIF name, and the GnuCash ;; namespace and mnemonic (symbol) to which it maps.
;; namespace and mnemonic (symbol) to which it maps. ;; Example: ("McDonald's" "NYSE" "MCD")
;; Example: ("McDonald's" "NYSE" "MCD") (let ((commodity (gnc-commodity-table-lookup comm-table ns mnemonic)))
(let ((commodity (gnc-commodity-table-lookup (if (and commodity (not (null? commodity)))
(gnc-commodity-table-get-table ;; There is an existing GnuCash commodity for this
(gnc-get-current-book)) ;; combination of namespace and symbol.
(cadr entry) (hash-set! table name commodity))))
(caddr entry)))) (_ #f))
(if (and commodity (not (null? commodity)))
;; There is an existing GnuCash commodity for this
;; combination of namespace and symbol.
(hash-set! table (car entry) commodity)))))
security-list) security-list)
table)) table))
@ -462,18 +460,11 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:find-new-acct qif-acct allowed-types gnc-acct-info) (define (qif-import:find-new-acct qif-acct allowed-types gnc-acct-info)
(cond ((and (string? qif-acct) (cond
(string=? qif-acct (default-equity-account))) ((equal? qif-acct (default-equity-account))
(let ((existing-equity (or (qif-import:find-similar-acct
(qif-import:find-similar-acct (default-equity-account) (default-equity-account) (list GNC-EQUITY-TYPE) gnc-acct-info)
(list GNC-EQUITY-TYPE) (list (default-equity-account) (list GNC-EQUITY-TYPE))))
gnc-acct-info))) ((equal? qif-acct "") (list (default-unspec-acct) allowed-types))
(if existing-equity (else (list qif-acct allowed-types))))
existing-equity
(list (default-equity-account) (list GNC-EQUITY-TYPE)))))
((and (string? qif-acct)
(not (string=? qif-acct "")))
(list qif-acct allowed-types))
(#t
(list (default-unspec-acct) allowed-types))))