gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Wed May 4 20:25:22 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/674b49bd (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3dd179c6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/fccd0742 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e6eb0f32 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3f6962cf (commit)
	from  https://github.com/Gnucash/gnucash/commit/f292ed66 (commit)



commit 674b49bd8dea735aa160adc4ff483977e019c165
Merge: f292ed66a 3dd179c61
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 5 08:23:31 2022 +0800

    Merge branch 'maint-stock-assistant' into maint #1328
    
    - add support for warnings in stock transaction assistant
    
    - warn if new transaction date is earlier than latest stock account
    transaction date
    
    - reorder pages - input date prior to input stock activity type,
    because the latter depends on the former.


commit 3dd179c611c110e7b91842f83f737f26bd6d0942
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed May 4 09:24:39 2022 +0800

    [assistant-stock-transaction] use std::optional

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 220309079..75de287ee 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -28,6 +28,7 @@
 #include <string>
 #include <numeric>
 #include <algorithm>
+#include <optional>
 
 extern "C" {
 #include "Transaction.h"
@@ -428,7 +429,7 @@ typedef struct
     GtkWidget * window;
     GtkWidget * assistant;
 
-    const TxnTypeVec * txn_types;
+    std::optional<TxnTypeVec> txn_types;
     Account   * acct;
     gnc_commodity * currency;
 
@@ -436,7 +437,7 @@ typedef struct
     GtkWidget * transaction_type_page;
     GtkWidget * transaction_type_combo;
     GtkWidget * transaction_type_explanation;
-    const TxnTypeInfo * txn_type;
+    std::optional<TxnTypeInfo> txn_type;
 
     // transaction details page
     GtkWidget * transaction_details_page;
@@ -506,7 +507,10 @@ refresh_page_transaction_type (GtkWidget *widget, gpointer user_data)
     if (type_idx < 0)           // combo isn't initialized yet.
         return;
 
-    info->txn_type = &(info->txn_types->at (type_idx));
+    if (!info->txn_types)
+        return;
+
+    info->txn_type = info->txn_types->at (type_idx);
 
     gtk_label_set_text (GTK_LABEL (info->transaction_type_explanation),
                         _(info->txn_type->explanation));
@@ -823,9 +827,9 @@ stock_assistant_prepare (GtkAssistant  *assistant, GtkWidget *page,
         time64 date;
         date = gnc_date_edit_get_date_end (GNC_DATE_EDIT (info->date_edit));
         balance = xaccAccountGetBalanceAsOfDate (info->acct, date);
-        info->txn_types = gnc_numeric_zero_p (balance) ? &starting_types
-            : gnc_numeric_positive_p (balance) ? &long_types
-            : &short_types;
+        info->txn_types = gnc_numeric_zero_p (balance) ? starting_types
+            : gnc_numeric_positive_p (balance) ? long_types
+            : short_types;
         gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (info->transaction_type_combo));
         for (auto& it : *(info->txn_types))
             gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (info->transaction_type_combo),

commit fccd07424d56c39a9f61e8965fff5343fc1cd2f1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed May 4 09:18:36 2022 +0800

    [assistant-stock-transaction] reorder of Pages - date before type.
    
    Because the date may be in the past, and the stock balance at that
    date will dictate the available stock txn types available for
    creation.
    
    The available stock txn types is thus dependent on the desired date,
    and must only be initialized when preparing the txn_type page.

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index d9cecf7f8..220309079 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -58,8 +58,8 @@ static const char* ASSISTANT_STOCK_TRANSACTION_CM_CLASS = "assistant-stock-trans
 enum assistant_pages
 {
     PAGE_INTRO = 0,
+    PAGE_TRANSACTION_DETAILS,
     PAGE_TRANSACTION_TYPE,
-    PAGE_TRANSATION_DETAILS,
     PAGE_STOCK_AMOUNT,
     PAGE_STOCK_VALUE,
     PAGE_CASH,
@@ -817,8 +817,15 @@ stock_assistant_prepare (GtkAssistant  *assistant, GtkWidget *page,
 
     switch (currentpage)
     {
-    case PAGE_TRANSACTION_TYPE:
+    case PAGE_TRANSACTION_TYPE:;
         // initialize transaction types.
+        gnc_numeric balance;
+        time64 date;
+        date = gnc_date_edit_get_date_end (GNC_DATE_EDIT (info->date_edit));
+        balance = xaccAccountGetBalanceAsOfDate (info->acct, date);
+        info->txn_types = gnc_numeric_zero_p (balance) ? &starting_types
+            : gnc_numeric_positive_p (balance) ? &long_types
+            : &short_types;
         gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (info->transaction_type_combo));
         for (auto& it : *(info->txn_types))
             gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (info->transaction_type_combo),
@@ -1143,11 +1150,6 @@ stock_assistant_create (StockTransactionInfo *info)
     // Set the name for this assistant so it can be easily manipulated with css
     gtk_widget_set_name (GTK_WIDGET(info->window), "gnc-id-assistant-stock-transaction");
 
-    auto balance = xaccAccountGetBalance (info->acct);
-    info->txn_types = gnc_numeric_zero_p (balance) ? &starting_types
-        : gnc_numeric_positive_p (balance) ? &long_types
-        : &short_types;
-
     info->currency = gnc_account_get_currency_or_parent (info->acct);
 
     /* Transaction Page Widgets */
diff --git a/gnucash/gtkbuilder/assistant-stock-transaction.glade b/gnucash/gtkbuilder/assistant-stock-transaction.glade
index 857f0d1b9..f011d2dcf 100644
--- a/gnucash/gtkbuilder/assistant-stock-transaction.glade
+++ b/gnucash/gtkbuilder/assistant-stock-transaction.glade
@@ -29,18 +29,18 @@
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="transaction_type_page">
+      <object class="GtkBox" id="transaction_details_page">
         <property name="visible">True</property>
         <property name="can-focus">False</property>
         <property name="margin-start">12</property>
         <property name="border-width">6</property>
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkLabel" id="transaction_type_page_label">
+          <object class="GtkLabel" id="transaction_details_label">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="margin-bottom">6</property>
-            <property name="label" translatable="yes">Select the type of stock activity that you wish to record. The available types depend on whether the current stock balance is positive, nil, or negative (i.e. when shorting stock). The type will determine the component splits.</property>
+            <property name="label" translatable="yes">Select the date and description for your records.</property>
             <property name="wrap">True</property>
           </object>
           <packing>
@@ -51,16 +51,16 @@
         </child>
         <child>
           <!-- n-columns=2 n-rows=2 -->
-          <object class="GtkGrid" id="transaction_type_table">
+          <object class="GtkGrid" id="transaction_details_table">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="row-spacing">3</property>
             <property name="column-spacing">6</property>
             <child>
-              <object class="GtkLabel" id="transaction_type_combo_label">
+              <object class="GtkLabel" id="transaction_date_label">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
-                <property name="label" translatable="yes">Type</property>
+                <property name="label" translatable="yes">Date</property>
               </object>
               <packing>
                 <property name="left-attach">0</property>
@@ -68,26 +68,20 @@
               </packing>
             </child>
             <child>
-              <object class="GtkComboBoxText" id="transaction_type_page_combobox">
+              <object class="GtkLabel" id="transaction_description_label">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
-                <items>
-                  <item>a1</item>
-                  <item>b2</item>
-                  <item>c3</item>
-                </items>
+                <property name="label" translatable="yes">Description</property>
               </object>
               <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">0</property>
+                <property name="left-attach">0</property>
+                <property name="top-attach">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="transaction_type_page_explanation">
+              <object class="GtkEntry" id="transaction_description_entry">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="label">label</property>
-                <property name="wrap">True</property>
+                <property name="can-focus">True</property>
               </object>
               <packing>
                 <property name="left-attach">1</property>
@@ -106,23 +100,23 @@
         </child>
       </object>
       <packing>
-        <property name="title" translatable="yes">Transaction Type</property>
+        <property name="title" translatable="yes">Transaction Details</property>
         <property name="complete">True</property>
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="transaction_details_page">
+      <object class="GtkBox" id="transaction_type_page">
         <property name="visible">True</property>
         <property name="can-focus">False</property>
         <property name="margin-start">12</property>
         <property name="border-width">6</property>
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkLabel" id="transaction_details_label">
+          <object class="GtkLabel" id="transaction_type_page_label">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="margin-bottom">6</property>
-            <property name="label" translatable="yes">Select the date and description for your records.</property>
+            <property name="label" translatable="yes">Select the type of stock activity that you wish to record. The available types depend on whether the current stock balance is positive, nil, or negative (i.e. when shorting stock). The type will determine the component splits.</property>
             <property name="wrap">True</property>
           </object>
           <packing>
@@ -133,16 +127,16 @@
         </child>
         <child>
           <!-- n-columns=2 n-rows=2 -->
-          <object class="GtkGrid" id="transaction_details_table">
+          <object class="GtkGrid" id="transaction_type_table">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="row-spacing">3</property>
             <property name="column-spacing">6</property>
             <child>
-              <object class="GtkLabel" id="transaction_date_label">
+              <object class="GtkLabel" id="transaction_type_combo_label">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
-                <property name="label" translatable="yes">Date</property>
+                <property name="label" translatable="yes">Type</property>
               </object>
               <packing>
                 <property name="left-attach">0</property>
@@ -150,20 +144,26 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="transaction_description_label">
+              <object class="GtkComboBoxText" id="transaction_type_page_combobox">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
-                <property name="label" translatable="yes">Description</property>
+                <items>
+                  <item>a1</item>
+                  <item>b2</item>
+                  <item>c3</item>
+                </items>
               </object>
               <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">1</property>
+                <property name="left-attach">1</property>
+                <property name="top-attach">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="transaction_description_entry">
+              <object class="GtkLabel" id="transaction_type_page_explanation">
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
+                <property name="can-focus">False</property>
+                <property name="label">label</property>
+                <property name="wrap">True</property>
               </object>
               <packing>
                 <property name="left-attach">1</property>
@@ -182,7 +182,7 @@
         </child>
       </object>
       <packing>
-        <property name="title" translatable="yes">Transaction Details</property>
+        <property name="title" translatable="yes">Transaction Type</property>
         <property name="complete">True</property>
       </packing>
     </child>

commit e6eb0f328cb1a0293ee23782dee63541a23043bb
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed May 4 20:02:17 2022 +0800

    [assistant-stock-transaction] warn if TxnDate < latest Stock Txn

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 31bb62dce..d9cecf7f8 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -694,6 +694,31 @@ refresh_page_finish (StockTransactionInfo *info)
     gnc_numeric credit = gnc_numeric_zero ();
     StringVec errors, warnings;
 
+    // check the stock transaction date. If there are existing stock
+    // transactions dated after the date specified, it is very likely
+    // 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_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);
+    }
+
     if (info->txn_type->stock_amount != FieldMask::DISABLED)
     {
         auto stock_amount = gnc_amount_edit_get_amount

commit 3f6962cfcaad9a292852b0d170759e6ac29a2881
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon May 2 22:48:16 2022 +0800

    [assistant-stock-transaction] refactor to allow warnings
    
    Adds support for warnings, which can still allow creating a stock
    transaction.

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 8b6b7b919..31bb62dce 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -692,7 +692,7 @@ refresh_page_finish (StockTransactionInfo *info)
 
     gnc_numeric debit = gnc_numeric_zero ();
     gnc_numeric credit = gnc_numeric_zero ();
-    StringVec errors;
+    StringVec errors, warnings;
 
     if (info->txn_type->stock_amount != FieldMask::DISABLED)
     {
@@ -763,23 +763,24 @@ refresh_page_finish (StockTransactionInfo *info)
         g_free (debit_str);
     }
 
-    if (errors.empty())
+    // generate final summary message. Collates a header, the errors
+    // and warnings. Then allow completion if errors is empty.
+    auto header = errors.empty() ?
+        N_("No errors found. Click Apply to create transaction.") :
+        N_("The following errors must be fixed:");
+    auto summary = std::string { _(header) };
+    auto summary_add = [&summary](auto a) { summary += "\n• "; summary += a; };
+    std::for_each (errors.begin(), errors.end(), summary_add);
+    if (!warnings.empty())
     {
-        auto success_msg = N_("No errors found. Click Apply to create transaction.");
-        gtk_assistant_set_page_complete (GTK_ASSISTANT (info->window),
-                                         info->finish_page, true);
-        gtk_label_set_text (GTK_LABEL (info->finish_summary), _(success_msg));
-    }
-    else
-    {
-        auto header_str = N_("The following errors must be fixed:");
-        auto header = std::string { _(header_str) };
-        auto fold = [](auto a, auto b) { return std::move(a) + '\n' + std::move(b); };
-        auto errmsg { std::accumulate (errors.begin(), errors.end(), header, fold) };
-        gtk_assistant_set_page_complete (GTK_ASSISTANT (info->window),
-                                         info->finish_page, false);
-        gtk_label_set_text (GTK_LABEL (info->finish_summary), errmsg.c_str());
+        auto warnings_header = N_ ("The following warnings exist:");
+        summary += "\n\n";
+        summary += _(warnings_header);
+        std::for_each (warnings.begin(), warnings.end(), summary_add);
     }
+    gtk_label_set_text (GTK_LABEL (info->finish_summary), summary.c_str());
+    gtk_assistant_set_page_complete (GTK_ASSISTANT (info->window),
+                                     info->finish_page, errors.empty());
 }
 
 void
diff --git a/gnucash/gtkbuilder/assistant-stock-transaction.glade b/gnucash/gtkbuilder/assistant-stock-transaction.glade
index 60f1defbf..857f0d1b9 100644
--- a/gnucash/gtkbuilder/assistant-stock-transaction.glade
+++ b/gnucash/gtkbuilder/assistant-stock-transaction.glade
@@ -896,6 +896,7 @@
           <object class="GtkScrolledWindow" id="finish_scrolled">
             <property name="visible">True</property>
             <property name="can-focus">True</property>
+            <property name="vscrollbar-policy">never</property>
             <child>
               <object class="GtkTreeView" id="transaction_view">
                 <property name="visible">True</property>
@@ -919,6 +920,7 @@
             <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="label">summary of errors</property>
+            <property name="wrap">True</property>
           </object>
           <packing>
             <property name="expand">False</property>



Summary of changes:
 gnucash/gnome/assistant-stock-transaction.cpp      | 84 +++++++++++++++-------
 .../gtkbuilder/assistant-stock-transaction.glade   | 66 ++++++++---------
 2 files changed, 92 insertions(+), 58 deletions(-)



More information about the gnucash-changes mailing list