Bug #515163: QIF importer no longer asks for mappings that will never get used.

BP


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17186 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Charles Day 2008-06-01 19:31:26 +00:00
parent 26a8c73c70
commit f7447960c1

View File

@ -57,6 +57,14 @@
(define (default-unspec-acct) (define (default-unspec-acct)
(_ "Unspecified")) (_ "Unspecified"))
;; The following investment actions implicitly specify
;; the two accounts involved in the transaction.
(define qif-import:actions-implicit
(list 'buy 'cglong 'cgmid 'cgshort 'div 'intinc 'margint 'reinvdiv
'reinvint 'reinvlg 'reinvmd 'reinvsg 'reinvsh 'reminder
'rtrncap 'sell 'shrsin 'shrsout 'stksplit))
(define (qif-import:gnc-account-exists map-entry acct-list) (define (qif-import:gnc-account-exists map-entry acct-list)
(let ((retval #f)) (let ((retval #f))
(for-each (for-each
@ -155,8 +163,10 @@
((divx cgshortx cgmidx cglongx intincx margintx rtrncapx) ((divx cgshortx cgmidx cglongx intincx margintx rtrncapx)
(set! qif-account (set! qif-account
(and (qif-split:category-is-account?
(car (qif-xtn:splits xtn)))
(qif-split:category (qif-split:category
(car (qif-xtn:splits xtn)))) (car (qif-xtn:splits xtn)))))
(set! qif-account-types (list GNC-BANK-TYPE (set! qif-account-types (list GNC-BANK-TYPE
GNC-CCARD-TYPE GNC-CCARD-TYPE
GNC-CASH-TYPE GNC-CASH-TYPE
@ -214,8 +224,10 @@
GNC-PAYABLE-TYPE))) GNC-PAYABLE-TYPE)))
((buyx sellx xin xout) ((buyx sellx xin xout)
(set! qif-account (set! qif-account
(and (qif-split:category-is-account?
(car (qif-xtn:splits xtn)))
(qif-split:category (qif-split:category
(car (qif-xtn:splits xtn)))) (car (qif-xtn:splits xtn)))))
(set! qif-account-types (list GNC-BANK-TYPE (set! qif-account-types (list GNC-BANK-TYPE
GNC-CCARD-TYPE GNC-CCARD-TYPE
GNC-CASH-TYPE GNC-CASH-TYPE
@ -415,6 +427,12 @@
(lambda (qif-file) (lambda (qif-file)
(for-each (for-each
(lambda (xtn) (lambda (xtn)
(let ((action (qif-xtn:action xtn)))
;; Many types of investment transactions implicitly use the
;; brokerage account or a known offshoot. There is no need
;; to consider a category mapping for these.
(if (not (and action
(memv action qif-import:actions-implicit)))
;; iterate over the splits ;; iterate over the splits
(for-each (for-each
(lambda (split) (lambda (split)
@ -425,18 +443,46 @@
(begin (begin
(set! xtn-cat (qif-split:category split)) (set! xtn-cat (qif-split:category split))
(set! entry (hash-ref cat-hash xtn-cat)) (set! entry (hash-ref cat-hash xtn-cat))
(if (not entry) ;; NOTE: It would be more robust and efficient if the
;; three "make display" routines below were combined:
;; make-account-display
;; make-category-display
;; make-memo-display
;;
;; This would also require adjusting several callback
;; functions that reference these procedures from C.
;;
;; Until then, the maintainer of this code must make
;; sure that the logic used in the "if" below matches
;; the criteria for making memo/payee mappings (seen
;; in make-memo-display).
;; Add an entry if there isn't one already and either
;; (a) the category is non-blank, or
;; (b) no memo/payee mapping can be applied
(if (and (not entry)
(or (not (and (string? xtn-cat)
(string=? xtn-cat "")))
(and (or (not (qif-split:memo split))
(equal? (qif-split:memo split) ""))
(or (> (length (qif-xtn:splits xtn)) 1)
(not (qif-xtn:payee xtn))
(equal? (qif-xtn:payee xtn) "")))))
(set! entry (set! entry
(qif-import:guess-acct (qif-import:guess-acct
xtn-cat xtn-cat
(if (gnc-numeric-positive-p (if (gnc-numeric-positive-p
(qif-split:amount split)) (qif-split:amount split))
(list GNC-INCOME-TYPE GNC-EXPENSE-TYPE) (list GNC-INCOME-TYPE
(list GNC-EXPENSE-TYPE GNC-INCOME-TYPE)) GNC-EXPENSE-TYPE)
(list GNC-EXPENSE-TYPE
GNC-INCOME-TYPE))
gnc-acct-info))) gnc-acct-info)))
(if entry
(begin
(qif-map-entry:set-display?! entry #t) (qif-map-entry:set-display?! entry #t)
(hash-set! cat-hash xtn-cat entry))))) (hash-set! cat-hash xtn-cat entry)))))))
(qif-xtn:splits xtn))) (qif-xtn:splits xtn)))))
(qif-file:xtns qif-file))) (qif-file:xtns qif-file)))
qif-files) qif-files)
@ -478,7 +524,13 @@
(for-each (for-each
(lambda (xtn) (lambda (xtn)
(let ((payee (qif-xtn:payee xtn)) (let ((payee (qif-xtn:payee xtn))
(action (qif-xtn:action xtn))
(splits (qif-xtn:splits xtn))) (splits (qif-xtn:splits xtn)))
;; Many types of investment transactions implicitly use the
;; brokerage account or a known offshoot. There is no need
;; to consider a memo/payee mapping for these.
(if (not (and action
(memv action qif-import:actions-implicit)))
(for-each (for-each
(lambda (split) (lambda (split)
(let ((cat (qif-split:category split)) (let ((cat (qif-split:category split))
@ -520,7 +572,7 @@
GNC-STOCK-TYPE GNC-MUTUAL-TYPE))))) GNC-STOCK-TYPE GNC-MUTUAL-TYPE)))))
(qif-map-entry:set-display?! entry #t) (qif-map-entry:set-display?! entry #t)
(hash-set! memo-hash key-string entry))))) (hash-set! memo-hash key-string entry)))))
splits))) splits))))
(qif-file:xtns file))) (qif-file:xtns file)))
qif-files) qif-files)