From c00cacda16ffc7f5cd7a9d650a486cb292aad5e0 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 14 Mar 2022 09:14:53 +0800 Subject: [PATCH] [assistant-stock-transaction.cpp] more sanity checks - stock amount must be positive. i.e. a negative stock amount during a regular BUY means a SELL. user must choose appropriate txn_type. - don't require account if zero-amount is allowable. eg fees. --- gnucash/gnome/assistant-stock-transaction.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp index 3fbfc8aa93..636bcaed0c 100644 --- a/gnucash/gnome/assistant-stock-transaction.cpp +++ b/gnucash/gnome/assistant-stock-transaction.cpp @@ -659,6 +659,8 @@ check_page (GtkListStore *list, gnc_numeric& debit, gnc_numeric& credit, acctstr = ""; else if (acct) acctstr = xaccAccountGetName (acct); + else if ((splitfield & FieldMask::ALLOW_ZERO) && gnc_numeric_zero_p (amount)) + acctstr = ""; else { add_error (errors, N_("Account for %s is missing"), page); @@ -696,6 +698,8 @@ refresh_page_finish (StockTransactionInfo *info) { auto stock_amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT(info->stock_amount_edit)); + if (!gnc_numeric_positive_p (stock_amount)) + add_error_str (errors, N_("Stock amount must be positive")); if (info->txn_type->stock_amount & FieldMask::ENABLED_CREDIT) stock_amount = gnc_numeric_neg (stock_amount); auto new_bal = gnc_numeric_add_fixed (info->balance_at_date, stock_amount);