mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-25 18:30:23 -06:00
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:
parent
26a8c73c70
commit
f7447960c1
@ -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
|
||||||
(qif-split:category
|
(and (qif-split:category-is-account?
|
||||||
(car (qif-xtn:splits xtn))))
|
(car (qif-xtn:splits xtn)))
|
||||||
|
(qif-split:category
|
||||||
|
(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
|
||||||
(qif-split:category
|
(and (qif-split:category-is-account?
|
||||||
(car (qif-xtn:splits xtn))))
|
(car (qif-xtn:splits xtn)))
|
||||||
|
(qif-split:category
|
||||||
|
(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,28 +427,62 @@
|
|||||||
(lambda (qif-file)
|
(lambda (qif-file)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (xtn)
|
(lambda (xtn)
|
||||||
;; iterate over the splits
|
(let ((action (qif-xtn:action xtn)))
|
||||||
(for-each
|
;; Many types of investment transactions implicitly use the
|
||||||
(lambda (split)
|
;; brokerage account or a known offshoot. There is no need
|
||||||
(let ((xtn-is-acct (qif-split:category-is-account? split))
|
;; to consider a category mapping for these.
|
||||||
(xtn-cat #f)
|
(if (not (and action
|
||||||
(entry #f))
|
(memv action qif-import:actions-implicit)))
|
||||||
(if (not xtn-is-acct)
|
;; iterate over the splits
|
||||||
(begin
|
(for-each
|
||||||
(set! xtn-cat (qif-split:category split))
|
(lambda (split)
|
||||||
(set! entry (hash-ref cat-hash xtn-cat))
|
(let ((xtn-is-acct (qif-split:category-is-account? split))
|
||||||
(if (not entry)
|
(xtn-cat #f)
|
||||||
(set! entry
|
(entry #f))
|
||||||
(qif-import:guess-acct
|
(if (not xtn-is-acct)
|
||||||
xtn-cat
|
(begin
|
||||||
(if (gnc-numeric-positive-p
|
(set! xtn-cat (qif-split:category split))
|
||||||
(qif-split:amount split))
|
(set! entry (hash-ref cat-hash xtn-cat))
|
||||||
(list GNC-INCOME-TYPE GNC-EXPENSE-TYPE)
|
;; NOTE: It would be more robust and efficient if the
|
||||||
(list GNC-EXPENSE-TYPE GNC-INCOME-TYPE))
|
;; three "make display" routines below were combined:
|
||||||
gnc-acct-info)))
|
;; make-account-display
|
||||||
(qif-map-entry:set-display?! entry #t)
|
;; make-category-display
|
||||||
(hash-set! cat-hash xtn-cat entry)))))
|
;; make-memo-display
|
||||||
(qif-xtn:splits xtn)))
|
;;
|
||||||
|
;; 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
|
||||||
|
(qif-import:guess-acct
|
||||||
|
xtn-cat
|
||||||
|
(if (gnc-numeric-positive-p
|
||||||
|
(qif-split:amount split))
|
||||||
|
(list GNC-INCOME-TYPE
|
||||||
|
GNC-EXPENSE-TYPE)
|
||||||
|
(list GNC-EXPENSE-TYPE
|
||||||
|
GNC-INCOME-TYPE))
|
||||||
|
gnc-acct-info)))
|
||||||
|
(if entry
|
||||||
|
(begin
|
||||||
|
(qif-map-entry:set-display?! entry #t)
|
||||||
|
(hash-set! cat-hash xtn-cat entry)))))))
|
||||||
|
(qif-xtn:splits xtn)))))
|
||||||
(qif-file:xtns qif-file)))
|
(qif-file:xtns qif-file)))
|
||||||
qif-files)
|
qif-files)
|
||||||
|
|
||||||
@ -478,49 +524,55 @@
|
|||||||
(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)))
|
||||||
(for-each
|
;; Many types of investment transactions implicitly use the
|
||||||
(lambda (split)
|
;; brokerage account or a known offshoot. There is no need
|
||||||
(let ((cat (qif-split:category split))
|
;; to consider a memo/payee mapping for these.
|
||||||
(memo (qif-split:memo split))
|
(if (not (and action
|
||||||
(key-string #f))
|
(memv action qif-import:actions-implicit)))
|
||||||
;; for each split: if there's a category, do nothing.
|
(for-each
|
||||||
;; if there's a payee, use that as the
|
(lambda (split)
|
||||||
;; key otherwise, use the split memo.
|
(let ((cat (qif-split:category split))
|
||||||
(cond ((and cat
|
(memo (qif-split:memo split))
|
||||||
(or (not (string? cat))
|
(key-string #f))
|
||||||
(not (string=? cat ""))))
|
;; for each split: if there's a category, do nothing.
|
||||||
(set! key-string #f))
|
;; if there's a payee, use that as the
|
||||||
((and payee (= (length splits) 1))
|
;; key otherwise, use the split memo.
|
||||||
(set! key-string payee))
|
(cond ((and cat
|
||||||
(memo
|
(or (not (string? cat))
|
||||||
(set! key-string memo)))
|
(not (string=? cat ""))))
|
||||||
|
(set! key-string #f))
|
||||||
|
((and payee (= (length splits) 1))
|
||||||
|
(set! key-string payee))
|
||||||
|
(memo
|
||||||
|
(set! key-string memo)))
|
||||||
|
|
||||||
(if key-string
|
(if key-string
|
||||||
(let ((entry (hash-ref memo-hash key-string)))
|
(let ((entry (hash-ref memo-hash key-string)))
|
||||||
(if (not entry)
|
(if (not entry)
|
||||||
(begin
|
(begin
|
||||||
(set! entry (make-qif-map-entry))
|
(set! entry (make-qif-map-entry))
|
||||||
(qif-map-entry:set-qif-name! entry key-string)
|
(qif-map-entry:set-qif-name! entry key-string)
|
||||||
(qif-map-entry:set-gnc-name!
|
(qif-map-entry:set-gnc-name!
|
||||||
entry (default-unspec-acct))
|
entry (default-unspec-acct))
|
||||||
(qif-map-entry:set-allowed-types!
|
(qif-map-entry:set-allowed-types!
|
||||||
entry
|
entry
|
||||||
(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 GNC-EXPENSE-TYPE
|
||||||
GNC-BANK-TYPE GNC-CCARD-TYPE
|
GNC-BANK-TYPE GNC-CCARD-TYPE
|
||||||
GNC-LIABILITY-TYPE GNC-ASSET-TYPE
|
GNC-LIABILITY-TYPE GNC-ASSET-TYPE
|
||||||
GNC-RECEIVABLE-TYPE GNC-PAYABLE-TYPE
|
GNC-RECEIVABLE-TYPE GNC-PAYABLE-TYPE
|
||||||
GNC-STOCK-TYPE GNC-MUTUAL-TYPE)
|
GNC-STOCK-TYPE GNC-MUTUAL-TYPE)
|
||||||
(list GNC-EXPENSE-TYPE GNC-INCOME-TYPE
|
(list GNC-EXPENSE-TYPE GNC-INCOME-TYPE
|
||||||
GNC-BANK-TYPE GNC-CCARD-TYPE
|
GNC-BANK-TYPE GNC-CCARD-TYPE
|
||||||
GNC-LIABILITY-TYPE GNC-ASSET-TYPE
|
GNC-LIABILITY-TYPE GNC-ASSET-TYPE
|
||||||
GNC-RECEIVABLE-TYPE GNC-PAYABLE-TYPE
|
GNC-RECEIVABLE-TYPE GNC-PAYABLE-TYPE
|
||||||
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)
|
||||||
|
|
||||||
@ -683,7 +735,7 @@
|
|||||||
(hash-fold
|
(hash-fold
|
||||||
(lambda (qif-name map-entry p)
|
(lambda (qif-name map-entry p)
|
||||||
(let ((security-name (qif-import:get-account-name qif-name)))
|
(let ((security-name (qif-import:get-account-name qif-name)))
|
||||||
;; Is this account going to be imported, is it security-denominated,
|
;; Is this account going to be imported, is it security-denominated,
|
||||||
;; and is the security not already in the security hash table?
|
;; and is the security not already in the security hash table?
|
||||||
(if (and
|
(if (and
|
||||||
security-name
|
security-name
|
||||||
|
Loading…
Reference in New Issue
Block a user