Add and test Teacher.calc_imputations method
This commit is contained in:
parent
68ddf09d44
commit
f1fb3073de
2 changed files with 71 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import date, timedelta
|
||||
import json
|
||||
from collections import OrderedDict
|
||||
from datetime import date, timedelta
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
|
@ -94,6 +95,37 @@ class Teacher(models.Model):
|
|||
'report': tot_trav - tot_paye,
|
||||
}
|
||||
|
||||
def calc_imputations(self):
|
||||
"""
|
||||
Return a tuple for accountings charges
|
||||
"""
|
||||
activities = self.calc_activity()
|
||||
imputations = OrderedDict(
|
||||
[('ASA', 0), ('ASSC', 0), ('ASE', 0), ('MP', 0), ('EDEpe', 0), ('EDEps', 0),
|
||||
('EDS', 0), ('CAS-FPP', 0), ('Direction', 0)]
|
||||
)
|
||||
courses = self.course_set.all()
|
||||
|
||||
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 périods in EDEpe and EDEps columns, in proportion
|
||||
ede = courses.filter(imputation='EDE').aggregate(models.Sum('period'))['period__sum'] or 0
|
||||
if ede > 0:
|
||||
pe = imputations['EDEpe']
|
||||
ps = imputations['EDEps']
|
||||
pe_percent = pe / (pe + ps)
|
||||
pe_plus = pe * pe_percent
|
||||
imputations['EDEpe'] += pe_plus
|
||||
imputations['EDEps'] += ede - pe_plus
|
||||
|
||||
return (self.calc_activity(), imputations)
|
||||
|
||||
|
||||
class Student(models.Model):
|
||||
ext_id = models.IntegerField(null=True, unique=True, verbose_name='ID externe')
|
||||
|
|
@ -343,6 +375,6 @@ class Course(models.Model):
|
|||
verbose_name_plural = 'Cours'
|
||||
|
||||
def __str__(self):
|
||||
return '{0} - {1} - {2} - {3} - {4}'.format(
|
||||
self.teacher, self.klass, self.subject, self.period, self.section
|
||||
return '{0} - {1} - {2} - {3}'.format(
|
||||
self.teacher, self.public, self.subject, self.period
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,15 +9,14 @@ from django.utils.html import escape
|
|||
|
||||
from .models import (
|
||||
Level, Domain, Section, Klass, Period, Student, Corporation, Availability,
|
||||
CorpContact, Teacher, Training,
|
||||
CorpContact, Teacher, Training, Course,
|
||||
)
|
||||
from .utils import school_year
|
||||
|
||||
|
||||
class StagesTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
def setUpTestData(cls):
|
||||
Section.objects.bulk_create([
|
||||
Section(name='ASE'), Section(name='ASSC'), Section(name='EDE')
|
||||
])
|
||||
|
|
@ -159,13 +158,20 @@ class PeriodTest(TestCase):
|
|||
|
||||
|
||||
class TeacherTests(TestCase):
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
User.objects.create_superuser('me', 'me@example.org', 'mepassword')
|
||||
cls.teacher = Teacher.objects.create(
|
||||
first_name='Jeanne', last_name='Dubois', birth_date='1974-08-08'
|
||||
)
|
||||
Course.objects.create(
|
||||
teacher=cls.teacher, period=8, subject='#ASE Colloque', imputation='ASSCFE',
|
||||
)
|
||||
Course.objects.create(
|
||||
teacher=cls.teacher, period=4, subject='Sém. enfance 2', imputation='EDEpe',
|
||||
)
|
||||
|
||||
def test_export_charge_sheet(self):
|
||||
Teacher.objects.create(
|
||||
first_name='Laurie', last_name='Bernasconi', birth_date='1974-08-08'
|
||||
)
|
||||
change_url = reverse('admin:stages_teacher_changelist')
|
||||
self.client.login(username='me', password='mepassword')
|
||||
response = self.client.post(change_url, {
|
||||
|
|
@ -179,6 +185,29 @@ class TeacherTests(TestCase):
|
|||
self.assertEqual(response['Content-Type'], 'application/zip')
|
||||
self.assertGreater(len(response.content), 200)
|
||||
|
||||
def test_calc_activity(self):
|
||||
expected = {
|
||||
'tot_mandats': 8,
|
||||
'tot_ens': 4,
|
||||
'tot_formation': 2,
|
||||
'tot_trav': 14,
|
||||
'tot_paye': 14,
|
||||
'report': 0,
|
||||
}
|
||||
effective = self.teacher.calc_activity()
|
||||
self.assertEqual(list(effective['mandats']), list(Course.objects.filter(subject__startswith='#')))
|
||||
del effective['mandats']
|
||||
self.assertEqual(effective, expected)
|
||||
# Second time for equivalence test
|
||||
effective = self.teacher.calc_activity()
|
||||
del effective['mandats']
|
||||
self.assertEqual(effective, expected)
|
||||
|
||||
def test_calc_imputations(self):
|
||||
result = self.teacher.calc_imputations()
|
||||
self.assertEqual(result[1]['ASSC'], 9)
|
||||
self.assertEqual(result[1]['EDEpe'], 5)
|
||||
|
||||
|
||||
class ImportTests(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue