gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Fri May 6 08:17:30 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/2b198dbc (commit)
	 via  https://github.com/Gnucash/gnucash/commit/19803ba9 (commit)
	from  https://github.com/Gnucash/gnucash/commit/674b49bd (commit)



commit 2b198dbce44e763f56e776f0d39ed77351e1e5f1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 5 22:41:00 2022 +0800

    [assistant-stock-transaction] avoid resetting txn_types unnecessarily.
    
    UX improvement.
    
    Previously the txn_types dropdown list would be regenerated whenever
    the GtkAssistant reaches the page PAGE_TRANSACTION_TYPE. This means
    selecting "Sell", pressing "Next", then "Previous" would reset the
    type to "Buy".
    
    This commit will store the date at which the txn_types was set; it
    will avoid resetting txn_types unless the date is changed.

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 850cef50d..070c76274 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -430,6 +430,10 @@ typedef struct
     GtkWidget * assistant;
 
     std::optional<TxnTypeVec> txn_types;
+    // the following stores date at which the txn_types were set. If
+    // the GNCDateEdit date is modified, it will trigger recreation of
+    // the txn_types above.
+    std::optional<time64>     txn_types_date;
     Account   * acct;
     gnc_commodity * currency;
 
@@ -830,6 +834,9 @@ stock_assistant_prepare (GtkAssistant  *assistant, GtkWidget *page,
         gnc_numeric balance;
         time64 date;
         date = gnc_date_edit_get_date_end (GNC_DATE_EDIT (info->date_edit));
+        if (info->txn_types_date && (info->txn_types_date == date))
+            break;
+        info->txn_types_date = date;
         balance = xaccAccountGetBalanceAsOfDate (info->acct, date);
         info->txn_types = gnc_numeric_zero_p (balance) ? starting_types
             : gnc_numeric_positive_p (balance) ? long_types

commit 19803ba9d0f89543667fa1a1c6188205b9e93556
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri May 6 09:01:35 2022 +0800

    [assistant-stock-transsaction] skip checking txn_date for empty stock acct

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 75de287ee..850cef50d 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -703,24 +703,28 @@ refresh_page_finish (StockTransactionInfo *info)
     // the later stock transactions will be invalidated. warn the user
     // to review them.
     auto new_date = gnc_date_edit_get_date_end (GNC_DATE_EDIT (info->date_edit));
-    auto last_split = static_cast<const Split*> (g_list_last (xaccAccountGetSplitList (info->acct))->data);
-    auto last_split_date = xaccTransGetDate (xaccSplitGetParent (last_split));
-    if (new_date <= last_split_date)
+    auto last_split_node = g_list_last (xaccAccountGetSplitList (info->acct));
+    if (last_split_node)
     {
-        auto last_split_date_str = qof_print_date (last_split_date);
-        auto new_date_str = qof_print_date (new_date);
-        // Translators: the first %s is the new transaction date;
-        // the second %s is the current stock account's latest
-        // transaction date.
-        auto warn_txt =  g_strdup_printf (_("You will enter a transaction \
+        auto last_split = static_cast<const Split*> (last_split_node->data);
+        auto last_split_date = xaccTransGetDate (xaccSplitGetParent (last_split));
+        if (new_date <= last_split_date)
+        {
+            auto last_split_date_str = qof_print_date (last_split_date);
+            auto new_date_str = qof_print_date (new_date);
+            // Translators: the first %s is the new transaction date;
+            // the second %s is the current stock account's latest
+            // transaction date.
+            auto warn_txt =  g_strdup_printf (_("You will enter a transaction \
 with date %s which is earlier than the latest transaction in this account, \
 dated %s. Doing so may affect the cost basis, and therefore capital gains, \
 of transactions dated after the new entry. Please review all transactions \
 to ensure proper recording."), new_date_str, last_split_date_str);
-        warnings.push_back (warn_txt);
-        g_free (warn_txt);
-        g_free (new_date_str);
-        g_free (last_split_date_str);
+            warnings.push_back (warn_txt);
+            g_free (warn_txt);
+            g_free (new_date_str);
+            g_free (last_split_date_str);
+        }
     }
 
     if (info->txn_type->stock_amount != FieldMask::DISABLED)



Summary of changes:
 gnucash/gnome/assistant-stock-transaction.cpp | 37 +++++++++++++++++----------
 1 file changed, 24 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list