From 77e3d2d67477c63438e5705c4aa4efa2a0041ca5 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Mon, 21 Feb 2005 20:58:36 +0000 Subject: [PATCH] Revert the change in December about date matching threshold. 2005-02-21 Christian Stimming * src/import-export/import-backend.c, import-backend.h, import-main-matcher.h: Revert the change in December about date matching thresholds that broke some OFX import. Now, the hard limit days interval is set by the importing sub-module when creating the dialog. This way, HBCI and OFX can set their different requirements. (Note: QIF does not use this code at all.) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10909 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 9 +++++ src/import-export/hbci/gnc-hbci-gettrans.c | 2 +- src/import-export/import-backend.c | 28 ++++++++-------- src/import-export/import-backend.h | 32 +++++++++--------- src/import-export/import-main-matcher.c | 6 ++-- src/import-export/import-main-matcher.h | 38 +++++++++++++++------- src/import-export/import-settings.c | 15 ++++++++- src/import-export/import-settings.h | 27 +++++++++++++-- src/import-export/ofx/gnc-ofx-import.c | 2 +- 9 files changed, 110 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc3179c2b3..5c9c029e8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-02-21 Christian Stimming + + * src/import-export/import-backend.c, import-backend.h, + import-main-matcher.h: Revert the change in December about date + matching thresholds that broke some OFX import. Now, the hard + limit days interval is set by the importing sub-module when + creating the dialog. This way, HBCI and OFX can set their + different requirements. (Note: QIF does not use this code at all.) + 2005-02-20 Neil Williams * src/engine/qof_book_merge.c: Fix double free of the targetList entities that cause xaccGroupGetNumSubAccounts to generate a diff --git a/src/import-export/hbci/gnc-hbci-gettrans.c b/src/import-export/hbci/gnc-hbci-gettrans.c index fe8e46be5f..923e459056 100644 --- a/src/import-export/hbci/gnc-hbci-gettrans.c +++ b/src/import-export/hbci/gnc-hbci-gettrans.c @@ -206,7 +206,7 @@ gnc_hbci_gettrans_final(GtkWidget *parent, if (trans_list && (AB_Transaction_List2_GetSize(trans_list) > 0)) { struct trans_list_data data; GNCImportMainMatcher *importer_generic_gui = - gnc_gen_trans_list_new(NULL, NULL, TRUE); + gnc_gen_trans_list_new(NULL, NULL, TRUE, 14); data.importer_generic = importer_generic_gui; data.gnc_acc = gnc_acc; diff --git a/src/import-export/import-backend.c b/src/import-export/import-backend.c index f54f0987e3..590af91d02 100644 --- a/src/import-export/import-backend.c +++ b/src/import-export/import-backend.c @@ -616,11 +616,8 @@ static void split_find_match (GNCImportTransInfo * trans_info, { /* If a transaction's amount doesn't match within the threshold, it's very unlikely to be the same transaction - so we give it an extra -5 penality. Changed 2004-11-27: - The penalty is so high that we can forget about this - split anyway and skip the rest of the tests. */ - return; - /* prob = prob-5; */ + so we give it an extra -5 penality */ + prob = prob-5; /* DEBUG("heuristics: probability - 1 (amount)"); */ } @@ -648,12 +645,13 @@ static void split_find_match (GNCImportTransInfo * trans_info, else if (datediff_day > MATCH_DATE_NOT_THRESHOLD) { /* Extra penalty if that split lies awfully far away from - the given one. Changed 2004-11-27: The penalty is so high - that we can forget about this split anyway and skip the - rest of the tests. */ - return; - /* prob = prob-5; */ + the given one. */ + prob = prob-5; /*DEBUG("heuristics: probability - 5 (date)"); */ + /* Changed 2005-02-21: Revert the hard-limiting behaviour + back to the previous large penalty. (Changed 2004-11-27: + The penalty is so high that we can forget about this + split anyway and skip the rest of the tests.) */ } /* Check number heuristics */ @@ -768,7 +766,8 @@ static void split_find_match (GNCImportTransInfo * trans_info, transaction, and find all matching splits there. */ void gnc_import_find_split_matches(GNCImportTransInfo *trans_info, gint process_threshold, - double fuzzy_amount_difference) + double fuzzy_amount_difference, + gint match_date_hardlimit) { GList * list_element; Query *query = xaccMallocQuery(); @@ -790,8 +789,8 @@ void gnc_import_find_split_matches(GNCImportTransInfo *trans_info, xaccQueryAddSingleAccountMatch (query, importaccount, QOF_QUERY_AND); xaccQueryAddDateMatchTT (query, - TRUE, download_time - MATCH_DATE_NOT_THRESHOLD*86400/2, - TRUE, download_time + MATCH_DATE_NOT_THRESHOLD*86400/2, + TRUE, download_time - match_date_hardlimit*86400, + TRUE, download_time + match_date_hardlimit*86400, QOF_QUERY_AND); list_element = xaccQueryGetSplits (query); /* Sigh. Doesnt help too much. We still create and run one query @@ -1072,7 +1071,8 @@ gnc_import_TransInfo_init_matches (GNCImportTransInfo *trans_info, /* Find all split matches in originating account. */ gnc_import_find_split_matches(trans_info, gnc_import_Settings_get_display_threshold (settings), - gnc_import_Settings_get_fuzzy_amount (settings)); + gnc_import_Settings_get_fuzzy_amount (settings), + gnc_import_Settings_get_match_date_hardlimit (settings)); if (trans_info->match_list != NULL) { diff --git a/src/import-export/import-backend.h b/src/import-export/import-backend.h index f27e5ddb9e..ab3b2a7fcc 100644 --- a/src/import-export/import-backend.h +++ b/src/import-export/import-backend.h @@ -71,10 +71,21 @@ gboolean gnc_import_exists_online_id (Transaction *trans); * @param fuzzy_amount_difference For fuzzy amount matching, a certain * fuzzyness in the matching amount is allowed up to this value. May * be e.g. 3.00 dollars for ATM fees, or 0.0 if you only want to allow - * exact matches. */ + * exact matches. + * + * @param match_date_hardlimit The number of days that a matching + * split may differ from the given transaction before it is discarded + * immediately. In other words, any split that is more distant from + * the given transaction than this match_date_hardlimit days will be + * ignored altogether. For use cases without paper checks (e.g. HBCI), + * values like 14 (days) might be appropriate, whereas for use cases + * with paper checks (e.g. OFX, QIF), values like 42 (days) seem more + * appropriate. + */ void gnc_import_find_split_matches(GNCImportTransInfo *transaction_info, gint process_threshold, - double fuzzy_amount_difference); + double fuzzy_amount_difference, + gint match_date_hardlimit); /** Iterates through all splits of the originating account of * trans_info. Sorts the resulting list and sets the selected_match @@ -83,21 +94,8 @@ void gnc_import_find_split_matches(GNCImportTransInfo *transaction_info, * @param trans_info The TransInfo for which the matches should be * found, sorted, and selected. * - * @param clear_threshold If the heuristics of the best matching split - * is higher or equal this value, 'clear' is selected as default - * action. - * - * @param add_threshold If the heuristics of the best matching split - * is lesser or equal this value, 'add' is selected as default - * action. - * - * @paran process_threshold Each potential match whose heuristics are - * smaller than this value is totally ignored. - * - * @param fuzzy_amount_difference For fuzzy amount matching, a certain - * fuzzyness in the matching amount is allowed up to this value. May - * be e.g. 3.00 dollars for ATM fees, or 0.0 if you only want to allow - * exact matches. */ + * @param settings The structure that holds all the user preferences. + */ void gnc_import_TransInfo_init_matches (GNCImportTransInfo *trans_info, GNCImportSettings *settings); diff --git a/src/import-export/import-main-matcher.c b/src/import-export/import-main-matcher.c index 0a58ae760a..c18fa9c640 100644 --- a/src/import-export/import-main-matcher.c +++ b/src/import-export/import-main-matcher.c @@ -380,8 +380,9 @@ static void gnc_gen_trans_list_thaw (GNCImportMainMatcher *gui) } GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, - const gchar* heading, - gboolean all_from_same_account) + const gchar* heading, + gboolean all_from_same_account, + gint match_date_hardlimit) { GNCImportMainMatcher *info; GladeXML *xml; @@ -393,6 +394,7 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, /* Initialize user Settings. */ info->user_settings = gnc_import_Settings_new (); + gnc_import_Settings_set_match_date_hardlimit (info->user_settings, match_date_hardlimit); /* Initialize the GnomeDialog. */ xml = gnc_glade_xml_new ("generic-import.glade", "transaction_matcher"); diff --git a/src/import-export/import-main-matcher.h b/src/import-export/import-main-matcher.h index 49d0b3f458..79fa58f09d 100644 --- a/src/import-export/import-main-matcher.h +++ b/src/import-export/import-main-matcher.h @@ -33,25 +33,41 @@ typedef struct _main_matcher_info GNCImportMainMatcher; /** Create a new generic transaction dialog window and return it. - @param parent The parent GtkWidget. May be NULL. - @param heading The heading label in the Importer window. May be NULL. - @param all_from_same_account Set this to TRUE if ALL the transaction - that will be added with gnc_gen_trans_list_add_trans are from the same - source account. This will cause the account column to be hidden. + * + * @param parent The parent GtkWidget. May be NULL. + * + * @param heading The heading label in the Importer window. May be NULL. + * + * @param all_from_same_account Set this to TRUE if ALL the + * transaction that will be added with gnc_gen_trans_list_add_trans + * are from the same source account. This will cause the account + * column to be hidden. + * + * @param match_date_hardlimit The number of days that a matching + * split may differ from the given transaction before it is discarded + * immediately. In other words, any split that is more distant from + * the given transaction than this match_date_hardlimit days will be + * ignored altogether. For use cases without paper checks (e.g. HBCI), + * values like 14 (days) might be appropriate, whereas for use cases + * with paper checks (e.g. OFX, QIF), values like 42 (days) seem more + * appropriate. */ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, const gchar* heading, - gboolean all_from_same_account); + gboolean all_from_same_account, + gint match_date_hardlimit); /** Deletes the given object. */ void gnc_gen_trans_list_delete (GNCImportMainMatcher *info); /** Add a newly imported Transaction to the Transaction Importer. - @param gui The Transaction Importer to use. - @param trans The Transaction to add. The must contain at least - one split, and this split must have been associated with an account - Only the first split will be used for matching. The - transaction must NOT be commited. + * + * @param gui The Transaction Importer to use. + * + * @param trans The Transaction to add. The must contain at least one + * split, and this split must have been associated with an account + * Only the first split will be used for matching. The transaction + * must NOT be commited. */ void gnc_gen_trans_list_add_trans(GNCImportMainMatcher *gui, Transaction *trans); diff --git a/src/import-export/import-settings.c b/src/import-export/import-settings.c index 913cf26f9c..ea06a66dca 100644 --- a/src/import-export/import-settings.c +++ b/src/import-export/import-settings.c @@ -84,6 +84,7 @@ struct _genimportsettings { /** The allowed amount range for fuzzy amount matching, in the users default commodity.*/ double fuzzy_amount; + gint match_date_hardlimit; }; @@ -122,7 +123,8 @@ gnc_import_Settings_new (void) settings->fuzzy_amount = gnc_lookup_number_option(MATCHER_PREF_PAGE,"Commercial ATM fees threshold", DEFAULT_ATM_FEE_THRESHOLD); - + + settings->match_date_hardlimit = 42; /* 6 weeks */ return settings; } @@ -183,4 +185,15 @@ gint gnc_import_Settings_get_display_threshold (GNCImportSettings *settings) return settings->display_threshold; }; +void gnc_import_Settings_set_match_date_hardlimit (GNCImportSettings *s, gint m) +{ + g_assert(s); + s->match_date_hardlimit = m; +} +gint gnc_import_Settings_get_match_date_hardlimit (const GNCImportSettings *s) +{ + g_assert(s); + return s->match_date_hardlimit; +} + /**@}*/ diff --git a/src/import-export/import-settings.h b/src/import-export/import-settings.h index 723942f3c4..34f392fd49 100644 --- a/src/import-export/import-settings.h +++ b/src/import-export/import-settings.h @@ -36,8 +36,17 @@ typedef struct _genimportsettings GNCImportSettings; -/** Allocates a new GNCImportSettings object, and initialize it with the - appropriate user prefs. +/** Allocates a new GNCImportSettings object, and initialize it with + * the appropriate user prefs. + * + * @param match_date_hardlimit The number of days that a matching + * split may differ from the given transaction before it is discarded + * immediately. In other words, any split that is more distant from + * the given transaction than this match_date_hardlimit days will be + * ignored altogether. For use cases without paper checks (e.g. HBCI), + * values like 14 (days) might be appropriate, whereas for use cases + * with paper checks (e.g. OFX, QIF), values like 42 (days) seem more + * appropriate. */ GNCImportSettings * gnc_import_Settings_new (void); @@ -83,6 +92,20 @@ gint gnc_import_Settings_get_add_threshold (GNCImportSettings *settings); /** Return the selected threshold. */ gint gnc_import_Settings_get_display_threshold (GNCImportSettings *settings); + +/** @param match_date_hardlimit The number of days that a matching + * split may differ from the given transaction before it is discarded + * immediately. In other words, any split that is more distant from + * the given transaction than this match_date_hardlimit days will be + * ignored altogether. For use cases without paper checks (e.g. HBCI), + * values like 14 (days) might be appropriate, whereas for use cases + * with paper checks (e.g. OFX, QIF), values like 42 (days) seem more + * appropriate. + */ +void gnc_import_Settings_set_match_date_hardlimit (GNCImportSettings *settings, gint match_date_hardlimit); +/** Returns the hard-limiting number of days that a matching split may differ. */ +gint gnc_import_Settings_get_match_date_hardlimit (const GNCImportSettings *settings); + /**@}*/ /**@}*/ diff --git a/src/import-export/ofx/gnc-ofx-import.c b/src/import-export/ofx/gnc-ofx-import.c index a0c5d2ef8e..82bc90aa28 100644 --- a/src/import-export/ofx/gnc-ofx-import.c +++ b/src/import-export/ofx/gnc-ofx-import.c @@ -642,7 +642,7 @@ void gnc_file_ofx_import (void) DEBUG("Filename found: %s",selected_filename); /* Create the Generic transaction importer GUI. */ - gnc_ofx_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE); + gnc_ofx_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE, 42); /* Initialize libofx */