From 1562324234b4974820831bd0a2542367d269818d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 21 Aug 2017 14:01:02 +0200 Subject: [PATCH] Fixed teacher activity calculation --- stages/models.py | 19 +++++++++++++++---- stages/tests.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/stages/models.py b/stages/models.py index 1b4f2db..511e297 100644 --- a/stages/models.py +++ b/stages/models.py @@ -65,6 +65,9 @@ class Teacher(models.Model): next_report = models.IntegerField(default=0, verbose_name='Report suivant') archived = models.BooleanField(default=False) + MAX_ENS_PERIODS = 1900 + MAX_FORMATION = 250 + class Meta: verbose_name='Enseignant' ordering = ('last_name', 'first_name') @@ -80,11 +83,19 @@ class Teacher(models.Model): ens = self.course_set.exclude(subject__startswith='#') tot_mandats = mandats.aggregate(models.Sum('period'))['period__sum'] or 0 tot_ens = ens.aggregate(models.Sum('period'))['period__sum'] or 0 - tot_formation = int(round((tot_mandats + tot_ens) / 1900 * 250)) + # formation periods calculated at pro-rata of total charge + tot_formation = int(round((tot_mandats + tot_ens) / self.MAX_ENS_PERIODS * self.MAX_FORMATION)) tot_trav = self.previous_report + tot_mandats + tot_ens + tot_formation tot_paye = tot_trav - if self.rate == 100 and tot_paye != 100: - tot_paye = 2150 + max_periods = self.MAX_ENS_PERIODS + self.MAX_FORMATION + # Special situations triggering reporting (positive or negative) hours for next year: + # - full-time teacher with a total charge under 100% + # - teachers with a total charge over 100% + if (self.rate == 100 and tot_paye < max_periods) or (tot_paye > max_periods): + tot_paye = max_periods + self.next_report = tot_paye - tot_trav + self.save() + return { 'mandats': mandats, 'tot_mandats': tot_mandats, @@ -92,7 +103,7 @@ class Teacher(models.Model): 'tot_formation': tot_formation, 'tot_trav': tot_trav, 'tot_paye': tot_paye, - 'report': tot_trav - tot_paye, + 'report': self.next_report, } def calc_imputations(self): diff --git a/stages/tests.py b/stages/tests.py index 02cde00..4f7293e 100644 --- a/stages/tests.py +++ b/stages/tests.py @@ -173,7 +173,7 @@ class TeacherTests(TestCase): 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' + first_name='Jeanne', last_name='Dubois', birth_date='1974-08-08', rate=50.0 ) Course.objects.create( teacher=cls.teacher, period=8, subject='#ASE Colloque', imputation='ASSCFE', @@ -214,6 +214,39 @@ class TeacherTests(TestCase): del effective['mandats'] self.assertEqual(effective, expected) + # Test over max hours per year for a full time + self.teacher.rate = 100.0 + self.teacher.save() + crs = Course.objects.create( + teacher=self.teacher, period=Teacher.MAX_ENS_PERIODS - 4, subject='Cours principal', imputation='ASSCFE', + ) + effective = self.teacher.calc_activity() + del effective['mandats'] + self.assertEqual(effective, { + 'tot_mandats': 8, + 'tot_ens': Teacher.MAX_ENS_PERIODS, + 'tot_formation': Teacher.MAX_FORMATION + 1, + 'tot_trav': Teacher.MAX_ENS_PERIODS + Teacher.MAX_FORMATION + 1 + 8, + 'tot_paye': Teacher.MAX_ENS_PERIODS + Teacher.MAX_FORMATION, + 'report': -8 - 1, + }) + self.assertEqual(self.teacher.next_report, -8 - 1) + + # Test below max hours per year for a full time + crs.period = Teacher.MAX_ENS_PERIODS - 4 - 10 + crs.save() + effective = self.teacher.calc_activity() + del effective['mandats'] + self.assertEqual(effective, { + 'tot_mandats': 8, + 'tot_ens': Teacher.MAX_ENS_PERIODS - 10, + 'tot_formation': Teacher.MAX_FORMATION, + 'tot_trav': Teacher.MAX_ENS_PERIODS + Teacher.MAX_FORMATION + 8 - 10, + 'tot_paye': Teacher.MAX_ENS_PERIODS + Teacher.MAX_FORMATION, + 'report': 2, + }) + self.assertEqual(self.teacher.next_report, 2) + def test_calc_imputations(self): result = self.teacher.calc_imputations() self.assertEqual(result[1]['ASSC'], 9)