Take read-only date setting of QofBook into account (no pun intended) when entering transaction into accounts.

The code will silently revert the entered date to the threshold and just
not allow any older date to be entered. I wonder whether we can display
some useful error message additionally, but unfortunately I didn't find
the place in the code where one single error message would have resulted,
only places where multiply (annoying) error messages would have resulted.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22124 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2012-03-26 20:15:04 +00:00
parent 5aa445ef95
commit 78cbc3d097

View File

@ -94,12 +94,44 @@ static void
gnc_parse_date (struct tm *parsed, const char * datestr) gnc_parse_date (struct tm *parsed, const char * datestr)
{ {
int day, month, year; int day, month, year;
gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
if (!parsed) return; if (!parsed) return;
if (!datestr) return; if (!datestr) return;
qof_scan_date (datestr, &day, &month, &year); qof_scan_date (datestr, &day, &month, &year);
// If we have an auto-read-only threshold, do not accept a date that is
// older than the threshold.
if (use_autoreadonly)
{
GDate *d = g_date_new_dmy(day, month, year);
GDate *readonly_threshold = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
if (g_date_compare(d, readonly_threshold) < 0)
{
g_warning("Entered date %s is before the \"auto-read-only threshold\"; resetting to the threshold.", datestr);
#if 0
GtkWidget *dialog = gtk_message_dialog_new(NULL,
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s", _("Cannot store a transaction at this date"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", _("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."));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
#endif
// Reset the date to the threshold date
day = g_date_get_day(readonly_threshold);
month = g_date_get_month(readonly_threshold);
year = g_date_get_year(readonly_threshold);
}
g_date_free(d);
g_date_free(readonly_threshold);
}
parsed->tm_mday = day; parsed->tm_mday = day;
parsed->tm_mon = month - 1; parsed->tm_mon = month - 1;
parsed->tm_year = year - 1900; parsed->tm_year = year - 1900;