r22117 - gnucash/trunk/src - Take read-only setting of QofBook into account for the transaction deletion as well.

Christian Stimming cstim at code.gnucash.org
Sat Mar 24 18:34:44 EDT 2012


Author: cstim
Date: 2012-03-24 18:34:44 -0400 (Sat, 24 Mar 2012)
New Revision: 22117
Trac: http://svn.gnucash.org/trac/changeset/22117

Modified:
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/Transaction.h
   gnucash/trunk/src/gnome/gnc-split-reg.c
   gnucash/trunk/src/register/ledger-core/split-register-model.c
Log:
Take read-only setting of QofBook into account for the transaction deletion as well.

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2012-03-24 22:34:32 UTC (rev 22116)
+++ gnucash/trunk/src/engine/Transaction.c	2012-03-24 22:34:44 UTC (rev 22117)
@@ -1957,6 +1957,41 @@
                trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL;
 }
 
+gboolean xaccTransIsReadonlyByPostedDate(const Transaction *trans)
+{
+    GDate *threshold_date;
+    GDate trans_date;
+    const QofBook *book = xaccTransGetBook (trans);
+    gboolean result;
+    g_assert(trans);
+
+    if (!qof_book_uses_autofreeze(book))
+    {
+        return FALSE;
+    }
+
+    threshold_date = qof_book_get_autofreeze_gdate(book);
+    trans_date = xaccTransGetDatePostedGDate(trans);
+
+//    g_warning("there is auto-read-only with days=%d, trans_date_day=%d, threshold_date_day=%d",
+//              qof_book_get_num_days_autofreeze(book),
+//              g_date_get_day(&trans_date),
+//              g_date_get_day(threshold_date));
+
+    if (g_date_compare(&trans_date, threshold_date) < 0)
+    {
+        //g_warning("we are auto-read-only");
+        result = TRUE;
+    }
+    else
+    {
+        result = FALSE;
+    }
+    g_date_free(threshold_date);
+    return result;
+}
+
+
 gboolean
 xaccTransHasReconciledSplitsByAccount (const Transaction *trans,
                                        const Account *account)

Modified: gnucash/trunk/src/engine/Transaction.h
===================================================================
--- gnucash/trunk/src/engine/Transaction.h	2012-03-24 22:34:32 UTC (rev 22116)
+++ gnucash/trunk/src/engine/Transaction.h	2012-03-24 22:34:44 UTC (rev 22117)
@@ -321,12 +321,23 @@
 gboolean xaccTransStillHasSplit(const Transaction *trans, const Split *s);
 
 
-/** Set the transaction to be ReadOnly */
+/** Set the transaction to be ReadOnly by setting a non-NULL value as "reason".
+ *
+ * FIXME: If "reason" is NULL, this function does nothing, instead of removing the
+ * readonly flag; the actual removal is possible only through
+ * xaccTransClearReadOnly(). */
 void          xaccTransSetReadOnly (Transaction *trans, const char *reason);
 void	      xaccTransClearReadOnly (Transaction *trans);
-/** FIXME: document me */
+
+/** Returns a non-NULL value if this Transaction was marked as read-only with
+ * some specific "reason" text. */
 const char *  xaccTransGetReadOnly (const Transaction *trans);
 
+/** Returns TRUE if this Transaction is read-only because its posted-date is
+ * older than the "auto-readonly" threshold of this book. See
+ * qof_book_uses_autofreeze() and qof_book_get_autofreeze_gdate(). */
+gboolean xaccTransIsReadonlyByPostedDate(const Transaction *trans);
+
 /** Returns the number of splits in this transaction. */
 int           xaccTransCountSplits (const Transaction *trans);
 

Modified: gnucash/trunk/src/gnome/gnc-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.c	2012-03-24 22:34:32 UTC (rev 22116)
+++ gnucash/trunk/src/gnome/gnc-split-reg.c	2012-03-24 22:34:44 UTC (rev 22117)
@@ -897,7 +897,7 @@
 
 
 static gboolean
-xaccTransWarnReadOnly (const Transaction *trans)
+is_trans_readonly_and_warn (const Transaction *trans)
 {
     GtkWidget *dialog;
     const gchar *reason;
@@ -907,6 +907,21 @@
 
     if (!trans) return FALSE;
 
+    if (xaccTransIsReadonlyByPostedDate (trans))
+    {
+        dialog = gtk_message_dialog_new(NULL,
+                                        0,
+                                        GTK_MESSAGE_ERROR,
+                                        GTK_BUTTONS_OK,
+                                        "%s", title);
+        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+                "%s", _("The date of this transaction is older than the \"Read-Only Threshold\" set for this book.  "
+                        "This setting can be changed in File -> Properties -> Accounts."));
+        gtk_dialog_run(GTK_DIALOG(dialog));
+        gtk_widget_destroy(dialog);
+        return TRUE;
+    }
+
     reason = xaccTransGetReadOnly (trans);
     if (reason)
     {
@@ -944,7 +959,7 @@
     reg = gnc_ledger_display_get_split_register( gsr->ledger );
 
     trans = gnc_split_register_get_current_trans (reg);
-    if (xaccTransWarnReadOnly(trans))
+    if (is_trans_readonly_and_warn(trans))
         return;
     dialog = gtk_message_dialog_new(GTK_WINDOW(gsr->window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1033,7 +1048,7 @@
     if (cursor_class == CURSOR_CLASS_NONE)
         return;
 
-    if (xaccTransWarnReadOnly(trans))
+    if (is_trans_readonly_and_warn(trans))
         return;
 
     /* On a split cursor, just delete the one split. */

Modified: gnucash/trunk/src/register/ledger-core/split-register-model.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-model.c	2012-03-24 22:34:32 UTC (rev 22116)
+++ gnucash/trunk/src/register/ledger-core/split-register-model.c	2012-03-24 22:34:44 UTC (rev 22117)
@@ -1770,41 +1770,6 @@
     return xaccPrintAmount (balance, gnc_account_print_info (account, FALSE));
 }
 
-static gboolean posted_date_means_readonly(const Transaction *trans)
-{
-    GDate *threshold_date;
-    GDate trans_date;
-    const QofBook *book = gnc_get_current_book ();
-    gboolean result;
-    g_assert(trans);
-
-    if (!qof_book_uses_autofreeze(book))
-    {
-        //g_warning("we don't use auto-read-only, num_days=%d", qof_book_get_num_days_autofreeze(book));
-        return FALSE;
-    }
-
-    threshold_date = qof_book_get_autofreeze_gdate(book);
-    trans_date = xaccTransGetDatePostedGDate(trans);
-
-//    g_warning("there is auto-read-only with days=%d, trans_date_day=%d, threshold_date_day=%d",
-//              qof_book_get_num_days_autofreeze(book),
-//              g_date_get_day(&trans_date),
-//              g_date_get_day(threshold_date));
-
-    if (g_date_compare(&trans_date, threshold_date) < 0)
-    {
-        //g_warning("we must auto-read-only");
-        result = TRUE;
-    }
-    else
-    {
-        result = FALSE;
-    }
-    g_date_free(threshold_date);
-    return result;
-}
-
 static gboolean
 gnc_split_register_cursor_is_readonly (VirtualLocation virt_loc,
                                        gpointer user_data)
@@ -1821,7 +1786,7 @@
     if (!txn) return FALSE;
 
     if (xaccTransGetReadOnly(txn)
-            || posted_date_means_readonly(txn))
+            || xaccTransIsReadonlyByPostedDate(txn))
         return(TRUE);
 
     type = xaccTransGetTxnType (txn);



More information about the gnucash-changes mailing list