def test_get_fiscal_year_start_date(self): # test more October date than September date self.assertEqual(datetime.date(2014, 9, 28), ReportingPeriod.get_fiscal_year_start_date(2015)) # test more September date than October date self.assertEqual(datetime.date(2015, 10, 4), ReportingPeriod.get_fiscal_year_start_date(2016)) # test fiscal year starts right on 10/1 self.assertEqual(datetime.date(2017, 10, 1), ReportingPeriod.get_fiscal_year_start_date(2018))
def handle(self, *args, **options): update_user_data = options["userdata"] for source_file in options['csv_path']: self.stdout.write(f'Loading timecard data from {source_file}') try: with open(source_file, newline='') as csvfile: reader = csv.reader(csvfile) for username, target, from_date in reader: # Tock reporting period spans fiscal years at start of FY20 # If from_date in input is 10/1/19, get all FY20 timecards if from_date == '10/1/2019': start_date = ReportingPeriod.get_fiscal_year_start_date(2020) else: start_date = datetime.strptime(from_date, '%m/%d/%Y') timecards = Timecard.objects.filter(user__username=username, reporting_period__start_date__gte=start_date) self.stdout.write(f'Updating {len(timecards)} timecards for {username} to target hours {target}') target_billable_expectation = self._get_target_billable_expectation(target) # Update all identified timecards [self._update_timecard(timecard, target_billable_expectation) for timecard in timecards] if update_user_data: self._update_userdata(username, target_billable_expectation) self.stdout.write(f'Updated UserData.billable_expectation for {username} to target hours {target}') except FileNotFoundError: self.stdout.write(self.style.ERROR(f'File not found : {source_file}'))