2003-02-10 Benoit Gr�goire <bock@step.polymtl.ca>

* 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
This commit is contained in:
Benoit Grégoire 2003-02-10 18:59:17 +00:00
parent 8811d1c8c2
commit d14b514571
4 changed files with 91 additions and 5 deletions

View File

@ -1,3 +1,8 @@
2003-02-10 Benoit Grégoire <bock@step.polymtl.ca>
* 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 <derek@ihtfp.com>
* po/POTFILES.in: fox for the search-param.c move

View File

@ -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)
@ -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;
}
}
/** @} */

View File

@ -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);

View File

@ -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);
}
}
}
/** @} */