New accounting rules
This commit is contained in:
parent
42c55f5521
commit
261ed1e99b
3 changed files with 97 additions and 53 deletions
|
|
@ -135,44 +135,45 @@ class Teacher(models.Model):
|
|||
'report': self.next_report,
|
||||
}
|
||||
|
||||
def calc_imputations(self):
|
||||
def calc_imputations(self, ratios):
|
||||
"""
|
||||
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)]
|
||||
[('ASAFE', 0), ('ASSCFE', 0), ('ASEFE', 0), ('MPTS', 0), ('MPS', 0), ('EDEpe', 0), ('EDEps', 0),
|
||||
('EDS', 0), ('CAS_FPP', 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
|
||||
|
||||
# Split EDE periods in EDEpe and EDEps columns, in proportion
|
||||
# Spliting imputations for EDE, ASE and ASSC
|
||||
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)) if (pe + ps) > 0 else 0.5
|
||||
pe_plus = round(ede * pe_percent)
|
||||
imputations['EDEpe'] += pe_plus
|
||||
imputations['EDEps'] += ede - pe_plus
|
||||
pe = int(round(ede * ratios['edepe'], 0))
|
||||
imputations['EDEpe'] += pe
|
||||
imputations['EDEps'] += ede - pe
|
||||
|
||||
ase = courses.filter(imputation='ASE').aggregate(models.Sum('period'))['period__sum'] or 0
|
||||
if ase > 0:
|
||||
asefe = int(round(ase * ratios['asefe'], 0))
|
||||
imputations['ASEFE'] += asefe
|
||||
imputations['MPTS'] += ase - asefe
|
||||
|
||||
assc = courses.filter(imputation='ASSC').aggregate(models.Sum('period'))['period__sum'] or 0
|
||||
if assc > 0:
|
||||
asscfe = int(round(assc * ratios['asscfe'], 0))
|
||||
imputations['ASSCFE'] += asscfe
|
||||
imputations['MPS'] += assc - asscfe
|
||||
|
||||
# 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'])
|
||||
imputations[key] += round(imputations[key] / tot * activities['tot_formation'],0)
|
||||
|
||||
# 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):
|
||||
|
|
@ -555,13 +556,20 @@ IMPUTATION_CHOICES = (
|
|||
('ASAFE', 'ASAFE'),
|
||||
('ASEFE', 'ASEFE'),
|
||||
('ASSCFE', 'ASSCFE'),
|
||||
('MP', 'MP'),
|
||||
|
||||
('MPTS', 'MPTS'),
|
||||
('MPS', 'MPS'),
|
||||
|
||||
('EDEpe', 'EDEpe'),
|
||||
('EDEps', 'EDEps'),
|
||||
('EDE', 'EDE'),
|
||||
('EDS', 'EDS'),
|
||||
('CAS_FPP', 'CAS_FPP'),
|
||||
('Direction', 'Direction'),
|
||||
|
||||
# To split afterwards
|
||||
('EDE', 'EDE'),
|
||||
('#Mandat_ASA', 'ASA'),
|
||||
('#Mandat_ASE', 'ASE'),
|
||||
('#Mandat_ASSC', 'ASSC'),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue