Skip to content
This repository
Browse code

Workaround for a bug in iTC that could cause duplicate weekly reports

  • Loading branch information...
commit 7991dea4bd17c481726cf765d3b88e02d1862c77 1 parent fd918a9
Ole Zorn authored

Showing 1 changed file with 17 additions and 0 deletions. Show diff stats Hide diff stats

  1. +17 0 Classes/ReportDownloadOperation.m
17 Classes/ReportDownloadOperation.m
@@ -183,6 +183,23 @@ - (void)main
183 183 if (originalFilename && [reportCSV length] > 0) {
184 184 //Parse report CSV:
185 185 Report *report = [Report insertNewReportWithCSV:reportCSV inAccount:account];
  186 +
  187 + //Check if the downloaded report is actually the one we expect
  188 + //(mostly to work around a bug in iTC that causes the wrong weekly report to be downloaded):
  189 + NSString *downloadedReportDateString = nil;
  190 + if ([report isKindOfClass:[WeeklyReport class]]) {
  191 + WeeklyReport *weeklyReport = (WeeklyReport *)report;
  192 + downloadedReportDateString = [dateFormatter stringFromDate:weeklyReport.endDate];
  193 + } else {
  194 + downloadedReportDateString = [dateFormatter stringFromDate:report.startDate];
  195 + }
  196 + if (![reportDateString isEqualToString:downloadedReportDateString]) {
  197 + NSLog(@"Downloaded report has incorrect date, ignoring");
  198 + [[report managedObjectContext] deleteObject:report];
  199 + report = nil;
  200 + continue;
  201 + }
  202 +
186 203 if (report && originalFilename) {
187 204 NSManagedObject *originalReport = [NSEntityDescription insertNewObjectForEntityForName:@"ReportCSV" inManagedObjectContext:moc];
188 205 [originalReport setValue:reportCSV forKey:@"content"];

0 comments on commit 7991dea

Please sign in to comment.
Something went wrong with that request. Please try again.