예제 #1
0
 def test_get_fiscal_year(self):
     """Check to ensure the proper fiscal year is returned."""
     self.assertEqual(2015, self.reporting_period.get_fiscal_year())
     reporting_period_2 = ReportingPeriod(
         start_date=datetime.date(2015, 10, 31),
         end_date=datetime.date(2015, 11, 7),
         exact_working_hours=32)
     self.assertEqual(2016, reporting_period_2.get_fiscal_year())
예제 #2
0
def limit_to_fy():
    """
    Filter component to Limit timecard aggregation to the current fiscal year
    """
    current_fy = ReportingPeriod().get_fiscal_year_from_date(
        datetime.date.today())
    fy_start_date = ReportingPeriod().get_fiscal_year_start_date(current_fy)
    return Q(timecards__submitted=True,
             timecards__reporting_period__start_date__gte=fy_start_date)
예제 #3
0
 def setUp(self):
     self.reporting_period = ReportingPeriod(
         start_date=datetime.date(2015, 1, 1),
         end_date=datetime.date(2015, 1, 7),
         exact_working_hours=40,
         min_working_hours=40,
         max_working_hours=60,
         message='This is not a vacation')
     self.reporting_period.save()
예제 #4
0
 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))
예제 #5
0
 def test_get_fiscal_year_end_date(self):
     # test more October date than September date
     self.assertEqual(datetime.date(2014, 9, 27),
         ReportingPeriod.get_fiscal_year_end_date(2014))
     # test more September date than October date
     self.assertEqual(datetime.date(2015, 10, 3),
         ReportingPeriod.get_fiscal_year_end_date(2015))
     # test fiscal year ends right on 9/30
     self.assertEqual(datetime.date(2017, 9, 30),
         ReportingPeriod.get_fiscal_year_end_date(2017))
예제 #6
0
 def test_is_late(self):
     """ Check if the user is late when no Timecard is present """
     userdata = UserData.objects.get(user=self.regular_user)
     reporting_period = ReportingPeriod(start_date=datetime.date(
         2015, 1, 1),
                                        end_date=datetime.date(2015, 1, 7),
                                        exact_working_hours=40,
                                        min_working_hours=40,
                                        max_working_hours=60,
                                        message='This is not a vacation')
     reporting_period.save()
     self.assertEqual(userdata.is_late, True)
    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}'))
예제 #8
0
 def test_unique_constraint(self):
     """ Check that unique constrains work for reporting period."""
     with self.assertRaises(ValidationError):
         ReportingPeriod(
             start_date=datetime.date(2015, 1, 1),
             end_date=datetime.date(2015, 1, 7),
             exact_working_hours=40).save()
예제 #9
0
def _get_reporting_periods(count):
    """
    Return start, end, and objects of `count` reporting periods from today
    """
    rps = ReportingPeriod.get_most_recent_periods(number_of_periods=count)
    if len(rps) == 1:
        start_date = rps[0].start_date
    else:
        start_date = rps[count - 1].start_date
    end_date = rps[0].end_date
    return start_date, end_date, rps
예제 #10
0
class ReportingPeriodTests(TestCase):
    def setUp(self):
        self.reporting_period = ReportingPeriod(
            start_date=datetime.date(2015, 1, 1),
            end_date=datetime.date(2015, 1, 7),
            exact_working_hours=40,
            min_working_hours=40,
            max_working_hours=60,
            message='This is not a vacation')
        self.reporting_period.save()

    def test_reporting_period_save(self):
        """Ensure that data was saved properly."""
        reporting_period = ReportingPeriod.objects.first()
        self.assertEqual(40, reporting_period.exact_working_hours)
        self.assertEqual(datetime.date(2015, 1, 1),
                         reporting_period.start_date)
        self.assertEqual(datetime.date(2015, 1, 7), reporting_period.end_date)
        self.assertEqual('This is not a vacation', reporting_period.message)
        self.assertEqual(40, reporting_period.min_working_hours)
        self.assertEqual(60, reporting_period.max_working_hours)

    def test_unique_constraint(self):
        """ Check that unique constrains work for reporting period."""
        with self.assertRaises(ValidationError):
            ReportingPeriod(start_date=datetime.date(2015, 1, 1),
                            end_date=datetime.date(2015, 1, 7),
                            exact_working_hours=40).save()

    def test_get_fiscal_year(self):
        """Check to ensure the proper fiscal year is returned."""
        self.assertEqual(2015, self.reporting_period.get_fiscal_year())
        reporting_period_2 = ReportingPeriod(
            start_date=datetime.date(2015, 10, 31),
            end_date=datetime.date(2015, 11, 7),
            exact_working_hours=32)
        self.assertEqual(2016, reporting_period_2.get_fiscal_year())
예제 #11
0
    def test_get_fiscal_year(self):
        """Check to ensure the proper fiscal year is returned."""
        self.assertEqual(2015, self.reporting_period.get_fiscal_year())
        reporting_period_2 = ReportingPeriod(
            start_date=datetime.date(2015, 10, 31),
            end_date=datetime.date(2015, 11, 7),
            exact_working_hours=32)
        self.assertEqual(2016, reporting_period_2.get_fiscal_year())

        # Testing the week that spans two FYs
        reporting_period_3 = ReportingPeriod(
            start_date=datetime.date(2014, 9, 28),
            end_date=datetime.date(2014, 10, 4),
            exact_working_hours=32)
        self.assertEqual(2015, reporting_period_3.get_fiscal_year())
        reporting_period_4 = ReportingPeriod(
            start_date=datetime.date(2015, 9, 27),
            end_date=datetime.date(2015, 10, 3),
            exact_working_hours=32)
        self.assertEqual(2015, reporting_period_4.get_fiscal_year())
예제 #12
0
class ReportingPeriodTests(TestCase):
    def setUp(self):
        self.reporting_period = ReportingPeriod(
            start_date=datetime.date(2015, 1, 1),
            end_date=datetime.date(2015, 1, 7),
            exact_working_hours=40,
            min_working_hours=40,
            max_working_hours=60,
            message='This is not a vacation')
        self.reporting_period.save()

    def test_reporting_period_save(self):
        """Ensure that data was saved properly."""
        reporting_period = ReportingPeriod.objects.first()
        self.assertEqual(40, reporting_period.exact_working_hours)
        self.assertEqual(
            datetime.date(2015, 1, 1), reporting_period.start_date)
        self.assertEqual(datetime.date(2015, 1, 7), reporting_period.end_date)
        self.assertEqual('This is not a vacation', reporting_period.message)
        self.assertEqual(40, reporting_period.min_working_hours)
        self.assertEqual(60, reporting_period.max_working_hours)

    def test_unique_constraint(self):
        """ Check that unique constrains work for reporting period."""
        with self.assertRaises(ValidationError):
            ReportingPeriod(
                start_date=datetime.date(2015, 1, 1),
                end_date=datetime.date(2015, 1, 7),
                exact_working_hours=40).save()

    def test_get_fiscal_year(self):
        """Check to ensure the proper fiscal year is returned."""
        self.assertEqual(2015, self.reporting_period.get_fiscal_year())
        reporting_period_2 = ReportingPeriod(
            start_date=datetime.date(2015, 10, 31),
            end_date=datetime.date(2015, 11, 7),
            exact_working_hours=32)
        self.assertEqual(2016, reporting_period_2.get_fiscal_year())

        # Testing the week that spans two FYs
        reporting_period_3 = ReportingPeriod(
            start_date=datetime.date(2014, 9, 28),
            end_date=datetime.date(2014, 10, 4),
            exact_working_hours=32)
        self.assertEqual(2015, reporting_period_3.get_fiscal_year())
        reporting_period_4 = ReportingPeriod(
            start_date=datetime.date(2015, 9, 27),
            end_date=datetime.date(2015, 10, 3),
            exact_working_hours=32)
        self.assertEqual(2015, reporting_period_4.get_fiscal_year())

    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 test_get_fiscal_year_end_date(self):
        # test more October date than September date
        self.assertEqual(datetime.date(2014, 9, 27),
            ReportingPeriod.get_fiscal_year_end_date(2014))
        # test more September date than October date
        self.assertEqual(datetime.date(2015, 10, 3),
            ReportingPeriod.get_fiscal_year_end_date(2015))
        # test fiscal year ends right on 9/30
        self.assertEqual(datetime.date(2017, 9, 30),
            ReportingPeriod.get_fiscal_year_end_date(2017))