Skip to content

Commit

Permalink
Merge branch 'account-splits-vector' into stable #1917
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Apr 15, 2024
2 parents 6506e48 + 2b71219 commit 3d17368
Show file tree
Hide file tree
Showing 31 changed files with 265 additions and 343 deletions.
8 changes: 4 additions & 4 deletions gnucash/gnome-utils/dialog-account.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ gnc_account_opening_balance_button_update (AccountWindow *aw, gnc_commodity *com
{
Account *account = aw_get_account (aw);
Account *ob_account = gnc_account_lookup_by_opening_balance (gnc_book_get_root_account (aw->book), commodity);
gboolean has_splits = (xaccAccountGetSplitList (account) != NULL);
gboolean has_splits = (xaccAccountGetSplitsSize (account) != 0);

if (aw->type != ACCT_TYPE_EQUITY)
{
Expand Down Expand Up @@ -1614,7 +1614,7 @@ gnc_account_window_create (GtkWindow *parent, AccountWindow *aw)
gtk_box_pack_start (GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
gtk_widget_show (aw->commodity_edit);
// If the account has transactions, prevent changes by displaying a label and tooltip
if (xaccAccountGetSplitList (aw_get_account (aw)) != NULL)
if (xaccAccountGetSplitsSize (aw_get_account (aw)) != 0)
{
gtk_widget_set_tooltip_text (aw->commodity_edit, tt);
gtk_widget_set_sensitive (aw->commodity_edit, FALSE);
Expand Down Expand Up @@ -1714,7 +1714,7 @@ gnc_account_window_create (GtkWindow *parent, AccountWindow *aw)
// immutable if gnucash depends on details that would be lost/missing
// if changing from/to such a type. At the time of this writing the
// immutable types are AR, AP and trading types.
if (xaccAccountGetSplitList (aw_get_account (aw)) != NULL)
if (xaccAccountGetSplitsSize (aw_get_account (aw)) != 0)
{
GNCAccountType atype = xaccAccountGetType (aw_get_account (aw));
compat_types = xaccAccountTypesCompatibleWith (atype);
Expand Down Expand Up @@ -2128,7 +2128,7 @@ gnc_ui_edit_account_window (GtkWindow *parent, Account *account)
gnc_resume_gui_refresh ();

gtk_widget_show_all (aw->dialog);
if (xaccAccountGetSplitList (account) != NULL)
if (xaccAccountGetSplitsSize (account) != 0)
gtk_widget_hide (aw->opening_balance_page);

parent_acct = gnc_account_get_parent (account);
Expand Down
5 changes: 2 additions & 3 deletions gnucash/gnome-utils/dialog-transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions gnucash/gnome-utils/gnc-autoclear.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ gnc_autoclear_get_splits (Account *account, gnc_numeric toclear_value,
else
nc_list = g_list_prepend (nc_list, split);
}
g_list_free (acc_splits);

if (gnc_numeric_zero_p (toclear_value))
{
Expand Down
1 change: 1 addition & 0 deletions gnucash/gnome-utils/gnc-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ gnc_post_file_open (GtkWindow *parent, const char * filename, gboolean is_readon
GList *splits = xaccAccountGetSplitList (acc);
g_list_foreach (splits,
(GFunc)gnc_sx_scrub_split_numerics, NULL);
g_list_free (splits);
}
g_list_free (children);
}
Expand Down
10 changes: 5 additions & 5 deletions gnucash/gnome/assistant-stock-transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sstream>

#include "Account.h"
#include "Account.hpp"
#include "Transaction.h"
#include "engine-helpers.h"
#include "dialog-utils.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions gnucash/gnome/dialog-lot-viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ lv_show_splits_free (GNCLotViewer *lv)
/* display list */
gnc_split_viewer_fill(lv, lv->split_free_store, filtered_list);
g_list_free (filtered_list);
g_list_free (split_list);
}

/* ======================================================================== */
Expand Down
2 changes: 2 additions & 0 deletions gnucash/gnome/dialog-sx-editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ gnc_sxed_check_consistent (GncSxEditorDialog *sxed)
g_hash_table_foreach (txns, set_sums_to_zero, NULL);

splitCount += g_list_length (splitList);
g_list_free (splitList);

xaccAccountForEachTransaction (tmpl_acct, check_transaction_splits, &sd);

Expand Down Expand Up @@ -1510,6 +1511,7 @@ schedXact_editor_populate (GncSxEditorDialog *sxed)
splitReg = gnc_ledger_display_get_split_register (sxed->ledger);
gnc_split_register_load (splitReg, splitList, NULL);
} /* otherwise, use the existing stuff. */
g_list_free (splitList);
}

/* Update the example cal */
Expand Down
19 changes: 7 additions & 12 deletions gnucash/gnome/gnc-plugin-page-account-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 };

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions gnucash/gnome/test/gtest-assistant-stock-transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 13 additions & 17 deletions gnucash/gnome/window-reconcile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#endif
#include <gdk/gdkkeysyms.h>

#include "Account.hpp"
#include "Scrub.h"
#include "Scrub3.h"
#include "dialog-account.h"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 split = GNC_SPLIT(n->data);
time64 recn_date = xaccSplitGetDateReconciled (split);
gchar *datestr, *recnstr;
if ((xaccSplitGetReconcile (split) != YREC) ||
(recn_date <= statement_date))
continue;
auto find_split = [statement_date](const Split *split)
{ return (xaccSplitGetReconcile (split) == YREC &&
xaccSplitGetDateReconciled (split) > statement_date); };

datestr = qof_print_date (xaccTransGetDate (xaccSplitGetParent (split)));
recnstr = qof_print_date (recn_date);
if (auto split = gnc_account_find_split (account, find_split, true))
{
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 \
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -2305,6 +2300,7 @@ find_payment_account(Account *account)
}
}

g_list_free (list);
return rv;
}

Expand Down
5 changes: 3 additions & 2 deletions gnucash/import-export/import-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions gnucash/import-export/import-main-matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions gnucash/register/ledger-core/split-register-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ gnc_find_split_in_account_by_memo (Account *account, const char *memo,
rv = split;
}

g_list_free (splits);
return rv;
}

Expand Down
Loading

0 comments on commit 3d17368

Please sign in to comment.