Developer forum

Forum » Integration » Bug in order filtering for QueuedOrdersSyncScheduledTask

Bug in order filtering for QueuedOrdersSyncScheduledTask

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

It seems that the scheduled task QueuedOrdersSyncScheduledTask doesn't take the "Finished for X minutes" setting into account appropriately. I tracked it down to an issue in OrderRepository line 1311.

The scheduled task sets up the filter as follows:

if (MinutesCompleted > 0)
{
  filter.ToCompletedDate = DateTime.Now.AddMinutes(-1 * MinutesCompleted);
}

That looks alright and creates a date that is X minutes in the past.

Then OrderRepository does this around line 1311:

if (filter.ToCompletedDate.HasValue)
{                
  var sqlToDate = filter.ToCompletedDate.Value.Add(new TimeSpan(23, 59, 59));
  if (sqlToDate > SqlDateTime.MaxValue.Value)
      sqlToDate = SqlDateTime.MaxValue.Value;
  sql.Add("AND EcomOrders.OrderCompletedDate <= {0} ", sqlToDate);
}

I think there are two issues with this code:

1. It just adds (almost) 24 hours to the date and time passed in which essentially sets the date to 24 hours in the future minus the configured "Finished for X minutes" in minutes. This then includes all orders that are in the database. Looks like the intend here was to make this midnight on the requested date which should have pulled the date from the Date property:

  var sqlToDate = filter.ToCompletedDate.Value.Date.Add(new TimeSpan(23, 59, 59));

2. However, for the ToCompletedDate we don't want midnight on the requested date, we want the exact time passed in. So I believe the correct implementation would be this:

if (filter.ToCompletedDate.HasValue)
{                
  var sqlToDate = filter.ToCompletedDate.Value);
  if (sqlToDate > SqlDateTime.MaxValue.Value)
      sqlToDate = SqlDateTime.MaxValue.Value;
  sql.Add("AND EcomOrders.OrderCompletedDate <= {0} ", sqlToDate);
}

which takes the date as-is and caps it if needed.

I believe the same issue is present with the ToDate filter in the same repo which is used by standard order list filtering. It adds 24 hours to the current date, giving you orders for the next day when you filter by a specific end date:

Can this be fixed please?

I think as a work around we can set the finished minutes to 1440 (a whole day) + whatever value we need (i.e. 1445 for a 5 minutes delay).

We're on DW 9.

Imar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Imar

Thank you for a great description. I have sent this to QA and we will take care of it.

BR Nicolai

Votes for this answer: 1
 
Rasmus Sanggaard Dynamicweb Employee
Rasmus Sanggaard
Reply
This post has been marked as an answer

Hi,

 

We have created a bug for it #24854.

 

BR Rasmus Sanggaard

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thank you both.

Just following up for someone else running into this: there was no issue with the ToData. The code filters on OrderDate while my screenshot shows CompletedDate.

Imar

 

You must be logged in to post in the forum