gnucash maint: Bug 767772 - Associated file with transaction is lost when moving entry between accounts

Geert Janssens gjanssens at code.gnucash.org
Fri Dec 28 03:47:34 EST 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/2634f23f (commit)
	from  https://github.com/Gnucash/gnucash/commit/692e2266 (commit)



commit 2634f23f87838c4c057affb6cd133e1a68e47a0c
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Oct 31 12:05:34 2018 +0000

    Bug 767772 - Associated file with transaction is lost
    when moving entry between accounts
    
    When using the cut transaction option the 'associated file' value was
    not being pasted to the new transaction. Added scheme code to get this
    value and save it to new transaction when using 'cut/copy' and then
    'paste' operations. When using the duplicate option, a dialogue allows
    you to keep the copied association or not. It does not get copied for
    autocomplete.

diff --git a/gnucash/gnome-utils/dialog-dup-trans.c b/gnucash/gnome-utils/dialog-dup-trans.c
index 0b5692d..02af630 100644
--- a/gnucash/gnome-utils/dialog-dup-trans.c
+++ b/gnucash/gnome-utils/dialog-dup-trans.c
@@ -45,12 +45,14 @@ typedef struct
     GtkWidget * date_edit;
     GtkWidget * num_edit;
     GtkWidget * tnum_edit;
+    GtkWidget * assoc_edit;
 
     GtkWidget *duplicate_title_label; // GtkLabel
     GtkWidget *duplicate_table; // GtkTable
     GtkWidget *date_label; // GtkLabel
     GtkWidget *num_label; // GtkLabel
     GtkWidget *tnum_label; // GtkLabel
+    GtkWidget *assoc_label; //GtkLabel
 } DupTransDialog;
 
 /* Parses the string value and returns true if it is a
@@ -169,6 +171,11 @@ gnc_dup_trans_dialog_create (GtkWidget * parent, DupTransDialog *dt_dialog,
         else
             gtk_entry_set_text (GTK_ENTRY (tnum_spin), "");
     }
+    /* Transaction Association */
+    {
+        dt_dialog->assoc_label = GTK_WIDGET(gtk_builder_get_object (builder, "assoc_label"));
+        dt_dialog->assoc_edit = GTK_WIDGET(gtk_builder_get_object (builder, "assoc_check_button"));
+    }
 
     gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dt_dialog);
 
@@ -179,7 +186,8 @@ static gboolean
 gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title,
                                gboolean show_date, time64 *date_p,
                                GDate *gdate_p, const char *num, char **out_num,
-                               const char *tnum, char **out_tnum)
+                               const char *tnum, char **out_tnum,
+                               const char *tassoc, char **out_tassoc)
 {
     DupTransDialog *dt_dialog;
     GtkWidget *entry;
@@ -243,6 +251,17 @@ gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title,
         gtk_entry_set_activates_default(GTK_ENTRY(dt_dialog->tnum_edit), TRUE);
     }
 
+    if (tassoc)
+    {
+        gtk_widget_set_visible(dt_dialog->assoc_label, TRUE);
+        gtk_widget_set_visible(dt_dialog->assoc_edit, TRUE);
+    }
+    else
+    {
+        gtk_widget_set_visible(dt_dialog->assoc_label, FALSE);
+        gtk_widget_set_visible(dt_dialog->assoc_edit, FALSE);
+    }
+
     result = gtk_dialog_run (GTK_DIALOG (dt_dialog->dialog));
 
     if (result == GTK_RESPONSE_OK)
@@ -255,6 +274,11 @@ gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title,
             *out_num = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->num_edit)));
         if (tnum)
             *out_tnum = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->tnum_edit)));
+        if (tassoc)
+        {
+            if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dt_dialog->assoc_edit)))
+                *out_tassoc = g_strdup (tassoc);
+        }
         ok = TRUE;
     }
     else
@@ -269,10 +293,11 @@ gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title,
 gboolean
 gnc_dup_trans_dialog (GtkWidget * parent, const char* title, gboolean show_date,
                       time64 *date_p, const char *num, char **out_num,
-                      const char *tnum, char **out_tnum)
+                      const char *tnum, char **out_tnum,
+                      const char *tassoc, char **out_tassoc)
 {
     return gnc_dup_trans_dialog_internal(parent, title, show_date, date_p, NULL,
-                                         num, out_num, tnum, out_tnum);
+                                         num, out_num, tnum, out_tnum, tassoc, out_tassoc);
 }
 
 gboolean
