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

Implement new school fee calculation based on civ configuration tables.

Location:
main/waeup.uniben/trunk/src/waeup/uniben/students
Files:
4 added
2 edited

Legend:

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

    r17395 r17457  
    551551        error, payment = utils.setPaymentDetails('schoolfee',
    552552            self.student, 2002, 300, None)
    553         self.assertEqual(payment.amount_auth, 40000.0)
     553        self.assertEqual(payment.amount_auth, 63000.0)
    554554        self.assertEqual(payment.p_session, 2002)
    555555        self.assertEqual(payment.p_level, 300)
     
    557557        error, payment = utils.setPaymentDetails('schoolfee',
    558558            self.student, 2003, 300, None)
    559         self.assertEqual(payment.amount_auth, 20000.0)
     559        self.assertEqual(payment.amount_auth, 26800.0)
    560560        self.assertEqual(payment.p_session, 2003)
    561561        self.assertEqual(payment.p_level, 300)
     
    569569        self.assertEqual(payment.p_level, 100)
    570570        self.assertEqual(payment.p_session, 2004)
    571         self.assertEqual(payment.amount_auth, 40000.0)
     571        self.assertEqual(payment.amount_auth, 63000.0)
    572572        self.assertEqual(payment.p_item, u'CERT1')
    573573        self.assertEqual(error, None)
     
    581581        error, payment = utils.setPaymentDetails('schoolfee',
    582582            self.student, None, None, None)
    583         self.assertEqual(payment.amount_auth, 40099.0)
     583        self.assertEqual(payment.amount_auth, 63099.0)
    584584
    585585        IWorkflowState(self.student).setState('returning')
     
    602602        self.assertEqual(payment.p_level, 200)
    603603        self.assertEqual(payment.p_session, 2005)
    604         self.assertEqual(payment.amount_auth, 20088.0)
     604        self.assertEqual(payment.amount_auth, 26888.0)
    605605        self.assertEqual(payment.p_item, u'CERT1')
    606606        self.assertEqual(error, None)
    607607
    608608        # Old returning students may pay less.
    609         self.certificate.school_fee_2 = 50000.0
    610         self.certificate.custom_float_2 = 30000.0
     609        #self.certificate.school_fee_2 = 50000.0
     610        #self.certificate.custom_float_2 = 30000.0
    611611        error, payment = utils.setPaymentDetails(
    612612            'schoolfee', self.student, None, None, None)
    613         self.assertEqual(payment.amount_auth, 20088.0)
     613        self.assertEqual(payment.amount_auth, 26888.0)
    614614
    615615        # Staff members pay less.
    616         self.certificate.custom_float_2 = None
    617616        self.student.is_staff = True
    618617        error, payment = utils.setPaymentDetails('schoolfee',
     
    620619        self.assertEqual(payment.p_level, 200)
    621620        self.assertEqual(payment.p_session, 2005)
    622         self.assertEqual(payment.amount_auth, 25088.0)
     621        self.assertEqual(payment.amount_auth, 13488.0)
    623622        self.assertEqual(payment.p_item, u'CERT1')
    624623        self.assertEqual(error, None)
     
    628627        self.student.is_staff = False
    629628        self.student.nationality = u'DE'
    630         self.certificate.school_fee_3 = 60000.0
    631629        error, payment = utils.setPaymentDetails(
    632630            'schoolfee', self.student, None, None, None)
    633631        self.assertEqual(payment.p_level, 100)
    634632        self.assertEqual(payment.p_session, 2004)
    635         self.assertEqual(payment.amount_auth, 60099.0)
     633        self.assertEqual(payment.amount_auth, 300099.0)
    636634        self.assertEqual(payment.p_item, u'CERT1')
    637635        self.assertEqual(error, None)
    638636        IWorkflowState(self.student).setState('returning')
    639637        self.student.is_staff = False
    640         self.certificate.school_fee_4 = 20000.0
    641638        error, payment = utils.setPaymentDetails(
    642639            'schoolfee', self.student, None, None, None)
    643640        self.assertEqual(payment.p_level, 200)
    644641        self.assertEqual(payment.p_session, 2005)
    645         self.assertEqual(payment.amount_auth, 20088.0)
     642        self.assertEqual(payment.amount_auth, 277088.0)
    646643        self.assertEqual(payment.p_item, u'CERT1')
    647644        self.assertEqual(error, None)
  • 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.