Add a flag to the account structure to defer balance computation

This commit is contained in:
jean
2020-07-21 13:39:26 -07:00
committed by jean
parent 1f592ce191
commit a9f79cf79c
9 changed files with 89 additions and 65 deletions

View File

@@ -1859,6 +1859,29 @@ gnc_account_set_balance_dirty (Account *acc)
priv->balance_dirty = TRUE;
}
void gnc_account_set_defer_bal_computation (Account *acc, gboolean defer)
{
AccountPrivate *priv;
g_return_if_fail (GNC_IS_ACCOUNT (acc));
if (qof_instance_get_destroying (acc))
return;
priv = GET_PRIVATE (acc);
priv->defer_bal_computation = defer;
}
gboolean gnc_account_get_defer_bal_computation (Account *acc)
{
AccountPrivate *priv;
if (!acc)
return false;
priv = GET_PRIVATE (acc);
return priv->defer_bal_computation;
}
/********************************************************************\
\********************************************************************/
@@ -2214,7 +2237,7 @@ xaccAccountRecomputeBalance (Account * acc)
priv = GET_PRIVATE(acc);
if (qof_instance_get_editlevel(acc) > 0) return;
if (!priv->balance_dirty) return;
if (!priv->balance_dirty || priv->defer_bal_computation) return;
if (qof_instance_get_destroying(acc)) return;
if (qof_book_shutting_down(qof_instance_get_book(acc))) return;

View File

@@ -360,7 +360,18 @@ void gnc_account_set_balance_dirty (Account *acc);
*
* @param acc Set the flag on this account. */
void gnc_account_set_sort_dirty (Account *acc);
/** Set the defer balance flag. If defer is true, the account balance
* is not automatically computed, which can save a lot of time if
* multiple operations have to be done on the same account. If
* defer is false, further operations on account will cause the
* balance to be recomputed as normal.
*
* @param acc Set the flag on this account.
*
* @param defer New value for the flag. */
void gnc_account_set_defer_bal_computation (Account *acc, gboolean defer);
/** Insert the given split from an account.
*
* @param acc The account to which the split should be added.
@@ -403,6 +414,8 @@ const char * xaccAccountGetNotes (const Account *account);
const char * xaccAccountGetLastNum (const Account *account);
/** Get the account's lot order policy */
GNCPolicy *gnc_account_get_policy (Account *account);
/** Get the account's flag for deferred balance computation */
gboolean gnc_account_get_defer_bal_computation (Account *acc);
/** The following recompute the partial balances (stored with the
* transaction) and the total balance, for this account

View File

@@ -126,6 +126,7 @@ typedef struct AccountPrivate
* in any way desired. Handy for specialty traversals of the
* account tree. */
short mark;
gboolean defer_bal_computation;
} AccountPrivate;
struct account_s

View File

@@ -46,6 +46,13 @@ xaccTransGetSplit (const Transaction *trans, int i)
return ((MockTransaction*)trans)->getSplit(i);
}
SplitList *
xaccTransGetSplitList (const Transaction *trans)
{
g_return_val_if_fail(GNC_IS_MOCK_TRANSACTION(trans), NULL);
return trans ? ((MockTransaction*)trans)->getSplitList() : NULL;
}
Split *
xaccTransFindSplitByAccount(const Transaction *trans, const Account *acc)
{

View File

@@ -52,6 +52,7 @@ public:
MOCK_METHOD0(beginEdit, void());
MOCK_METHOD0(commitEdit, void());
MOCK_METHOD1(getSplit, Split *(int));
MOCK_METHOD0(getSplitList, SplitList *());
MOCK_METHOD1(findSplitByAccount, Split *(const Account*));
MOCK_METHOD0(getDate, time64());
MOCK_METHOD1(setDatePostedSecsNormalized, void(time64));