From d14b51457193c2424f4694399ca9fdab91ad9f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoit=20Gr=C3=A9goire?= Date: Mon, 10 Feb 2003 18:59:17 +0000 Subject: [PATCH] =?UTF-8?q?2003-02-10=20=20Benoit=20Gr=EF=BF=BDgoire=20=20?= =?UTF-8?q??= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/import-export/import-backend.c,h: * src/import-export/import-main-matcher.c: Apply most of cmorgan's patch for iterative destination account matching. Optionally restricting to the transactions after the one being edited still need's to be implemented. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7969 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 5 +++ src/import-export/import-backend.c | 60 ++++++++++++++++++++++--- src/import-export/import-backend.h | 5 +++ src/import-export/import-main-matcher.c | 26 +++++++++++ 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b181c36ec7..84c0b8ac25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-02-10 Benoit Grégoire + + * src/import-export/import-backend.c,h: + * src/import-export/import-main-matcher.c: Apply most of cmorgan's patch for iterative destination account matching. Optionally restricting to the transactions after the one being edited still need's to be implemented. + 2003-02-10 Derek Atkins * po/POTFILES.in: fox for the search-param.c move diff --git a/src/import-export/import-backend.c b/src/import-export/import-backend.c index 7d41d87ab3..51e0c365b5 100644 --- a/src/import-export/import-backend.c +++ b/src/import-export/import-backend.c @@ -63,6 +63,16 @@ static const int MATCH_DATE_NOT_THRESHOLD = 21; performance of the matcher. */ static const int SHOW_TRANSACTIONS_WITH_UNIQUE_ID = TRUE; /* DISABLE once account transfer bug is fixed! */ +/********************************************************************\ + * Forward declared prototypes * +\********************************************************************/ + +static void +matchmap_store_destination (GncImportMatchMap *matchmap, + GNCImportTransInfo *trans_info, + gboolean use_match); + + /********************************************************************\ * Structures passed between the functions * \********************************************************************/ @@ -186,6 +196,9 @@ void gnc_import_TransInfo_set_destacc (GNCImportTransInfo *info, g_assert (info); info->dest_acc = acc; info->dest_acc_selected_manually = selected_manually; + + /* Store the mapping to the other account in the MatchMap. */ + matchmap_store_destination (NULL, info, FALSE); } gboolean @@ -326,6 +339,9 @@ GdkPixmap* gen_probability_pixmap(gint score_original, GNCImportSettings *settin /*-************************************************************************ * MatchMap- related functions (storing and retrieving) */ + +/* searches using the GNCImportTransInfo through all existing transactions */ +/* if there is an exact match of the description and memo */ static Account * matchmap_find_destination (GncImportMatchMap *matchmap, GNCImportTransInfo *info) @@ -357,7 +373,7 @@ matchmap_find_destination (GncImportMatchMap *matchmap, 'use_match' is true, the destination account of the selected matching/duplicate transaction is used; otherwise, the stored destination_acc pointer is used. */ -static void +static void matchmap_store_destination (GncImportMatchMap *matchmap, GNCImportTransInfo *trans_info, gboolean use_match) @@ -514,7 +530,7 @@ static void split_find_match (GNCImportTransInfo * trans_info, xaccSplitGetMemo(split)) ==0)) { - /* An exact match of description gives a +2 */ + /* An exact match of memo gives a +2 */ prob = prob+2; /* DEBUG("heuristics: probability + 2 (memo)"); */ } @@ -671,9 +687,6 @@ gnc_import_process_trans_clist (GtkCList *clist, xaccTransGetCurrency (gnc_import_TransInfo_get_trans (trans_info))); xaccSplitSetMemo (split, _("Auto-Balance split")); - - /* Store the mapping to the other account in the MatchMap. */ - matchmap_store_destination (matchmap, trans_info, FALSE); } xaccSplitSetReconcile(gnc_import_TransInfo_get_fsplit (trans_info), CREC); @@ -896,4 +909,41 @@ gnc_import_TransInfo_init_matches (GNCImportTransInfo *trans_info, trans_info->previous_action=trans_info->action; } + +/* Try to automatch a transaction to a destination account if the */ +/* transaction hasn't already been manually assigned to another account */ +gboolean +gnc_import_TransInfo_refresh_destacc (GNCImportTransInfo *transaction_info, + GncImportMatchMap *matchmap) +{ + Transaction *transaction; + g_assert(transaction_info); + + Account *orig_destacc = gnc_import_TransInfo_get_destacc(transaction_info); + Account *new_destacc = NULL; + + /* if we haven't manually selected a destination account for this transaction */ + if(gnc_import_TransInfo_get_destacc_selected_manually(transaction_info) == FALSE) + { + /* Try to find a previous selected destination account string match for the ADD action */ + new_destacc = matchmap_find_destination(matchmap, transaction_info); + gnc_import_TransInfo_set_destacc(transaction_info, new_destacc, FALSE); + } else + { + new_destacc = orig_destacc; + } + + transaction = gnc_import_TransInfo_get_trans(transaction_info); + + /* account has changed */ + if(new_destacc != orig_destacc) + { + return TRUE; + } else /* account is the same */ + { + return FALSE; + } +} + + /** @} */ diff --git a/src/import-export/import-backend.h b/src/import-export/import-backend.h index e0ce5db352..f27e5ddb9e 100644 --- a/src/import-export/import-backend.h +++ b/src/import-export/import-backend.h @@ -216,6 +216,11 @@ gnc_import_TransInfo_set_destacc (GNCImportTransInfo *info, Account *acc, gboolean selected_manually); +/** Try to automatch a given transaction to a destination account */ +gboolean +gnc_import_TransInfo_refresh_destacc (GNCImportTransInfo *transaction_info, + GncImportMatchMap *matchmap); + /** Returns if the currently selected destination account for auto-matching was selected by the user. */ gboolean gnc_import_TransInfo_get_destacc_selected_manually (const GNCImportTransInfo *info); diff --git a/src/import-export/import-main-matcher.c b/src/import-export/import-main-matcher.c index 3bf9d8b974..576265caad 100644 --- a/src/import-export/import-main-matcher.c +++ b/src/import-export/import-main-matcher.c @@ -68,6 +68,11 @@ struct _main_matcher_info #define DOWNLOADED_CLIST_ACTION_INFO 8 static short module = MOD_IMPORT; +/* Local prototypes */ +static void automatch_clist_transactions(GNCImportMainMatcher *info, GtkCList *clist); + + + static char * fleche_xpm[] = { "17 22 41 1", " c None", @@ -265,6 +270,9 @@ run_account_picker_dialog (GNCImportMainMatcher *info, gnc_import_TransInfo_set_destacc (trans_info, new_acc, TRUE); + + /* Iterate through the transactions in a given clist to auto match them */ + automatch_clist_transactions(info, (GtkCList*)info->clist); } } @@ -823,4 +831,22 @@ void gnc_gen_trans_list_add_trans(GNCImportMainMatcher *gui, Transaction *trans) return; }/* end gnc_import_add_trans() */ +/* Iterate through the rows of the clist and try to automatch each of them */ +static void automatch_clist_transactions(GNCImportMainMatcher *info, GtkCList *clist) +{ + int row; + GNCImportTransInfo *trans_info; + + for(row = 0; row < clist->rows; row++) + { + trans_info = gtk_clist_get_row_data(clist, row); + + /* returns TRUE if we changed this row, so update it */ + if(gnc_import_TransInfo_refresh_destacc(trans_info, NULL)) + { + refresh_clist_row(info, row, trans_info); + } + } +} + /** @} */