test_calc_imputations_3
This commit is contained in:
parent
32861d10af
commit
390f563ac0
2 changed files with 28 additions and 6 deletions
|
|
@ -149,11 +149,6 @@ class Teacher(models.Model):
|
|||
for key in imputations:
|
||||
imputations[key] = courses.filter(imputation__contains=key).aggregate(models.Sum('period'))['period__sum'] or 0
|
||||
|
||||
tot = sum(imputations.values())
|
||||
if tot > 0:
|
||||
for key in imputations:
|
||||
imputations[key] += round(imputations[key] / tot * activities['tot_formation'])
|
||||
|
||||
# Split EDE periods in EDEpe and EDEps columns, in proportion
|
||||
ede = courses.filter(imputation='EDE').aggregate(models.Sum('period'))['period__sum'] or 0
|
||||
if ede > 0:
|
||||
|
|
@ -164,7 +159,21 @@ class Teacher(models.Model):
|
|||
imputations['EDEpe'] += pe_plus
|
||||
imputations['EDEps'] += ede - pe_plus
|
||||
|
||||
return (self.calc_activity(), imputations)
|
||||
# Split formation periods in proportions
|
||||
tot = sum(imputations.values())
|
||||
if tot > 0:
|
||||
for key in imputations:
|
||||
imputations[key] += round(imputations[key] / tot * activities['tot_formation'])
|
||||
|
||||
# Correct for rounding errors changing the first imputations value
|
||||
tot = sum(imputations.values()) + self.previous_report - (self.next_report)
|
||||
dif = tot - activities['tot_paye']
|
||||
if dif in [-1, 1]:
|
||||
for k, v in imputations.items():
|
||||
if v > 0:
|
||||
imputations[k] += 1 if dif == -1 else -1
|
||||
break
|
||||
return (activities, imputations)
|
||||
|
||||
def total_logbook(self):
|
||||
return LogBook.objects.filter(teacher=self).aggregate(models.Sum('nb_period'))['nb_period__sum']
|
||||
|
|
|
|||
|
|
@ -372,16 +372,29 @@ class TeacherTests(TestCase):
|
|||
result = self.teacher.calc_imputations()
|
||||
self.assertEqual(result[1]['ASSC'], 9)
|
||||
self.assertEqual(result[1]['EDEpe'], 5)
|
||||
|
||||
# Test with only EDE data
|
||||
t2 = Teacher.objects.create(
|
||||
first_name='Isidore', last_name='Gluck', birth_date='1986-01-01'
|
||||
)
|
||||
Course.objects.create(
|
||||
teacher=t2, period=13, subject='#ASE Colloque', imputation='ASSCFE',
|
||||
)
|
||||
Course.objects.create(
|
||||
teacher=t2, period=5, subject='Cours EDE', imputation='EDE',
|
||||
)
|
||||
Course.objects.create(
|
||||
teacher=t2, period=17, subject='Sém. enfance 2', imputation='ASE',
|
||||
)
|
||||
|
||||
result = t2.calc_imputations()
|
||||
self.assertEqual(result[1]['ASE'], 19)
|
||||
self.assertEqual(result[1]['ASSC'], 16) # rounding correction (first col > 0)
|
||||
self.assertEqual(result[1]['EDEpe'], 2)
|
||||
self.assertEqual(result[1]['EDEps'], 3)
|
||||
self.assertEqual(result[0]['tot_paye'], result[0]['tot_trav'])
|
||||
self.assertEqual(result[0]['tot_paye'], 40)
|
||||
self.assertEqual(result[0]['report'], 0)
|
||||
|
||||
def test_export_imputations(self):
|
||||
self.client.login(username='me', password='mepassword')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue