David Hampton's qif import patch.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3987 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-04-17 20:23:49 +00:00
parent 65c99a6608
commit b5e8d20903
6 changed files with 134 additions and 10 deletions

View File

@ -107,6 +107,7 @@ Hans de Graaff <hans@degraaff.org> XML patches
Bill Gribble <grib@billgribble.com> qif importation code, and much much more
Mitsuo Hamada <mhamada@redhat.com> messages Japanese translations
Otto Hammersmith <otto@bug.redhat.com> for RedHat RPM version
David Hampton <hampton@employees.org> qif import patch
Eric Hanchrow <offby1@blarg.net> updated currency documentation
Alexandru Harsanyi <haral@codec.ro> for core dumps, lockups, gtk work
John Hasler <john@dhh.gt.org> engine patch

View File

@ -554,6 +554,14 @@ Christiansen</glossterm>
<para>for RedHat RPM packaging</para>
</glossdef>
</glossentry>
<glossentry>
<glossterm><email>hampton@employees.org</email> David Hampton</glossterm>
<glossdef>
<para>qif import patch</para>
</glossdef>
</glossentry>
<glossentry>
<glossterm><email>offby1@blarg.net</email> Eric Hanchrow</glossterm>
<glossdef>

View File

@ -87,6 +87,7 @@ struct _qifimportwindow {
SCM gnc_acct_info;
SCM stock_hash;
SCM new_stocks;
SCM ticker_map;
SCM imported_account_group;
SCM match_transactions;
@ -139,6 +140,7 @@ gnc_ui_qif_import_druid_make(void) {
GtkObject * wobj;
SCM load_map_prefs;
SCM mapping_info;
SCM create_ticker_map;
int i;
char * pre_page_names[NUM_PRE_PAGES] = {
@ -173,6 +175,7 @@ gnc_ui_qif_import_druid_make(void) {
retval->memo_map_info = SCM_BOOL_F;
retval->stock_hash = SCM_BOOL_F;
retval->new_stocks = SCM_BOOL_F;
retval->ticker_map = SCM_BOOL_F;
retval->imported_account_group = SCM_BOOL_F;
retval->match_transactions = SCM_BOOL_F;
retval->selected_transaction = 0;
@ -230,6 +233,9 @@ gnc_ui_qif_import_druid_make(void) {
retval->cat_map_info = gh_list_ref(mapping_info, gh_int2scm(2));
retval->memo_map_info = gh_list_ref(mapping_info, gh_int2scm(3));
retval->stock_hash = gh_list_ref(mapping_info, gh_int2scm(4));
create_ticker_map = gh_eval_str("make-ticker-map");
retval->ticker_map = gh_call0(create_ticker_map);
scm_protect_object(retval->imported_files);
scm_protect_object(retval->selected_file);
@ -242,6 +248,7 @@ gnc_ui_qif_import_druid_make(void) {
scm_protect_object(retval->acct_map_info);
scm_protect_object(retval->stock_hash);
scm_protect_object(retval->new_stocks);
scm_protect_object(retval->ticker_map);
scm_protect_object(retval->imported_account_group);
scm_protect_object(retval->match_transactions);
@ -287,6 +294,7 @@ gnc_ui_qif_import_druid_destroy (QIFImportWindow * window) {
scm_unprotect_object(window->acct_map_info);
scm_unprotect_object(window->stock_hash);
scm_unprotect_object(window->new_stocks);
scm_unprotect_object(window->ticker_map);
scm_unprotect_object(window->imported_account_group);
scm_unprotect_object(window->match_transactions);
@ -560,8 +568,8 @@ gnc_ui_qif_import_load_file_next_cb(GnomeDruidPage * page,
scm_protect_object(wind->selected_file);
/* load the file */
load_return = gh_call2(qif_file_load, gh_car(imported_files),
scm_filename);
load_return = gh_call3(qif_file_load, gh_car(imported_files),
scm_filename, wind->ticker_map);
/* a list returned is (#f error-message) for an error,
* (#t error-message) for a warning, or just #f for an
@ -1325,8 +1333,8 @@ gnc_ui_qif_import_memo_next_cb(GnomeDruidPage * page,
/* if we need to look at stocks, do that, otherwise import
* xtns and go to the duplicates page */
scm_unprotect_object(wind->new_stocks);
wind->new_stocks = gh_call2(update_stock, wind->stock_hash,
wind->acct_map_info);
wind->new_stocks = gh_call3(update_stock, wind->stock_hash,
wind->ticker_map, wind->acct_map_info);
scm_protect_object(wind->new_stocks);
if(wind->new_stocks != SCM_BOOL_F) {
@ -1380,8 +1388,8 @@ gnc_ui_qif_import_currency_next_cb(GnomeDruidPage * page,
int show_matches;
scm_unprotect_object(wind->new_stocks);
wind->new_stocks = gh_call2(update_stock, wind->stock_hash,
wind->acct_map_info);
wind->new_stocks = gh_call3(update_stock, wind->stock_hash,
wind->ticker_map, wind->acct_map_info);
scm_protect_object(wind->new_stocks);
if(wind->new_stocks != SCM_BOOL_F) {

View File

@ -587,7 +587,7 @@
;; new stocks or #f if none.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:update-stock-hash stock-hash acct-hash)
(define (qif-import:update-stock-hash stock-hash ticker-map acct-hash)
(let ((names '()))
(hash-fold
(lambda (qif-name map-entry p)
@ -625,13 +625,15 @@
;; we know nothing about this security.. we need to
;; ask about it
(begin
(let ((ticker-symbol (qif-ticker-map:lookup-ticker ticker-map stock-name)))
(if (not ticker-symbol)
(set! ticker-symbol stock-name))
(set! names (cons stock-name names))
(hash-set!
stock-hash stock-name
(gnc:commodity-create stock-name
GNC_COMMODITY_NS_NYSE
stock-name
ticker-symbol
""
100000))))))
#f))

View File

@ -17,7 +17,7 @@
;; just store the fields "raw".
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-file:read-file self path)
(define (qif-file:read-file self path ticker-map)
(false-if-exception
(let* ((qstate-type #f)
(current-xtn #f)
@ -88,6 +88,8 @@
(set! current-xtn (make-qif-cat)))
((account)
(set! current-xtn (make-qif-acct)))
((type:security)
(set! current-xtn (make-qif-stock-symbol)))
((option:autoswitch)
(set! ignore-accounts #t))
((clear:autoswitch)
@ -322,6 +324,35 @@
(display "qif-file:read-file : unknown Cat slot ")
(display tag)
(display " .. continuing anyway") (newline))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Security transactions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
((type:security)
(case tag
;; N : stock name
((#\N)
(qif-stock-symbol:set-name! current-xtn value))
;; S : ticker symbol
((#\S)
(qif-stock-symbol:set-symbol! current-xtn value))
;; T : type
((#\T)
(qif-stock-symbol:set-type! current-xtn value))
;; end-of-record
((#\^)
(qif-ticker-map:add-ticker! ticker-map current-xtn)
(set! current-xtn (make-qif-stock-symbol)))
(else
(display "qif-file:read-file : unknown Security slot ")
(display tag)
(display " .. continuing anyway.")
(newline))))
;; trying to sneak one by, eh?
(else

View File

@ -578,3 +578,77 @@
(define qif-map-entry:set-display?!
(simple-obj-setter <qif-map-entry> 'display?))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; <qif-stock-symbol>
;; [N] stock name : string
;; [S] ticker symbol : string
;; [T] type : string
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define <qif-stock-symbol>
(make-simple-class
'qif-stock-symbol
'(name symbol type)))
(define qif-stock-symbol:name
(simple-obj-getter <qif-stock-symbol> 'name))
(define qif-stock-symbol:set-name!
(simple-obj-setter <qif-stock-symbol> 'name))
(define qif-stock-symbol:symbol
(simple-obj-getter <qif-stock-symbol> 'symbol))
(define qif-stock-symbol:set-symbol!
(simple-obj-setter <qif-stock-symbol> 'symbol))
(define qif-stock-symbol:type
(simple-obj-getter <qif-stock-symbol> 'type))
(define qif-stock-symbol:set-type!
(simple-obj-setter <qif-stock-symbol> 'type))
(define (qif-stock-symbol:print self)
(simple-obj-print self))
(define (make-qif-stock-symbol)
(make-simple-obj <qif-stock-symbol>))
(define <qif-ticker-map>
(make-simple-class
'qif-ticker-map
'(stocks)))
(define qif-ticker-map:ticker-map
(simple-obj-getter <qif-ticker-map> 'stocks))
(define qif-ticker-map:set-ticker-map!
(simple-obj-setter <qif-ticker-map> 'stocks))
(define (make-ticker-map)
(let ((self (make-simple-obj <qif-ticker-map>)))
(qif-ticker-map:set-ticker-map! self '())
self))
(define (qif-ticker-map:add-ticker! ticker-map stock-symbol)
(qif-ticker-map:set-ticker-map!
ticker-map
(cons stock-symbol (qif-ticker-map:ticker-map ticker-map))))
(define (qif-ticker-map:lookup-ticker ticker-map name)
(let ((retval #f))
(for-each
(lambda (symbol)
(if (string=? name (qif-stock-symbol:name symbol))
(begin
(set! retval (qif-stock-symbol:symbol symbol))
(if (string=? retval "")
(set! retval #f)))))
(qif-ticker-map:ticker-map ticker-map))
retval))