From 8cc8ffe374c804fe7a1f34fe07debddc7ddf2ef0 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Wed, 21 Mar 2012 22:18:53 +0000 Subject: [PATCH] Add auto-read-only feature for old transactions after N days, denoted by the new red line in the register. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22109 57a11ea4-9604-0410-9ed3-97b8803252fd --- .../ledger-core/split-register-model.c | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/register/ledger-core/split-register-model.c b/src/register/ledger-core/split-register-model.c index e99f3a301f..4cb2760ca5 100644 --- a/src/register/ledger-core/split-register-model.c +++ b/src/register/ledger-core/split-register-model.c @@ -1770,6 +1770,41 @@ gnc_split_register_get_rbaln_entry (VirtualLocation virt_loc, 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) @@ -1785,7 +1820,8 @@ gnc_split_register_cursor_is_readonly (VirtualLocation virt_loc, txn = xaccSplitGetParent (split); if (!txn) return FALSE; - if (xaccTransGetReadOnly(txn)) + if (xaccTransGetReadOnly(txn) + || posted_date_means_readonly(txn)) return(TRUE); type = xaccTransGetTxnType (txn);