@@ -284,7 +309,7 @@ gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,
 
     tmp_time = gdate_to_time64 (*gdate_p);
     return gnc_dup_trans_dialog_internal(parent, NULL, TRUE, &tmp_time, gdate_p,
-                                         num, out_num, NULL, NULL);
+                                         num, out_num, NULL, NULL, NULL, NULL);
 }
 
 gboolean
@@ -295,5 +320,5 @@ gnc_dup_date_dialog (GtkWidget * parent, const char* title, GDate *gdate_p)
 
     tmp_time = gdate_to_time64(*gdate_p);
     return gnc_dup_trans_dialog_internal(parent, title, TRUE, &tmp_time, gdate_p,
-                                         NULL, NULL, NULL, NULL);
+                                         NULL, NULL, NULL, NULL, NULL, NULL);
 }
diff --git a/gnucash/gnome-utils/dialog-dup-trans.h b/gnucash/gnome-utils/dialog-dup-trans.h
index ad3506a..a3fdb54 100644
--- a/gnucash/gnome-utils/dialog-dup-trans.h
+++ b/gnucash/gnome-utils/dialog-dup-trans.h
@@ -45,12 +45,15 @@
  *         out_num   - output num field, g_newed string             *
  *         tnum      - input tnum field, if used, else NULL         *
  *         out_tnum  - output tnum field, g_newed string            *
+ *         tassoc    - input association field, if used, else NULL  *
+ *         out_tnum  - output association field, g_newed string     *
  * Return: TRUE if user closes dialog with 'OK'                     *
 \********************************************************************/
 gboolean
 gnc_dup_trans_dialog (GtkWidget * parent, const char* title, gboolean show_date,
                       time64 *date_p, const char *num, char **out_num,
-                      const char *tnum, char **out_tnum);
+                      const char *tnum, char **out_tnum,
+                      const char *tassoc, char **out_tassoc);
 
 gboolean
 gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,
diff --git a/gnucash/gnome-utils/gnc-tree-control-split-reg.c b/gnucash/gnome-utils/gnc-tree-control-split-reg.c
index f366e82..a09f7b0 100644
--- a/gnucash/gnome-utils/gnc-tree-control-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-control-split-reg.c
@@ -1240,7 +1240,7 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
 
         /* We are on a split in an expanded transaction.
          * Just copy the split and add it to the transaction.
-         * However, if the split-action field is being used as the register 
+         * However, if the split-action field is being used as the register
          * number, and the action field is a number, request a new value or
          * cancel. Need to get next number and update account last num from
          * split account not register account, which may be the same or not */
