Skip to content

Commit

Permalink
Fix 3 problems with the scheduled transactions calculations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jean authored and jralls committed Apr 25, 2020
1 parent 31daba1 commit e0e7cf7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
11 changes: 7 additions & 4 deletions gnucash/gnome-utils/gnc-dense-cal.c
Expand Up @@ -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);

}

Expand Down
5 changes: 2 additions & 3 deletions gnucash/gnome/dialog-sx-editor.c
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion gnucash/register/ledger-core/gnc-ledger-display2.c
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions libgnucash/engine/SchedXaction.c
Expand Up @@ -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);
Expand Down

0 comments on commit e0e7cf7

Please sign in to comment.