r22107 - gnucash/trunk/src - Add option for automatically setting old transactions to read-only.
Christian Stimming
cstim at code.gnucash.org
Wed Mar 21 18:18:29 EDT 2012
Author: cstim
Date: 2012-03-21 18:18:29 -0400 (Wed, 21 Mar 2012)
New Revision: 22107
Trac: http://svn.gnucash.org/trac/changeset/22107
Modified:
gnucash/trunk/src/app-utils/app-utils.scm
gnucash/trunk/src/app-utils/business-prefs.scm
gnucash/trunk/src/engine/Makefile.am
gnucash/trunk/src/engine/engine.i
gnucash/trunk/src/libqof/qof/qofbook.c
gnucash/trunk/src/libqof/qof/qofbook.h
gnucash/trunk/src/libqof/qof/qofbookslots.h
gnucash/trunk/src/libqof/qof/test/test-qofbook.c
Log:
Add option for automatically setting old transactions to read-only.
The number of days for this read-only threshold can be chosen.
Modified: gnucash/trunk/src/app-utils/app-utils.scm
===================================================================
--- gnucash/trunk/src/app-utils/app-utils.scm 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/app-utils/app-utils.scm 2012-03-21 22:18:29 UTC (rev 22107)
@@ -322,8 +322,9 @@
(define gnc:*option-section-accounts* OPTION-SECTION-ACCOUNTS)
(define gnc:*option-name-trading-accounts* OPTION-NAME-TRADING-ACCOUNTS)
+(define gnc:*option-name-auto-freeze-days* OPTION-NAME-AUTO-FREEZE-DAYS)
-(export gnc:*option-section-accounts* gnc:*option-name-trading-accounts*)
+(export gnc:*option-section-accounts* gnc:*option-name-trading-accounts* gnc:*option-name-auto-freeze-days*)
(define gnc:*option-section-budgeting* OPTION-SECTION-BUDGETING)
(define gnc:*option-name-default-budget* OPTION-NAME-DEFAULT-BUDGET)
Modified: gnucash/trunk/src/app-utils/business-prefs.scm
===================================================================
--- gnucash/trunk/src/app-utils/business-prefs.scm 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/app-utils/business-prefs.scm 2012-03-21 22:18:29 UTC (rev 22107)
@@ -131,6 +131,17 @@
"a" (N_ "Check to have trading accounts used for transactions involving more than one currency or commodity")
#f))
+ (reg-option
+ (gnc:make-number-range-option
+ gnc:*option-section-accounts* gnc:*option-name-auto-freeze-days*
+ "b" (N_ "Choose the number of days after which transactions will be read-only and cannot be edited anymore. This threshold is marked by a red line in the account register windows. If zero, all transactions can be edited and none are read-only.")
+ 0 ;; default
+ 0 ;; lower bound
+ 3650 ;; upper bound
+ 0 ;; number of decimals
+ 1 ;; step size
+ ))
+
;; Budgeting Tab
(reg-option
Modified: gnucash/trunk/src/engine/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/Makefile.am 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/engine/Makefile.am 2012-03-21 22:18:29 UTC (rev 22107)
@@ -191,9 +191,11 @@
if BUILDING_FROM_SVN
# The generated file depends on various libqof headers. Out of
-# laziness I only include one here - more might be needed
+# laziness I only include a few here - more might be needed
# subsequently.
-QOFHEADERS = $(top_srcdir)/src/libqof/qof/qofbook.h
+QOFHEADERS = \
+ $(top_srcdir)/src/libqof/qof/qofbook.h \
+ $(top_srcdir)/src/libqof/qof/qofbookslots.h
swig-engine.c: engine.i $(top_srcdir)/src/base-typemaps.i \
$(QOFHEADERS) \
Modified: gnucash/trunk/src/engine/engine.i
===================================================================
--- gnucash/trunk/src/engine/engine.i 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/engine/engine.i 2012-03-21 22:18:29 UTC (rev 22107)
@@ -295,6 +295,7 @@
SET_ENUM("OPTION-SECTION-ACCOUNTS");
SET_ENUM("OPTION-NAME-TRADING-ACCOUNTS");
+ SET_ENUM("OPTION-NAME-AUTO-FREEZE-DAYS");
SET_ENUM("OPTION-SECTION-BUDGETING");
SET_ENUM("OPTION-NAME-DEFAULT-BUDGET");
Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/libqof/qof/qofbook.c 2012-03-21 22:18:29 UTC (rev 22107)
@@ -641,6 +641,41 @@
return FALSE;
}
+gboolean qof_book_uses_autofreeze (const QofBook *book)
+{
+ g_assert(book);
+ return (qof_book_get_num_days_autofreeze(book) != 0);
+}
+
+gint qof_book_get_num_days_autofreeze (const QofBook *book)
+{
+ kvp_value *kvp_val;
+ double tmp;
+ g_assert(book);
+ kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book),
+ KVP_OPTION_PATH,
+ OPTION_SECTION_ACCOUNTS,
+ OPTION_NAME_AUTO_FREEZE_DAYS,
+ NULL);
+
+ if (kvp_val == NULL)
+ {
+ //g_warning("kvp_val for slot '%s' is NULL", OPTION_NAME_AUTO_FREEZE_DAYS);
+ return 0;
+ }
+
+ tmp = kvp_value_get_double (kvp_val);
+ return (gint) tmp;
+}
+
+GDate* qof_book_get_autofreeze_gdate (const QofBook *book)
+{
+ GDate* result = gnc_g_date_new_today();
+ g_assert(book);
+ g_date_subtract_days(result, qof_book_get_num_days_autofreeze(book));
+ return result;
+}
+
const char*
qof_book_get_string_option(const QofBook* book, const char* opt_name)
{
Modified: gnucash/trunk/src/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.h 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/libqof/qof/qofbook.h 2012-03-21 22:18:29 UTC (rev 22107)
@@ -248,6 +248,23 @@
/** Returns flag indicating whether this book uses trading accounts */
gboolean qof_book_use_trading_accounts (const QofBook *book);
+/** Returns TRUE if the auto-freeze feature should be used, otherwise
+ * FALSE. This is just a wrapper on get_num_days_autofreeze == 0. */
+gboolean qof_book_uses_autofreeze (const QofBook *book);
+
+/** Returns the number of days for auto-freeze transactions. If zero,
+ * the auto-freeze feature should be disabled (and uses_autofreeze
+ * returns FALSE). */
+gint qof_book_get_num_days_autofreeze (const QofBook *book);
+
+/** Returns the GDate that is the threshold for autofreeze. Any txn
+ * with posted-date lesser or equal to this date should be set to
+ * freeze.
+ *
+ * The returned object was allocated newly; the caller must
+ * g_date_free() the object afterwards. */
+GDate* qof_book_get_autofreeze_gdate (const QofBook *book);
+
/** Is the book shutting down? */
gboolean qof_book_shutting_down (const QofBook *book);
Modified: gnucash/trunk/src/libqof/qof/qofbookslots.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbookslots.h 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/libqof/qof/qofbookslots.h 2012-03-21 22:18:29 UTC (rev 22107)
@@ -64,6 +64,7 @@
#define OPTION_SECTION_ACCOUNTS N_("Accounts")
#define OPTION_NAME_TRADING_ACCOUNTS N_("Use Trading Accounts")
+#define OPTION_NAME_AUTO_FREEZE_DAYS N_("Day Threshold for Read-Only Transactions (red line)")
#define OPTION_SECTION_BUDGETING N_("Budgeting")
#define OPTION_NAME_DEFAULT_BUDGET N_("Default Budget")
@@ -74,6 +75,7 @@
* KVP-OPTION-PATH
* OPTION-SECTION-ACCOUNTS
* OPTION-NAME-TRADING-ACCOUNTS
+ * OPTION-NAME-AUTO-FREEZE-DAYS
* OPTION-SECTION-BUDGETING
* OPTION-NAME-DEFAULT-BUDGET
*/
Modified: gnucash/trunk/src/libqof/qof/test/test-qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-qofbook.c 2012-03-21 20:19:28 UTC (rev 22106)
+++ gnucash/trunk/src/libqof/qof/test/test-qofbook.c 2012-03-21 22:18:29 UTC (rev 22107)
@@ -388,6 +388,41 @@
}
static void
+test_book_get_num_days_autofreeze( Fixture *fixture, gconstpointer pData )
+{
+ const char *slot_path;
+
+ /* create correct slot path */
+ slot_path = (const char *) g_strconcat( KVP_OPTION_PATH, "/", OPTION_SECTION_ACCOUNTS, "/", OPTION_NAME_AUTO_FREEZE_DAYS, NULL );
+ g_assert( slot_path != NULL );
+
+ g_test_message( "Testing default: No auto-freeze days are set" );
+ g_assert( qof_book_uses_autofreeze( fixture-> book ) == FALSE );
+ g_assert( qof_book_get_num_days_autofreeze( fixture-> book ) == 0 );
+
+ g_test_message( "Testing with incorrect slot path and some correct value - 17" );
+ kvp_frame_set_double(qof_book_get_slots(fixture->book), OPTION_NAME_AUTO_FREEZE_DAYS, 17);
+ g_assert( qof_book_uses_autofreeze( fixture-> book ) == FALSE );
+ g_assert( qof_book_get_num_days_autofreeze( fixture-> book ) == 0 );
+
+ g_test_message( "Testing when setting this correctly with some correct value - 17" );
+ kvp_frame_set_double(qof_book_get_slots(fixture->book), slot_path, 17);
+ g_assert( qof_book_uses_autofreeze( fixture-> book ) == TRUE );
+ g_assert( qof_book_get_num_days_autofreeze( fixture-> book ) == 17 );
+
+ g_test_message( "Testing when setting this correctly to zero again" );
+ kvp_frame_set_double(qof_book_get_slots(fixture->book), slot_path, 0);
+ g_assert( qof_book_uses_autofreeze( fixture-> book ) == FALSE );
+ g_assert( qof_book_get_num_days_autofreeze( fixture-> book ) == 0 );
+
+ g_test_message( "Testing when setting this correctly with some correct value - 32" );
+ kvp_frame_set_double(qof_book_get_slots(fixture->book), slot_path, 32);
+ g_assert( qof_book_uses_autofreeze( fixture-> book ) == TRUE );
+ g_assert( qof_book_get_num_days_autofreeze( fixture-> book ) == 32 );
+
+}
+
+static void
test_book_mark_session_dirty( Fixture *fixture, gconstpointer pData )
{
QofBook *_empty = NULL;
@@ -696,6 +731,7 @@
GNC_TEST_ADD( suitename, "increment and format counter", Fixture, NULL, setup, test_book_increment_and_format_counter, teardown );
GNC_TEST_ADD( suitename, "kvp changed", Fixture, NULL, setup, test_book_kvp_changed, teardown );
GNC_TEST_ADD( suitename, "use trading accounts", Fixture, NULL, setup, test_book_use_trading_accounts, teardown );
+ GNC_TEST_ADD( suitename, "get autofreeze days", Fixture, NULL, setup, test_book_get_num_days_autofreeze, teardown );
GNC_TEST_ADD( suitename, "mark session dirty", Fixture, NULL, setup, test_book_mark_session_dirty, teardown );
GNC_TEST_ADD( suitename, "session dirty time", Fixture, NULL, setup, test_book_get_session_dirty_time, teardown );
GNC_TEST_ADD( suitename, "set dirty callback", Fixture, NULL, setup, test_book_set_dirty_cb, teardown );
More information about the gnucash-changes
mailing list