use xaccAccountGetSplits and gnc_account_find_split

This commit is contained in:
Christopher Lam 2024-04-14 10:35:04 +08:00
parent 3f7a5a8267
commit f70ee754fc
12 changed files with 51 additions and 89 deletions

View File

@ -44,6 +44,7 @@
#include "gnc-ui.h"
#include "Transaction.h"
#include "Account.h"
#include "Account.hpp"
#include "engine-helpers.h"
#include "QuickFill.h"
#include <gnc-commodity.h>
@ -472,10 +473,8 @@ gnc_xfer_dialog_reload_quickfill( XferDialog *xferData )
gnc_quickfill_destroy( xferData->qf );
xferData->qf = gnc_quickfill_new();
auto splitlist = xaccAccountGetSplitList( account );
for ( GList *node = splitlist; node; node = node->next )
for (auto split : xaccAccountGetSplits (account))
{
auto split = static_cast<Split *> (node->data);
auto trans = xaccSplitGetParent (split);
gnc_quickfill_insert( xferData->qf,
xaccTransGetDescription (trans), QUICKFILL_LIFO);

View File

@ -37,6 +37,7 @@
#include <sstream>
#include "Account.h"
#include "Account.hpp"
#include "Transaction.h"
#include "engine-helpers.h"
#include "dialog-utils.h"
@ -1262,9 +1263,8 @@ StockAssistantModel::set_txn_type (guint type_idx)
};
static void
check_txn_date(GList* last_split_node, time64 txn_date, Logger& logger)
check_txn_date(Split* last_split, time64 txn_date, Logger& logger)
{
auto last_split = static_cast<const Split *>(last_split_node->data);
auto last_split_date = xaccTransGetDate(xaccSplitGetParent(last_split));
if (txn_date <= last_split_date) {
auto last_split_date_str = qof_print_date(last_split_date);
@ -1301,9 +1301,9 @@ StockAssistantModel::generate_list_of_splits() {
// transactions dated after the date specified, it is very likely
// the later stock transactions will be invalidated. warn the user
// to review them.
auto last_split_node = g_list_last (xaccAccountGetSplitList (m_acct));
if (last_split_node)
check_txn_date(last_split_node, m_transaction_date, m_logger);
auto splits{xaccAccountGetSplits (m_acct)};
if (!splits.empty())
check_txn_date(splits.back(), m_transaction_date, m_logger);
if (m_stock_entry->enabled() || m_stock_entry->has_amount())
{

View File

@ -39,6 +39,7 @@
#include "gnc-plugin-page-account-tree.h"
#include "gnc-plugin-page-register.h"
#include "Account.hpp"
#include "Scrub.h"
#include "Scrub3.h"
#include "ScrubBusiness.h"
@ -1145,22 +1146,19 @@ static gpointer
delete_account_helper (Account * account, gpointer data)
{
auto helper_res = static_cast<delete_helper_t*>(data);
GList *splits;
auto splits{xaccAccountGetSplits (account)};
splits = xaccAccountGetSplitList (account);
if (splits)
if (!splits.empty())
{
helper_res->has_splits = TRUE;
while (splits)
for (auto s : splits)
{
auto s = GNC_SPLIT(splits->data);
Transaction *txn = xaccSplitGetParent (s);
if (xaccTransGetReadOnly (txn))
{
helper_res->has_ro_splits = TRUE;
break;
}
splits = splits->next;
}
}
@ -1383,7 +1381,6 @@ account_delete_dialog (Account *account, GtkWindow *parent, Adopters* adopt)
gchar *title = NULL;
GtkBuilder *builder = gtk_builder_new();
gchar *acct_name = gnc_account_get_full_name(account);
GList* splits = xaccAccountGetSplitList(account);
GList* filter = g_list_prepend(NULL, (gpointer)xaccAccountGetType(account));
if (!acct_name)
@ -1416,7 +1413,7 @@ account_delete_dialog (Account *account, GtkWindow *parent, Adopters* adopt)
account, FALSE);
// Does the selected account have splits
if (splits)
if (!xaccAccountGetSplits(account).empty())
{
delete_helper_t delete_res2 = { FALSE, FALSE };
@ -1537,8 +1534,7 @@ gnc_plugin_page_account_tree_cmd_delete_account (GSimpleAction *simple,
}
// If no transaction or children just delete it.
if (!(xaccAccountGetSplitList (account) != NULL ||
gnc_account_n_children (account)))
if (xaccAccountGetSplits (account).empty() && gnc_account_n_children (account) == 0)
{
do_delete_account (account, NULL, NULL, NULL);
return;
@ -1581,7 +1577,6 @@ confirm_delete_account (GSimpleAction *simple, GncPluginPageAccountTree *page,
delete_helper_t delete_res)
{
Account *account = gnc_plugin_page_account_tree_get_current_account (page);
GList* splits = xaccAccountGetSplitList(account);
GtkWidget* window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
gint response;
@ -1595,7 +1590,7 @@ confirm_delete_account (GSimpleAction *simple, GncPluginPageAccountTree *page,
acct_name);
g_free(acct_name);
if (splits)
if (!xaccAccountGetSplits (account).empty())
{
if (ta)
{

View File

@ -231,9 +231,8 @@ static void dump_acct (Account *acct)
std::cout << '\n' << std::setw(20) << std::right << xaccAccountGetName (acct)
<< " Bal=" << std::setw(10) << std::right << GncNumeric (xaccAccountGetBalance (acct))
<< std::endl;
for (auto n = xaccAccountGetSplitList (acct); n; n = n->next)
for (auto s : xaccAccountGetSplits (acct))
{
auto s = static_cast<Split*>(n->data);
bal += xaccSplitGetAmount (s);
std::cout << std::setw(20) << std::right << GncDateTime (xaccTransGetDate (xaccSplitGetParent (s))).format_iso8601()
<< " amt=" << std::setw(10) << std::right << GncNumeric (xaccSplitGetAmount (s))

View File

@ -37,6 +37,7 @@
#endif
#include <gdk/gdkkeysyms.h>
#include "Account.hpp"
#include "Scrub.h"
#include "Scrub3.h"
#include "dialog-account.h"
@ -1621,10 +1622,8 @@ recn_set_watches_one_account (gpointer data, gpointer user_data)
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
/* add a watch on each unreconciled or cleared split for the account */
GList *splits = xaccAccountGetSplitList (account);
for (GList *node = splits; node; node = node->next)
for (auto split : xaccAccountGetSplits (account))
{
auto split = GNC_SPLIT(node->data);
Transaction *trans;
char recn;
@ -1942,22 +1941,16 @@ recnWindowWithBalance (GtkWidget *parent, Account *account, gnc_numeric new_endi
GtkWidget *box = gtk_statusbar_get_message_area (bar);
GtkWidget *image = gtk_image_new_from_icon_name
("dialog-warning", GTK_ICON_SIZE_SMALL_TOOLBAR);
GList *splits = xaccAccountGetSplitList (account);
for (GList *n = splits; n; n = n->next)
auto find_split = [statement_date](const Split *split)
{ return (xaccSplitGetReconcile (split) == YREC &&
xaccSplitGetDateReconciled (split) > statement_date); };
if (auto split = gnc_account_find_split (account, find_split, true))
{
auto split = GNC_SPLIT(n->data);
time64 recn_date = xaccSplitGetDateReconciled (split);
gchar *datestr, *recnstr;
if ((xaccSplitGetReconcile (split) != YREC) ||
(recn_date <= statement_date))
continue;
datestr = qof_print_date (xaccTransGetDate (xaccSplitGetParent (split)));
recnstr = qof_print_date (recn_date);
auto datestr = qof_print_date (xaccTransGetDate (xaccSplitGetParent (split)));
auto recnstr = qof_print_date (xaccSplitGetDateReconciled (split));
PWARN ("split posting_date=%s, recn_date=%s", datestr, recnstr);
g_free (datestr);
g_free (recnstr);
gtk_statusbar_push (bar, context, _("WARNING! Account contains \
splits whose reconcile date is after statement date. Reconciliation may be \
@ -1970,7 +1963,9 @@ use Find Transactions to find them, unreconcile, and re-reconcile."));
gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX(box), image, 0);
break;
g_free (datestr);
g_free (recnstr);
}
}
@ -2305,6 +2300,7 @@ find_payment_account(Account *account)
}
}
g_list_free (list);
return rv;
}

View File

@ -38,6 +38,7 @@
#include "import-backend.h"
#include "import-utilities.h"
#include "Account.h"
#include "Account.hpp"
#include "Query.h"
#include "gnc-engine.h"
#include "engine-helpers.h"
@ -996,9 +997,9 @@ hash_account_online_ids (Account *account)
{
auto acct_hash = g_hash_table_new_full
(g_str_hash, g_str_equal, g_free, nullptr);
for (GList *n = xaccAccountGetSplitList (account) ; n; n = n->next)
for (auto split : xaccAccountGetSplits (account))
{
auto id = gnc_import_get_split_online_id (static_cast<Split *>(n->data));
auto id = gnc_import_get_split_online_id (split);
if (id && *id)
g_hash_table_insert (acct_hash, (void*) id, GINT_TO_POINTER (1));
}

View File

@ -44,6 +44,7 @@
#include "import-main-matcher.h"
#include "Account.hpp"
#include "dialog-transfer.h"
#include "dialog-utils.h"
#include "gnc-glib-utils.h"
@ -468,9 +469,8 @@ load_hash_tables (GNCImportMainMatcher *info)
}
for (GList *m = accounts_list; m; m = m->next)
{
for (GList *n = xaccAccountGetSplitList (static_cast<Account*>(m->data)); n; n = n->next)
for (auto s : xaccAccountGetSplits (static_cast<Account*>(m->data)))
{
auto s = static_cast<const Split*>(n->data);
const Transaction *t = xaccSplitGetParent (s);
const gchar *key = xaccTransGetDescription (t);

View File

@ -47,6 +47,7 @@
#include "Account.h"
#include "AccountP.hpp"
#include "Account.hpp"
#include "Scrub.h"
#include "Transaction.h"
#include "TransactionP.h"
@ -91,8 +92,8 @@ gnc_get_ongoing_scrub (void)
static void add_transactions (const Account *account, GHashTable **ht)
{
for (GList *m = xaccAccountGetSplitList (account); m; m = g_list_next (m))
g_hash_table_add (*ht, xaccSplitGetParent (GNC_SPLIT(m->data)));
for (auto s : xaccAccountGetSplits (account))
g_hash_table_add (*ht, xaccSplitGetParent (s));
}
static GList*
@ -226,12 +227,11 @@ xaccAccountTreeScrubSplits (Account *account)
void
xaccAccountScrubSplits (Account *account)
{
GList *node;
scrub_depth++;
for (node = xaccAccountGetSplitList (account); node; node = node->next)
for (auto s : xaccAccountGetSplits (account))
{
if (abort_now) break;
xaccSplitScrub (GNC_SPLIT(node->data));
xaccSplitScrub (s);
}
scrub_depth--;
}

View File

@ -37,6 +37,7 @@
#include "qof.h"
#include "Account.h"
#include "AccountP.hpp"
#include "Account.hpp"
#include "Transaction.h"
#include "TransactionP.h"
#include "Scrub2.h"
@ -57,19 +58,14 @@ static QofLogModule log_module = GNC_MOD_LOT;
void
xaccAccountAssignLots (Account *acc)
{
SplitList *splits, *node;
if (!acc) return;
ENTER ("acc=%s", xaccAccountGetName(acc));
xaccAccountBeginEdit (acc);
restart_loop:
splits = xaccAccountGetSplitList(acc);
for (node = splits; node; node = node->next)
for (auto split : xaccAccountGetSplits (acc))
{
Split * split = GNC_SPLIT(node->data);
/* If already in lot, then no-op */
if (split->lot) continue;

View File

@ -58,6 +58,7 @@ ToDo:
#include <glib.h>
#include <glib/gi18n.h>
#include "Account.hpp"
#include "AccountP.hpp"
#include "Scrub2.h"
#include "Scrub3.h"
@ -79,7 +80,6 @@ gboolean
xaccAccountHasTrades (const Account *acc)
{
gnc_commodity *acc_comm;
SplitList *splits, *node;
if (!acc) return FALSE;
@ -88,10 +88,8 @@ xaccAccountHasTrades (const Account *acc)
acc_comm = xaccAccountGetCommodity(acc);
splits = xaccAccountGetSplitList(acc);
for (node = splits; node; node = node->next)
for (auto s : xaccAccountGetSplits (acc))
{
Split *s = GNC_SPLIT(node->data);
Transaction *t = s->parent;
if (s->gains == GAINS_STATUS_GAINS) continue;
if (acc_comm != t->common_currency) return TRUE;

View File

@ -34,6 +34,7 @@
#include <glib.h>
#include "Account.h"
#include "Account.hpp"
#include "Transaction.h"
#include "TransactionP.h"
#include "cap-gains.h"
@ -100,38 +101,16 @@ DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
* hasn't been assigned to a lot. Return that split.
* Make use of the fact that the splits in an account are
* already in date order; so we don't have to sort. */
auto splits = xaccAccountGetSplitList (lot_account);
Split *rv = nullptr;
for (auto node = reverse ? g_list_last (splits) : splits; !rv && node;
node = reverse ? node->prev : node->next)
auto find_split = [open_time, common_currency, want_positive](const Split* split)
{
split = GNC_SPLIT(node->data);
if (split->lot)
continue;
return (!split->lot &&
xaccTransRetDatePosted (xaccSplitGetParent (split)) >= open_time &&
gnc_commodity_equiv (common_currency, split->parent->common_currency) &&
!gnc_numeric_zero_p (split->amount) &&
want_positive == gnc_numeric_positive_p (split->amount));
};
/* Skip it if it's too early */
if (xaccTransRetDatePosted (xaccSplitGetParent (split)) < open_time)
{
if (reverse)
/* Going backwards, no point in looking further */
break;
continue;
}
/* Allow equiv currencies */
if (!gnc_commodity_equiv (common_currency, split->parent->common_currency))
continue;
/* Disallow zero-amount splits in general. */
if (gnc_numeric_zero_p(split->amount))
continue;
if (want_positive == gnc_numeric_positive_p (split->amount))
rv = split;
}
return rv;
return gnc_account_find_split (lot_account, find_split, reverse);
}
/* ============================================================== */

View File

@ -1074,7 +1074,6 @@ make_random_changes_to_level (QofBook *book, Account *parent)
account = static_cast<Account*>(get_random_list_element (accounts));
splits = xaccAccountGetSplitList (account);
splits = g_list_copy (splits);
for (node = splits; node; node = node->next)
{