@@ -1260,7 +1260,7 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
                     in_num = gnc_get_num_action (NULL, split);
 
                 if (!gnc_dup_trans_dialog (GTK_WIDGET (window), title, FALSE,
-                                           &date, in_num, &out_num, NULL, NULL))
+                                           &date, in_num, &out_num, NULL, NULL, NULL, NULL))
                 {
                     LEAVE("dup cancelled");
                     return FALSE;
@@ -1314,6 +1314,7 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
         const char *in_tnum = NULL;
         char *out_num;
         char *out_tnum;
+        char *out_tassoc = NULL;
         time64 date;
         gboolean use_autoreadonly = qof_book_uses_autoreadonly (gnc_get_current_book());
 
@@ -1335,7 +1336,8 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
                                         : NULL);
 
         if (!gnc_dup_trans_dialog (GTK_WIDGET (window), NULL, TRUE,
-                                   &date, in_num, &out_num, in_tnum, &out_tnum))
+                                   &date, in_num, &out_num, in_tnum, &out_tnum,
+                                   xaccTransGetAssociation (trans), &out_tassoc))
         {
             LEAVE("dup cancelled");
             return FALSE;
@@ -1380,6 +1382,12 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
          * because otherwise the ordering is not deterministic */
         xaccTransSetDateEnteredSecs(new_trans, gnc_time(NULL));
 
+        /* clear the associated entry if returned value NULL */
+        if (out_tassoc == NULL)
+            xaccTransSetAssociation (new_trans, "");
+        else
+            g_free (out_tassoc);
+
         /* set per book option */
         gnc_set_num_action (new_trans, NULL, out_num, out_tnum);
 
@@ -1942,7 +1950,7 @@ gnc_tree_control_split_reg_recn_test (GncTreeViewSplitReg *view, GtkTreePath *sp
 }
 
 
-/* Return the account for name given or create it */ 
+/* Return the account for name given or create it */
 Account *
 gnc_tree_control_split_reg_get_account_by_name (GncTreeViewSplitReg *view, const char *name)
 {
@@ -2163,6 +2171,9 @@ gnc_tree_control_auto_complete (GncTreeViewSplitReg *view, Transaction *trans,
         if (g_strcmp0 (text, new_text) == 0)
         {
             xaccTransCopyOnto (trans_from, trans);
+            /* if there is an association, lets clear it */
+            if (xaccTransGetAssociation (trans_from) != NULL)
+                xaccTransSetAssociation (trans, "");
             g_free (text);
             break;
         }
diff --git a/gnucash/gtkbuilder/gnc-plugin-page-register.glade b/gnucash/gtkbuilder/gnc-plugin-page-register.glade
index ba509bd..088ba6c 100644
--- a/gnucash/gtkbuilder/gnc-plugin-page-register.glade
+++ b/gnucash/gtkbuilder/gnc-plugin-page-register.glade
@@ -1085,6 +1085,47 @@ If 0, all previous days included</property>
                     <property name="top_attach">2</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkBox" id="assoc_hbox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">5</property>
+                    <child>
+                      <object class="GtkLabel" id="assoc_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">start</property>
+                        <property name="label" translatable="yes">Keep Associated Entry</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="assoc_check_button">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="halign">start</property>
+                        <property name="image_position">top</property>
+                        <property name="active">True</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">3</property>
+                    <property name="width">2</property>
+                  </packing>
+                </child>
               </object>
             </child>
           </object>
diff --git a/gnucash/register/ledger-core/split-register-control.c b/gnucash/register/ledger-core/split-register-control.c
index 129e051..57be98e 100644
--- a/gnucash/register/ledger-core/split-register-control.c
+++ b/gnucash/register/ledger-core/split-register-control.c
@@ -889,6 +889,9 @@ gnc_split_register_auto_completion (SplitRegister *reg,
         g_assert(pending_trans == trans);
 
         gnc_copy_trans_onto_trans (auto_trans, trans, FALSE, FALSE);
+        /* if there is an association, lets clear it */
+        if (xaccTransGetAssociation (auto_trans) != NULL)
+            xaccTransSetAssociation (trans, "");
         blank_split = NULL;
 
         if (gnc_split_register_get_default_account (reg) != NULL)
diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c
index 575c621..f1cd663 100644
--- a/gnucash/register/ledger-core/split-register.c
+++ b/gnucash/register/ledger-core/split-register.c
@@ -510,8 +510,10 @@ gnc_split_register_duplicate_current (SplitRegister *reg)
                 in_num = xaccAccountGetLastNum (account);
             else
                 in_num = gnc_get_num_action (NULL, split);
+
             if (!gnc_dup_trans_dialog (gnc_split_register_get_parent (reg),
-                                   title, FALSE, &date, in_num, &out_num, NULL, NULL))
+                                   title, FALSE, &date, in_num, &out_num,
+                                   NULL, NULL, NULL, NULL))
             {
                 gnc_resume_gui_refresh ();
                 LEAVE("dup cancelled");
@@ -527,6 +529,7 @@ gnc_split_register_duplicate_current (SplitRegister *reg)
         gnc_copy_split_onto_split (split, new_split, FALSE);
         if (new_act_num) /* if new number supplied by user dialog */
             gnc_set_num_action (NULL, new_split, out_num, NULL);
+
         xaccTransCommitEdit (trans);
 
         if (new_act_num && gnc_strisnum (out_num))
@@ -567,6 +570,7 @@ gnc_split_register_duplicate_current (SplitRegister *reg)
         const char *in_tnum = NULL;
         char *out_num = NULL;
         char *out_tnum = NULL;
+        char *out_tassoc = NULL;
         time64 date;
         gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
 
@@ -587,7 +591,8 @@ gnc_split_register_duplicate_current (SplitRegister *reg)
         }
 
         if (!gnc_dup_trans_dialog (gnc_split_register_get_parent (reg), NULL,
-                                   TRUE, &date, in_num, &out_num, in_tnum, &out_tnum))
+                                   TRUE, &date, in_num, &out_num, in_tnum, &out_tnum,
+                                   xaccTransGetAssociation (trans), &out_tassoc))
         {
             gnc_resume_gui_refresh ();
             LEAVE("dup cancelled");
@@ -638,6 +643,12 @@ gnc_split_register_duplicate_current (SplitRegister *reg)
          * because otherwise the ordering is not deterministic */
         xaccTransSetDateEnteredSecs(new_trans, gnc_time(NULL));
 
+        /* clear the associated entry if returned value NULL */
+        if (out_tassoc == NULL)
+            xaccTransSetAssociation (new_trans, "");
+        else
+            g_free (out_tassoc);
+
         /* set per book option */
         gnc_set_num_action (new_trans, NULL, out_num, out_tnum);
         if (!reg->use_tran_num_for_num_field)
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index 866fc1f..1466834 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -757,6 +757,7 @@ xaccTransCopyFromClipBoard(const Transaction *from_trans, Transaction *to_trans,
         xaccTransSetNum(to_trans, xaccTransGetNum(from_trans));
 
     xaccTransSetNotes(to_trans, xaccTransGetNotes(from_trans));
+    xaccTransSetAssociation(to_trans, xaccTransGetAssociation (from_trans));
     if(!no_date)
     {
         xaccTransSetDatePostedSecs(to_trans, xaccTransRetDatePosted (from_trans));
diff --git a/libgnucash/engine/engine-interface.scm b/libgnucash/engine/engine-interface.scm
index a1217ef..34a1768 100644
--- a/libgnucash/engine/engine-interface.scm
+++ b/libgnucash/engine/engine-interface.scm
@@ -136,7 +136,7 @@
   (make-record-type
    "gnc:transaction-structure"
    '(transaction-guid currency date-entered date-posted
-                      num description notes split-scms)))
+                      num description notes association split-scms)))
 
 ;; constructor
 (define gnc:make-transaction-scm
@@ -168,6 +168,9 @@
 (define gnc:transaction-scm-get-notes
   (record-accessor gnc:transaction-structure 'notes))
 
+(define gnc:transaction-scm-get-association
+  (record-accessor gnc:transaction-structure 'association))
+
 (define gnc:transaction-scm-get-split-scms
   (record-accessor gnc:transaction-structure 'split-scms))
 
@@ -206,6 +209,9 @@
 (define gnc:transaction-scm-set-notes
   (record-modifier gnc:transaction-structure 'notes))
 
+(define gnc:transaction-scm-set-association
+  (record-modifier gnc:transaction-structure 'association))
+
 (define gnc:transaction-scm-set-split-scms
   (record-modifier gnc:transaction-structure 'split-scms))
 
@@ -235,6 +241,7 @@
        #f)
    (xaccTransGetDescription trans)
    (xaccTransGetNotes trans)
+   (xaccTransGetAssociation trans)
    (trans-splits 0)))
 
 ;; Copy a scheme representation of a transaction onto a C transaction.
@@ -254,11 +261,13 @@
               (description (gnc:transaction-scm-get-description trans-scm))
               (num         (gnc:transaction-scm-get-num trans-scm))
               (notes       (gnc:transaction-scm-get-notes trans-scm))
+              (association (gnc:transaction-scm-get-association trans-scm))
               (date-posted (gnc:transaction-scm-get-date-posted trans-scm)))
           (if currency    (xaccTransSetCurrency trans currency))
           (if description (xaccTransSetDescription trans description))
           (if num         (xaccTransSetNum trans num))
           (if notes       (xaccTransSetNotes trans notes))
+          (if association (xaccTransSetAssociation trans association))
           (if date-posted (xaccTransSetDatePostedSecs trans date-posted)))
 
         ;; strip off the old splits



Summary of changes:
 gnucash/gnome-utils/dialog-dup-trans.c             | 35 +++++++++++++++---
 gnucash/gnome-utils/dialog-dup-trans.h             |  5 ++-
 gnucash/gnome-utils/gnc-tree-control-split-reg.c   | 19 +++++++---
 gnucash/gtkbuilder/gnc-plugin-page-register.glade  | 41 ++++++++++++++++++++++
 .../register/ledger-core/split-register-control.c  |  3 ++
 gnucash/register/ledger-core/split-register.c      | 15 ++++++--
 libgnucash/engine/Transaction.c                    |  1 +
 libgnucash/engine/engine-interface.scm             | 11 +++++-
 8 files changed, 117 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list