[GNC] Bug found in Stock Assistant with negative capital gain
bugs at sr16.net
bugs at sr16.net
Tue Sep 15 20:11:35 EDT 2026
Hi all,
I found a bug in Gnucash 5.16 in the Stock Assistant.
When recording a stock sale with a capital loss using the Stock Transaction Assistant, entering the capital gain as a negative number (as per the instruction) can cause the assistant to incorrectly record the loss as a positive capital gain.
Steps to reproduce:
1. Right click on a stock account select Stock Assistant
2. Select Sell, enter any amounts for number of stock and stock value
3. Continue to the Capital Gain/Loss page and select an Income account for capital gains
4. Type a negative value normally, e.g. -101.54 then complete the assistant.
5. The capital gains Income account receives a credit of 101.54 rather than a debit of 101.54
Bug source:
Looking at https://code.gnucash.org/docs/STABLE/assistant-stock-transaction_8cpp_source.html
StockTransactionEntry::set_value()
toggles m_debit_side each time it receives a negative value:
if (gnc_numeric_negative_p (amount))
{
m_value = gnc_numeric_neg(amount);
m_debit_side = !m_debit_side;
}
GncAmountEdit connects value_changed_cb to the GTK "changed" signal, so set_value() is called repeatedly on every keystroke while a negative number is being typed.
Each valid negative intermediate value toggles m_debit_side again which means that sometimes the amount is then incorrectly entered as a positive instead of a negative.
Fix:
m_debit side should be set to true in the if statement above instead of being toggled.
Temp workaround:
Enter 101.54 as a positive value first, then move the cursor to the beginning and type the minus sign. With this method m_debit_side is toggled only once and the Stock Assistant creates the transaction correctly.
I don't have a Bugzilla account but if someone can create one for me, I could post the bug report there.
Regards,
Chris Howard
More information about the gnucash-user
mailing list