mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Take read-only setting of QofBook into account for the transaction deletion as well.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22117 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1957,6 +1957,41 @@ xaccTransGetReadOnly (const Transaction *trans)
|
||||
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)
|
||||
|
@@ -321,12 +321,23 @@ SplitList * xaccTransGetSplitList (const Transaction *trans);
|
||||
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);
|
||||
|
||||
|
@@ -897,7 +897,7 @@ gnc_split_reg_reverse_trans_cb (GtkWidget *w, gpointer data)
|
||||
|
||||
|
||||
static gboolean
|
||||
xaccTransWarnReadOnly (const Transaction *trans)
|
||||
is_trans_readonly_and_warn (const Transaction *trans)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
const gchar *reason;
|
||||
@@ -907,6 +907,21 @@ xaccTransWarnReadOnly (const Transaction *trans)
|
||||
|
||||
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 @@ gsr_default_reinit_handler( GNCSplitReg *gsr, gpointer data )
|
||||
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 @@ gsr_default_delete_handler( GNCSplitReg *gsr, gpointer data )
|
||||
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. */
|
||||
|
@@ -1770,41 +1770,6 @@ 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)
|
||||
@@ -1821,7 +1786,7 @@ gnc_split_register_cursor_is_readonly (VirtualLocation virt_loc,
|
||||
if (!txn) return FALSE;
|
||||
|
||||
if (xaccTransGetReadOnly(txn)
|
||||
|| posted_date_means_readonly(txn))
|
||||
|| xaccTransIsReadonlyByPostedDate(txn))
|
||||
return(TRUE);
|
||||
|
||||
type = xaccTransGetTxnType (txn);
|
||||
|
Reference in New Issue
Block a user