diff --git a/src/engine/Account.c b/src/engine/Account.c index 6db562a3ad..af07f2783b 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -1835,6 +1835,39 @@ xaccAccountGetLotList (Account *acc) return (acc->lots); } +LotList * +xaccAccountFindOpenLots (Account *acc, + gboolean (*match_func)(GNCLot *lot, + gpointer user_data), + gpointer user_data, GCompareFunc sort_func) +{ + GList *lot_list; + GList *retval = NULL; + + if (!acc) + return NULL; + + lot_list = xaccAccountGetLotList (acc); + for ( ; lot_list ; lot_list = lot_list->next ) { + GNCLot *lot = lot_list->data; + + /* If this lot is closed, then ignore it */ + if (gnc_lot_is_closed (lot)) + continue; + + if (match_func && !(match_func)(lot, user_data)) + continue; + + /* Ok, this is a valid lot. Add it to our list of lots */ + if (sort_func) + retval = g_list_insert_sorted (retval, lot, sort_func); + else + retval = g_list_prepend (retval, lot); + } + + return retval; +} + /********************************************************************\ \********************************************************************/ diff --git a/src/engine/Account.h b/src/engine/Account.h index 86f2a20ef9..c3d0d07ecd 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -312,6 +312,16 @@ gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account, time_t date); SplitList* xaccAccountGetSplitList (Account *account); LotList* xaccAccountGetLotList (Account *account); +/* Find a list of open lots that match the match_func. Sort according + * to sort_func. If match_func is NULL, then all open lots are returned. + * If sort_func is NULL, then the returned list has no particular order. + * The caller must free to returned list. + */ +LotList * xaccAccountFindOpenLots (Account *acc, + gboolean (*match_func)(GNCLot *lot, + gpointer user_data), + gpointer user_data, GCompareFunc sort_func); + gboolean xaccAccountGetTaxRelated (Account *account); void xaccAccountSetTaxRelated (Account *account, gboolean tax_related);