Skip to content

Commit

Permalink
Add option for automatically setting old transactions to read-only.
Browse files Browse the repository at this point in the history
The number of days for this read-only threshold can be chosen.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22107 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
cstim committed Mar 21, 2012
1 parent e058cf0 commit bfbe9b8
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app-utils/app-utils.scm
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/app-utils/business-prefs.scm
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/engine/Makefile.am
Expand Up @@ -191,9 +191,11 @@ noinst_DATA = .scm-links
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) \
Expand Down
1 change: 1 addition & 0 deletions src/engine/engine.i
Expand Up @@ -295,6 +295,7 @@ KvpValue * kvp_frame_get_slot_path_gslist (KvpFrame *frame, GSList *key_path);

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");
Expand Down
35 changes: 35 additions & 0 deletions src/libqof/qof/qofbook.c
Expand Up @@ -641,6 +641,41 @@ qof_book_use_trading_accounts (const QofBook *book)
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)
{
Expand Down
17 changes: 17 additions & 0 deletions src/libqof/qof/qofbook.h
Expand Up @@ -248,6 +248,23 @@ void qof_book_mark_readonly(QofBook *book);
/** 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);

Expand Down
2 changes: 2 additions & 0 deletions src/libqof/qof/qofbookslots.h
Expand Up @@ -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")
Expand All @@ -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
*/
36 changes: 36 additions & 0 deletions src/libqof/qof/test/test-qofbook.c
Expand Up @@ -387,6 +387,41 @@ test_book_use_trading_accounts( Fixture *fixture, gconstpointer pData )

}

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 )
{
Expand Down Expand Up @@ -696,6 +731,7 @@ test_suite_qofbook ( void )
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 );
Expand Down

0 comments on commit bfbe9b8

Please sign in to comment.