From e0e7cf7dfb0d34ca8cbbb891474b614bca2fe081 Mon Sep 17 00:00:00 2001 From: jean Date: Mon, 13 Apr 2020 14:02:03 -0700 Subject: [PATCH] Fix 3 problems with the scheduled transactions calculations This fixes 3 bugs: - Set a monthly recurrence on the 10th with a start date on the 20th of this month. The editor correctly shows the next occurrence to be on the 10th of the following month. The schedule transaction summary dialog incorrectly shows the next occurrence to be on the 10th of this month (before the start date!) - Set a monthly recurrence on the 19th, with a start date on the 20th of this month. The editor's calendar marks incorrectly show the next occurrence to be on the 19th of this month (before the start date). - Set a monthly recurrence on the 18th, with a start date on the 20th and an end date on the 17 of the following month. The calendar should show no mark, but fails to erase the marks that were present. --- gnucash/gnome-utils/gnc-dense-cal.c | 11 +++++++---- gnucash/gnome/dialog-sx-editor.c | 5 ++--- gnucash/register/ledger-core/gnc-ledger-display2.c | 1 - libgnucash/engine/SchedXaction.c | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 9bd6a872d1..ebef9f24d5 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -1939,10 +1939,13 @@ gdc_model_added_cb(GncDenseCalModel *model, guint added_tag, gpointer user_data) static void gdc_model_update_cb(GncDenseCalModel *model, guint update_tag, gpointer user_data) { - GncDenseCal *cal = GNC_DENSE_CAL(user_data); - g_debug("gdc_model_update_cb update for tag [%d]\n", update_tag); - gdc_mark_remove(cal, update_tag, FALSE); - gdc_add_tag_markings(cal, update_tag); + GncDenseCal *cal = GNC_DENSE_CAL (user_data); + gint num_marks = 0; + g_debug ("gdc_model_update_cb update for tag [%d]\n", update_tag); + num_marks = gnc_dense_cal_model_get_instance_count (cal->model, update_tag); + // We need to redraw if there are no mark, to ensure they're all erased. + gdc_mark_remove (cal, update_tag, num_marks==0); + gdc_add_tag_markings (cal, update_tag); } diff --git a/gnucash/gnome/dialog-sx-editor.c b/gnucash/gnome/dialog-sx-editor.c index ff6704cae7..acfca97d0c 100644 --- a/gnucash/gnome/dialog-sx-editor.c +++ b/gnucash/gnome/dialog-sx-editor.c @@ -1598,7 +1598,6 @@ gnc_sxed_update_cal(GncSxEditorDialog *sxed) g_date_clear(&start_date, 1); gnc_frequency_save_to_recurrence(sxed->gncfreq, &recurrences, &start_date); - g_date_subtract_days(&start_date, 1); recurrenceListNextInstance(recurrences, &start_date, &first_date); /* Deal with the fact that this SX may have been run before [the @@ -1609,10 +1608,10 @@ gnc_sxed_update_cal(GncSxEditorDialog *sxed) last_sx_inst = xaccSchedXactionGetLastOccurDate(sxed->sx); if (g_date_valid(last_sx_inst) && g_date_valid(&first_date) - && g_date_compare(last_sx_inst, &first_date) != 0) + && g_date_compare(last_sx_inst, &first_date) > 0) { /* last occurrence will be passed as initial date to update store - * later on as well */ + * later on as well, but only if it's past first_date */ start_date = *last_sx_inst; recurrenceListNextInstance(recurrences, &start_date, &first_date); } diff --git a/gnucash/register/ledger-core/gnc-ledger-display2.c b/gnucash/register/ledger-core/gnc-ledger-display2.c index 6df238c9ba..cfedaec60a 100644 --- a/gnucash/register/ledger-core/gnc-ledger-display2.c +++ b/gnucash/register/ledger-core/gnc-ledger-display2.c @@ -809,7 +809,6 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q, ld->use_double_line_default = use_double_line; - // JEAN: add mismatched_commodities ld->model = gnc_tree_model_split_reg_new (reg_type, style, use_double_line, is_template, mismatched_commodities); gnc_tree_model_split_reg_set_data (ld->model, ld, gnc_ledger_display2_parent); diff --git a/libgnucash/engine/SchedXaction.c b/libgnucash/engine/SchedXaction.c index fc4ae0e9b4..fac52bc9eb 100644 --- a/libgnucash/engine/SchedXaction.c +++ b/libgnucash/engine/SchedXaction.c @@ -931,13 +931,13 @@ xaccSchedXactionGetNextInstance (const SchedXaction *sx, SXTmpStateData *tsd) * we're at the beginning. We want to pretend prev_occur is the day before * the start_date in case the start_date is today so that the SX will fire * today. If start_date isn't valid either then the SX will fire anyway, no - * harm done. + * harm done. prev_occur cannot be before start_date either. */ - if (! g_date_valid( &prev_occur ) && g_date_valid(&sx->start_date)) + if (g_date_valid (&sx->start_date) && (!g_date_valid ( &prev_occur ) || g_date_compare (&prev_occur, &sx->start_date)<0)) { /* We must be at the beginning. */ prev_occur = sx->start_date; - g_date_subtract_days( &prev_occur, 1 ); + g_date_subtract_days (&prev_occur, 1 ); } recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur);