def milestones(self, create, count, **kwargs): if isinstance(count, dict): start_date = count['start_date'] count = None else: start_date = faker.date_time_between(start_date="now", end_date="1y", tzinfo=timezone(settings.TIME_ZONE)) if count is None: count = 4 make_milestones = getattr(MilestoneFactory, 'create' if create else 'build') milestones = list() #[make_milestones(project=self) for i in range(count)] fiscal_year = FiscalYear.create_from_date(start_date, display='AF%s') self.fiscal_year = str(fiscal_year) for i in range(count): if i == 0: milestone = make_milestones(project=self, milestone_type=Milestone.MILESTONE_START, date=start_date) start_date = start_date + timedelta(weeks=randint(2, 8)) elif i == count - 1: milestone = make_milestones(project=self, milestone_type=Milestone.MILESTONE_END, date=start_date) start_date = start_date + timedelta(weeks=randint(2, 8)) else: milestone = make_milestones(project=self, date=start_date) start_date = start_date + timedelta(weeks=randint(2, 8)) milestones.append(milestone) if create: self.save() else: # Fiddle with django internals so self.product_set.all() works with build() self._prefetched_objects_cache = {'milestones': milestones}
def test_get_with_errors(self): last_holiday = ACPHoliday.objects.last() fiscal_year = FiscalYear.create_from_date(last_holiday.date) year = fiscal_year.year + 1 url = reverse('fiscal-year-calendar', kwargs={'fiscal_year': year}) response = self.client.get(url) self.assertEqual(200, response.status_code) self.assertRegex(response.context['version'], self.version_regex) self.assertEqual(year, response.context['fiscal_year']) self.assertEqual('End date exceed the last registered holiday', response.context['errors'])
def test_get_with_errors(self): last_holiday = ACPHoliday.objects.last() fiscal_year = FiscalYear.create_from_date(last_holiday.date) year = fiscal_year.year + 1 url = reverse('calendar:fiscal-year-calendar', kwargs={'fiscal_year': year}) response = self.client.get(url) self.assertEqual(200, response.status_code) self.assertRegex(response.context['version'], self.version_regex) self.assertEqual(year, response.context['fiscal_year']) self.assertEqual('End date exceed the last registered holiday', response.context['errors'])
def handle(self, *args, **options): office = None office_title = 'All' if options['office'] != None: office = OrganizationUnit.objects.get(short_name=options['office']) office_title = options['office'] if options['fiscal_year'] != None: fiscal_year = int(options['fiscal_year']) else: fy = FiscalYear.create_from_date(datetime.now()) fiscal_year = fy.year if office: assignments = UnitAssignment.objects.get_fiscal_year_assignments_to(fiscal_year, office).order_by('employee__last_name') self.stdout.write('Office: %s FY: %d' % (office_title, fiscal_year)) self.stdout.write('-'*100) num = 1 for assignment in assignments: self.stdout.write('%2d. %-30s %-10s %-10s %4d' % (num, assignment.employee, assignment.start_date, assignment.end_date, assignment.age)) num += 1
def test_create_from_date_datetime(self): cdate = datetime.datetime(2013, 10, 1, 0, 0, 0) fy = FiscalYear.create_from_date(cdate) self.assertEqual('FY14', str(fy))
def test_create_from_date_2(self): cdate = datetime.date(2014, 9, 1) fy = FiscalYear.create_from_date(cdate) self.assertEqual('FY14', str(fy))
def test__str(self): fy = FiscalYear(2014, display='AF%s') self.assertEqual('AF14', str(fy))
def test__create(self): fy = FiscalYear(2016) self.assertEqual('FY16', str(fy)) self.assertEqual(datetime.date(2015, 10, 1), fy.start_date) self.assertEqual(datetime.date(2016, 9, 30), fy.end_date)
def test_create_from_date(self): cdate = datetime.date(2013, 10, 1) fy = FiscalYear.create_from_date(cdate) self.assertEqual('FY14', str(fy))
def test_current_fiscal_year(self, mock_now): mock_now.return_value = datetime.datetime(2013, 10, 1, 0, 0, 0) fy = FiscalYear.current_fiscal_year() self.assertEqual('FY14', str(fy))