Skip to content

Commit 048dfa1

Browse files
committed
Bug 343711 - Splits to Imbalance-USD do not disappear when zero-valued.
To mitigate potential impact, the Imbalance split is only removed when the split transitions to zero value during the commit of the transaction and the split's memo and action have no value.
1 parent ea17983 commit 048dfa1

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

libgnucash/engine/Scrub.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,6 @@ add_balance_split (Transaction *trans, gnc_numeric imbalance,
594594
LEAVE("");
595595
return;
596596
}
597-
account = xaccSplitGetAccount(balance_split);
598-
599-
xaccTransBeginEdit (trans);
600597

601598
old_value = xaccSplitGetValue (balance_split);
602599

@@ -607,8 +604,25 @@ add_balance_split (Transaction *trans, gnc_numeric imbalance,
607604
gnc_commodity_get_fraction(currency),
608605
GNC_HOW_RND_ROUND_HALF_UP);
609606

610-
xaccSplitSetValue (balance_split, new_value);
607+
if (gnc_numeric_zero_p (new_value))
608+
{
609+
const char *p;
610+
p = xaccSplitGetMemo (balance_split);
611+
if (!p || !*p)
612+
{
613+
p = xaccSplitGetAction (balance_split);
614+
if (!p || !*p)
615+
{
616+
xaccSplitDestroy (balance_split);
617+
return;
618+
}
619+
}
620+
}
611621

622+
xaccTransBeginEdit (trans);
623+
xaccSplitSetValue (balance_split, new_value);
624+
625+
account = xaccSplitGetAccount(balance_split);
612626
commodity = xaccAccountGetCommodity (account);
613627
if (gnc_commodity_equiv (currency, commodity))
614628
{

libgnucash/engine/test/utest-Split.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ test_xaccSplitRollbackEdit (Fixture *fixture, gconstpointer pData)
667667
fixture->split->orig_parent = NULL;
668668

669669
xaccSplitRollbackEdit (fixture->split);
670-
test_signal_assert_hits (sig1, 1);
670+
test_signal_assert_hits (sig1, 2);
671671
test_signal_assert_hits (sig2, 0);
672672
test_signal_assert_hits (sig3, 0);
673673
g_assert_true (fixture->split->acc == NULL);
@@ -684,9 +684,9 @@ test_xaccSplitRollbackEdit (Fixture *fixture, gconstpointer pData)
684684
g_assert_true (fixture->split->acc == acc);
685685
g_assert_true (fixture->split->parent == txn1);
686686
g_assert_true (fixture->split->orig_parent == txn1);
687-
test_signal_assert_hits (sig1, 1);
687+
test_signal_assert_hits (sig1, 2);
688688
test_signal_assert_hits (sig2, 1);
689-
test_signal_assert_hits (sig3, 1);
689+
test_signal_assert_hits (sig3, 2);
690690
g_assert_true (fixture->split->parent == fixture->split->orig_parent);
691691
g_assert_true (fixture->split->parent == txn1);
692692

0 commit comments

Comments
 (0)