Bug 795831 - When read only threshold set, dates are silently changed

When you have specified a read only threshold, the date is silently
changed if it's beyond the threshold. There was already code to present
a dialog informing of this but was disabled so enable it.
This commit is contained in:
Robert Fewell
2018-06-10 14:26:39 +01:00
parent 2384af6068
commit 64837820ed
2 changed files with 44 additions and 32 deletions

View File

@@ -333,15 +333,26 @@ gnc_gdate_in_valid_range (GDate *test_date, gboolean warn)
GDate *max_date = g_date_new_dmy (1,1,10000);
GDate *min_date;
gboolean ret = FALSE;
gboolean max_date_ok = FALSE;
gboolean min_date_ok = FALSE;
if (use_autoreadonly)
min_date = qof_book_get_autoreadonly_gdate (gnc_get_current_book());
else
min_date = g_date_new_dmy (1,1,1400);
if ((g_date_compare (max_date, test_date) > 0) &&
(g_date_compare (min_date, test_date) <= 0))
ret = TRUE;
// max date
if (g_date_compare (max_date, test_date) > 0)
max_date_ok = TRUE;
// min date
if (g_date_compare (min_date, test_date) <= 0)
min_date_ok = TRUE;
if (use_autoreadonly && warn)
ret = max_date_ok;
else
ret = min_date_ok & max_date_ok;
if (warn && !ret)
{

View File

@@ -41,6 +41,7 @@
#include "datecell.h"
#include "dialog-utils.h"
#include "gnc-ui.h"
#include "gnc-ui-util.h"
#include "gnucash-date-picker.h"
#include "gnucash-item-edit.h"
@@ -92,34 +93,35 @@ static gboolean gnc_date_cell_enter (BasicCell *bcell,
static void gnc_date_cell_leave (BasicCell *bcell);
static gboolean
check_readonly_threshold (const gchar *datestr, GDate *d)
check_readonly_threshold (const gchar *datestr, GDate *d, gboolean warn)
{
GDate *readonly_threshold = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
if (g_date_compare(d, readonly_threshold) < 0)
{
#if 0
gchar *dialog_msg = _("The entered date of the new transaction is "
"older than the \"Read-Only Threshold\" set for "
"this book. This setting can be changed in "
"File -> Properties -> Accounts.");
gchar *dialog_title = _("Cannot store a transaction at this date");
GtkWidget *dialog = gtk_message_dialog_new(NULL,
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s", dialog_title);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", dialog_msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
#endif
g_warning("Entered date %s is before the \"auto-read-only threshold\";"
" resetting to the threshold.", datestr);
if (warn)
{
gchar *dialog_msg = _("The entered date of the transaction is "
"older than the \"Read-Only Threshold\" set for "
"this book. This setting can be changed in "
"File -> Properties -> Accounts, resetting to the threshold.");
gchar *dialog_title = _("Cannot store a transaction at this date");
GtkWidget *dialog = gtk_message_dialog_new(gnc_ui_get_main_window (NULL),
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s", dialog_title);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
"%s", dialog_msg);
gtk_dialog_run (GTK_DIALOG(dialog));
gtk_widget_destroy (dialog);
// Reset the date to the threshold date
g_date_set_julian (d, g_date_get_julian (readonly_threshold));
g_date_free (readonly_threshold);
return TRUE;
// g_warning("Entered date %s is before the \"auto-read-only threshold\";"
// " resetting to the threshold.", datestr);
}
// Reset the date to the threshold date
g_date_set_julian (d, g_date_get_julian (readonly_threshold));
g_date_free (readonly_threshold);
return TRUE;
}
g_date_free (readonly_threshold);
return FALSE;
@@ -161,14 +163,13 @@ gnc_parse_date (struct tm *parsed, const char * datestr, gboolean warn)
// older than the threshold.
if (use_autoreadonly)
{
GDate *d = g_date_new_dmy(day, month, year);
if (check_readonly_threshold (datestr, d))
g_date_set_dmy (test_date, day, month, year);
if (check_readonly_threshold (datestr, test_date, warn))
{
day = g_date_get_day (d);
month = g_date_get_month (d);
year = g_date_get_year (d);
day = g_date_get_day (test_date);
month = g_date_get_month (test_date);
year = g_date_get_year (test_date);
}
g_date_free (d);
}
g_date_free (test_date);