Ignore:
Timestamp:
26 Jun 2023, 21:30:00 (15 months ago)
Author:
Henrik Bettermann
Message:

Implement new school fee calculation based on civ configuration tables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py

    r17396 r17457  
    1717##
    1818import grok
     19import os
     20import csv
    1921from time import time
    2022from reportlab.platypus import Paragraph, Table
     
    3032from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
    3133from waeup.uniben.interfaces import MessageFactory as _
     34
     35SCHOOLFEES = dict()
     36
     37schoolfees_path = os.path.join(
     38    os.path.dirname(__file__), 'schoolfees_22.csv')
     39reader = csv.DictReader(open(schoolfees_path, 'rb'))
     40SCHOOLFEES[22] = {line['code']: {item[0]:item[1] for item in line.items()}
     41    for line in reader}
     42
     43
     44schoolfees_path = os.path.join(
     45    os.path.dirname(__file__), 'schoolfees_20.csv')
     46reader = csv.DictReader(open(schoolfees_path, 'rb'))
     47SCHOOLFEES[20] = {line['code']: {item[0]:item[1] for item in line.items()}
     48    for line in reader}
     49
     50
     51schoolfees_path = os.path.join(
     52    os.path.dirname(__file__), 'schoolfees_17.csv')
     53reader = csv.DictReader(open(schoolfees_path, 'rb'))
     54SCHOOLFEES[17] = {line['code']: {item[0]:item[1] for item in line.items()}
     55    for line in reader}
     56
     57schoolfees_path = os.path.join(
     58    os.path.dirname(__file__), 'schoolfees_12.csv')
     59reader = csv.DictReader(open(schoolfees_path, 'rb'))
     60SCHOOLFEES[12] = {line['code']: {item[0]:item[1] for item in line.items()}
     61    for line in reader}
    3262
    3363class CustomStudentsUtils(NigeriaStudentsUtils):
     
    346376            except (AttributeError, TypeError):
    347377                return _('Study course data are incomplete.'), None
    348             discount_year = 2017
    349             if student.is_postgrad:
    350                 discount_year = 2020
     378            try:
     379                if student.entry_session < 2017:
     380                    schoolfees_dict = SCHOOLFEES[12][p_item]
     381                elif student.entry_session < 2020:
     382                    schoolfees_dict = SCHOOLFEES[17][p_item]
     383                elif student.entry_session < 2022:
     384                    schoolfees_dict = SCHOOLFEES[20][p_item]
     385                else:
     386                    schoolfees_dict = SCHOOLFEES[22][p_item]
     387            except KeyError:
     388                return _('School fee not yet fixed: p_item = %s' % p_item), None
    351389            if previous_session:
    352390                # Students can pay for previous sessions in all workflow states.
     
    355393                if previous_session == student['studycourse'].entry_session:
    356394                    if student.is_foreigner:
    357                         amount = getattr(certificate, 'school_fee_3', 0.0)
     395                        amount = schoolfees_dict['initial_foreigner']
    358396                    else:
    359                         amount = getattr(certificate, 'school_fee_1', 0.0)
    360                         # Old new students get a discount.
    361                         if student.entry_session < discount_year \
    362                             and certificate.custom_float_1:
    363                             amount -= certificate.custom_float_1                       
     397                        amount = schoolfees_dict['initial']
    364398                else:
    365399                    if student.is_foreigner:
    366                         amount = getattr(certificate, 'school_fee_4', 0.0)
     400                        amount = schoolfees_dict['returning_foreigner']
    367401                    else:
    368                         amount = getattr(certificate, 'school_fee_2', 0.0)
    369                         # Old returning students get a discount.
    370                         if student.entry_session < discount_year \
    371                             and certificate.custom_float_2:
    372                             amount -= certificate.custom_float_2
     402                        amount = schoolfees_dict['returning']
    373403            else:
    374404                if student.state == CLEARED:
    375405                    if student.is_foreigner:
    376                         amount = getattr(certificate, 'school_fee_3', 0.0)
     406                        amount = schoolfees_dict['initial_foreigner']
    377407                    else:
    378                         amount = getattr(certificate, 'school_fee_1', 0.0)
    379                         # Old new students get a discount.
    380                         if student.entry_session < discount_year \
    381                             and certificate.custom_float_1:
    382                             amount -= certificate.custom_float_1                             
     408                        amount = schoolfees_dict['initial']
    383409                elif student.state == PAID and student.is_postgrad:
    384410                    p_session += 1
     
    386412                    if academic_session == None:
    387413                        return _(u'Session configuration object is not available.'), None
    388 
    389                     # Students are only allowed to pay for the next session
    390                     # if current session payment
    391                     # has really been made, i.e. payment object exists.
    392                     #if not self._paymentMade(
    393                     #    student, student.current_session):
    394                     #    return _('You have not yet paid your current/active' +
    395                     #             ' session. Please use the previous session' +
    396                     #             ' payment form first.'), None
    397 
    398414                    if student.is_foreigner:
    399                         amount = getattr(certificate, 'school_fee_4', 0.0)
     415                        amount = schoolfees_dict['returning_foreigner']
    400416                    else:
    401                         amount = getattr(certificate, 'school_fee_2', 0.0)
    402                         # Old returning students might get a discount.
    403                         if student.entry_session < discount_year \
    404                             and certificate.custom_float_2:
    405                             amount -= certificate.custom_float_2
     417                        amount = schoolfees_dict['returning']
    406418                elif student.state == RETURNING:
    407419                    # In case of returning school fee payment the payment session
     
    423435
    424436                    if student.is_foreigner:
    425                         amount = getattr(certificate, 'school_fee_4', 0.0)
     437                        amount = schoolfees_dict['returning_foreigner']
    426438                    else:
    427                         amount = getattr(certificate, 'school_fee_2', 0.0)
    428                         # Old returning students might get a discount.
    429                         if student.entry_session < discount_year \
    430                             and certificate.custom_float_2:
    431                             amount -= certificate.custom_float_2
     439                        amount = schoolfees_dict['returning']
    432440                # PHARMD school fee amount is fixed and previously paid
    433441                # installments in current session are deducted.
     
    438446                    else:
    439447                        amount = 160000.0 - self._pharmdInstallments(student)
     448            try:
     449                amount = float(amount)
     450            except ValueError:
     451                return _(u'School fee not yet fixed: p_item = %s' % p_item), None
    440452            # Give 50% school fee discount to staff members.
    441453            if student.is_staff:
    442454                amount /= 2
     455
    443456        else:
    444457            fee_name = category + '_fee'
Note: See TracChangeset for help on using the changeset viewer.