source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/utils.py @ 17942

Last change on this file since 17942 was 17734, checked in by Henrik Bettermann, 7 months ago

School fee payments are becoming even more complex.

  • Property svn:keywords set to Id
File size: 23.9 KB
RevLine 
[7419]1## $Id: utils.py 17734 2024-04-04 12:19:05Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
[7151]18import grok
[9190]19import random
[8599]20from time import time
[9950]21from zope.component import createObject, getUtility
[13800]22from waeup.kofa.interfaces import (
23    CLEARED, RETURNING, PAID, ADMITTED, CLEARANCE, REQUESTED)
[8834]24from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]25from waeup.kofa.accesscodes import create_accesscode
[9143]26from waeup.kofa.interfaces import CLEARED, RETURNING
[8460]27from waeup.fceokene.interfaces import MessageFactory as _
[9950]28from waeup.kofa.browser.interfaces import IPDFCreator
[9982]29from waeup.kofa.students.utils import trans
[6902]30
[11919]31# Very special school fee configuration, should be moved to
32# a seperate file.
33
34ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
35        'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
36        'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
37        'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
38        'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
39
[15594]40GATEWAY_AMT = 0.0
[15283]41
[8834]42class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]43    """A collection of customized methods.
44
45    """
46
[15706]47    def selectBed(self, available_beds):
[13459]48        """Randomly select a bed from the list of available beds.
[9190]49        """
50        return random.choice(available_beds)
51
[8270]52    def getReturningData(self, student):
53        """ This method defines what happens after school fee payment
[8319]54        of returning students depending on the student's senate verdict.
[8270]55        """
[8319]56        prev_level = student['studycourse'].current_level
57        cur_verdict = student['studycourse'].current_verdict
58        if cur_verdict in ('A','B','L','M','N','Z',):
59            # Successful student
60            new_level = divmod(int(prev_level),100)[0]*100 + 100
[9923]61        elif cur_verdict in ('C','O'):
[8319]62            # Student on probation
63            new_level = int(prev_level) + 10
64        else:
65            # Student is somehow in an undefined state.
66            # Level has to be set manually.
67            new_level = prev_level
[9923]68        if cur_verdict == 'O':
69            new_session = student['studycourse'].current_session
70        else:
71            new_session = student['studycourse'].current_session + 1
[8270]72        return new_session, new_level
73
[16899]74    #def _nce3PaymentMade(self, student, p_level):
75    #    if len(student['payments']):
76    #        for ticket in student['payments'].values():
77    #            if ticket.p_state in ('paid', 'scholarship', 'waived') and \
78    #                ticket.p_level == p_level and \
79    #                ticket.p_category == 'schoolfee':
80    #                return True
81    #    return False
[16008]82
[9153]83    def setPaymentDetails(self, category, student,
[15678]84            previous_session=None, previous_level=None, combi=[]):
[8599]85        """Create Payment object and set the payment data of a student for
86        the payment category specified.
87
88        """
[8306]89        details = {}
[8599]90        p_item = u''
91        amount = 0.0
92        error = u''
[9153]93        if previous_session:
94            return _('Previous session payment not yet implemented.'), None
[8599]95        p_session = student['studycourse'].current_session
96        p_level = student['studycourse'].current_level
[9153]97        p_current = True
[9525]98        academic_session = self._getSessionConfiguration(p_session)
99        if academic_session == None:
[8599]100            return _(u'Session configuration object is not available.'), None
[9525]101        # Determine fee.
[7151]102        if category == 'transfer':
[8599]103            amount = academic_session.transfer_fee
[7151]104        elif category == 'gown':
[8599]105            amount = academic_session.gown_fee
[7151]106        elif category == 'bed_allocation':
[17183]107            acco_details = self.getAccommodationDetails(student)
108            p_session = acco_details['booking_session']
109            p_item = acco_details['bt']
[8599]110            amount = academic_session.booking_fee
[7151]111        elif category == 'hostel_maintenance':
[17183]112            amount = 0.0
113            booking_session = grok.getSite()['hostels'].accommodation_session
114            bedticket = student['accommodation'].get(str(booking_session), None)
[9611]115            if bedticket is not None and bedticket.bed is not None:
[17183]116                p_session = booking_session
[9611]117                p_item = bedticket.bed_coordinates
[17629]118                if bedticket.bed.__parent__.maint_fee > 0:
119                    amount = bedticket.bed.__parent__.maint_fee
120                #if student['studycourse'].current_session < 2022:
121                #    amount = 6100.0
122                #else:
123                #    amount = 10090.0
[9611]124            else:
[13616]125                return _(u'No bed space allocated.'), None
126            if student.current_mode.endswith('_sw') \
127                or student.current_mode == 'pd_ft':
128                amount *= 0.625
[7151]129        elif category == 'clearance':
[9143]130            amount = academic_session.clearance_fee
[8599]131            try:
132                p_item = student['studycourse'].certificate.code
133            except (AttributeError, TypeError):
134                return _('Study course data are incomplete.'), None
[13800]135            if student.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
136                return _(u'Acceptance Fee payments not allowed.'), None
[16899]137        #elif category == 'third_semester' and student.current_mode == 'nce_ft' \
138        #    and p_level in (300, 310, 320, 400, 410, 420):
139        #    #if not self._nce3PaymentMade(student, p_level):
140        #    #    return _(u'Make NCE 3 school fee payment first.'), None
141        #    no_additional_courses = 0
142        #    courses_level = student['studycourse'].get(str(p_level))
143        #    if courses_level and len(courses_level)> 6:
144        #        no_additional_courses = len(courses_level)-6
145        #        amount = 2000.0 * no_additional_courses
[16461]146        elif category.startswith('schoolfee'):
[17493]147            increment_2022 = 0
[16461]148            if category == 'schoolfee_pde1':
[16462]149                if not student.current_mode.startswith('pd'):
150                    return _('You are not a PDE student.'), None
[16461]151                if student.state != CLEARED:
152                        return _('You are not a fresh student.'), None
[17734]153            if category == 'schoolfee_ug_new':
154                if not student.current_mode.startswith('ug'):
155                    return _('You are not a UG student.'), None
156                if student.state != CLEARED:
157                        return _('You are not a fresh student.'), None
158            if category == 'schoolfee_ug_ret':
159                if not student.current_mode.startswith('ug'):
160                    return _('You are not a UG student.'), None
161                if student.state != RETURNING:
162                        return _('You are not a returning student.'), None
[16899]163            if category == 'schoolfee_third':
164                if not student.current_mode == 'nce_ft' \
165                    or not p_level in (300, 310, 320, 400, 410, 420):
166                    return _('You are not an NCE 3 student.'), None
[12602]167            p_item =  student.certcode
168            if not p_item:
[8599]169                return _('Study course data are incomplete.'), None
[10012]170            if student.state not in (CLEARED, RETURNING):
171                return _('Wrong state.'), None
[10661]172            # PDE repeater
173            if student.current_verdict == 'OPDE':
[11850]174                amount = 23000
[13274]175            # PDE new
176            elif student.current_mode == 'pd_ft' and student.state == CLEARED:
[15523]177                amount = 70000
[16461]178                if category == 'schoolfee_pde1':
179                    amount = 40000
[10660]180            # PDE
181            elif student.current_mode == 'pd_ft':
[13275]182                amount = 35300
[12602]183
184            #Short Duration ICT Programs
185            elif p_item in ('CCO','DPMTS','DTPGD') and \
186                 student.state == CLEARED:
187                amount = 15000
188            elif p_item in ('ADTPGD','ADPMTS') and \
189                 student.state == CLEARED:
190                amount = 16000
191            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
192                 student.state == CLEARED:
193                amount = 25000
194            elif p_item in ('ADPMTSA','ADTPGDA') and \
195               student.state == CLEARED:
196                amount = 35000
197
[10012]198            # UG
199            elif student.current_mode == 'ug_ft':
[17734]200                if category == 'schoolfee_ug_new':
201                    # conditions checked above
202                    amount = 63200
203                elif category == 'schoolfee_ug_ret':
204                    # conditions checked above
205                    amount = 48700
206                elif student.state == CLEARED:
207                    amount = 126200
[13779]208                # Introducing repeater fee for 'ug_ft' for 1st time
209                # on 15/03/2016
[17734]210                #elif student.current_verdict == 'O':
211                #    amount = 96700
[10876]212                else:
[17734]213                    amount = 96700
[10012]214            # NCE
[9143]215            elif not student.current_mode.endswith('_sw'):
[17113]216                # in 2022 NCE school fees have encreased
217                increment_2022 = 11000
[9143]218                # PRENCE
219                if student.current_level == 10 and student.state == CLEARED:
220                    if student.depcode in ARTS:
[14933]221                        amount = 24500
[9143]222                    else:
[14933]223                        amount = 25000
[10012]224                # NCE I fresh
[9143]225                elif student.current_level == 100 and student.state == CLEARED:
226                    if student.depcode in ARTS:
[15283]227                        amount = 28000
[9143]228                    else:
[15283]229                        amount = 28500
[14931]230                    # SIWES Fee
[16542]231                    if student.depcode in ('AGE', 'BED', 'FAA', 'HEC', 'CSC', 'MUS') \
[17087]232                       or student.certcode in ('NCECHECSC',
233                                               'NCEBIOCSC',
234                                               'NCEPHYCSC',
235                                               'NCEPHECSC',
236                                               'NCETHAMUS',
237                                               'NCEANFMUS',
238                                               'NCEHISMUS',
239                                               'NCEIGBMUS',
240                                               'NCESPCCSC',
241                                               ):
[14931]242                        amount += 3000
[10012]243                # NCE II
[9143]244                elif student.current_level in (100, 110, 120) and \
245                    student.state == RETURNING:
246                    if student.depcode in ARTS:
[15283]247                        amount = 24500
[9143]248                    else:
[15283]249                        amount = 25000
[16899]250                # NCE III third semester
251                elif category == 'schoolfee_third':
252                    amount = 7000
[17706]253                    increment_2022 = 0
[10012]254                # NCE III
[9143]255                elif student.current_level in (200, 210, 220):
256                    if student.depcode in ARTS:
[14931]257                        amount = 15375
[9143]258                    else:
[14931]259                        amount = 15875
[17113]260                    increment_2022 = 20125
[10012]261                # NCE III repeater
[9143]262                elif student.current_level in (300, 310, 320) and \
263                    student.current_verdict == 'O':
264                    if student.depcode in ARTS:
[14931]265                        amount = 13475
[9143]266                    else:
[14931]267                        amount = 13975
[17499]268                    increment_2022 = 11000
[10012]269                # NCE III spillover
[9143]270                elif student.current_level in (300, 310, 320) and \
271                    student.current_verdict == 'B':
272                    if student.depcode in ARTS:
[14931]273                        amount = 13475
[9143]274                    else:
[14931]275                        amount = 13975
[17113]276                    increment_2022 = 20125
[10012]277                # NCE III second spillover
[9143]278                elif student.current_level in (400, 410, 420) and \
279                    student.current_verdict == 'B':
280                    if student.depcode in ARTS:
[14931]281                        amount = 13475
[9143]282                    else:
[14931]283                        amount = 13975
[17113]284                    increment_2022 = 20125
[9143]285            else:
[14265]286                # NCE I fresh sw
[9143]287                if student.current_level == 100 and student.state == CLEARED:
288                    if student.depcode in ARTS:
[14193]289                        amount = 23100
[9143]290                    else:
[14193]291                        amount = 23600
[14265]292                # NCE II fresh sw
293                elif student.current_level == 200 and student.state == CLEARED:
294                    if student.depcode in ARTS:
295                        amount = 19000
296                    else:
297                        amount = 19500
[10012]298                # NCE II sw
[9143]299                elif student.current_level in (100, 110, 120) and \
300                    student.state == RETURNING:
301                    if student.depcode in ARTS:
[11850]302                        amount = 19000
[9143]303                    else:
[11882]304                        amount = 19500
[10012]305                # NCE III sw
[9143]306                elif student.current_level in (200, 210, 220):
307                    if student.depcode in ARTS:
[11850]308                        amount = 21000
[9143]309                    else:
[14193]310                        amount = 21500
[10012]311                # NCE IV sw
[9143]312                elif student.current_level in (300, 310, 320):
313                    if student.depcode in ARTS:
[11850]314                        amount = 19000
[9143]315                    else:
[11850]316                        amount = 19500
[10012]317                # NCE V sw
[9143]318                elif student.current_level in (400, 410, 420):
319                    if student.depcode in ARTS:
[11850]320                        amount = 19000
[9143]321                    else:
[11850]322                        amount = 19500
[10012]323                # NCE V spillover sw
[9143]324                elif student.current_level in (500, 510, 520) and \
325                    student.current_verdict == 'B':
326                    if student.depcode in ARTS:
[11850]327                        amount = 17500
[9143]328                    else:
[11850]329                        amount = 18000
[10012]330                # NCE V second spillover sw
[9143]331                elif student.current_level in (600, 610, 620) and \
332                    student.current_verdict == 'B':
333                    if student.depcode in ARTS:
[16921]334                        amount = 17500
[9143]335                    else:
[16921]336                        amount = 18000
[10009]337            # NCE student payment can be disabled by
338            # setting the base school fee to -1
339            if academic_session.school_fee_base == -1 and \
340                student.current_mode.startswith('nce'):
[10010]341                return _(u'School fee payment is disabled.'), None
[9297]342            if student.state == RETURNING:
[9525]343                # Override p_session and p_level
[9297]344                p_session, p_level = self.getReturningData(student)
[9525]345                academic_session = self._getSessionConfiguration(p_session)
346                if academic_session == None:
347                    return _(u'Session configuration object is not available.'), None
[17501]348            if amount and p_session > 2021:
[17493]349                    amount += increment_2022
[17087]350        else:
351            fee_name = category + '_fee'
352            amount = getattr(academic_session, fee_name, 0.0)
353           
[8599]354        if amount in (0.0, None):
355            return _(u'Amount could not be determined.'), None
[14566]356
357        # Add session and level specific penalty fee.
[13881]358        if category == 'schoolfee' and student.current_mode in (
[14617]359            'ug_ft', 'de_ft') and student.state != CLEARED:
[13881]360            amount += academic_session.penalty_ug_ft
361        elif category == 'schoolfee' and student.current_mode in (
[14556]362            'nce_ft',) and student['studycourse'].previous_verdict != 'O':
[14566]363            # NCE I fresh
364            if student.current_level == 100 and student.state == CLEARED:
365                amount += academic_session.penalty_nce1_ft
366            # NCE II
367            elif student.current_level in (100, 110, 120) and \
368                student.state == RETURNING:
369                amount += academic_session.penalty_nce2_ft
370            # NCE III (except repeaters and spillovers)
371            elif student.current_level in (200, 210, 220):
372                amount += academic_session.penalty_nce3_ft
[14618]373        elif category == 'schoolfee' and student.current_mode in ('nce_sw',
374            'nce_pt') and student['studycourse'].previous_verdict != 'O':
[14566]375            # NCE I fresh
376            if student.current_level == 100 and student.state == CLEARED:
377                amount += academic_session.penalty_nce1_pt
378            # NCE II
379            elif student.current_level in (100, 110, 120) and \
380                student.state == RETURNING:
381                amount += academic_session.penalty_nce2_pt
382            # NCE III (except repeaters and spillovers)
383            elif student.current_level in (200, 210, 220):
384                amount += academic_session.penalty_nce3_pt
[13881]385        elif category == 'schoolfee' and student.current_mode in ('prence',):
386            amount += academic_session.penalty_prence
[11649]387        if self.samePaymentMade(student, category, p_item, p_session):
388            return _('This type of payment has already been made.'), None
[11457]389        if self._isPaymentDisabled(p_session, category, student):
[13800]390            return _('This category of payments has been disabled.'), None
[8713]391        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]392        timestamp = ("%d" % int(time()*10000))[1:]
[8599]393        payment.p_id = "p%s" % timestamp
394        payment.p_category = category
395        payment.p_item = p_item
396        payment.p_session = p_session
397        payment.p_level = p_level
[9153]398        payment.p_current = p_current
[10388]399        payment.amount_auth = float(amount) + GATEWAY_AMT
[8599]400        return None, payment
[7621]401
[9207]402    def getAccommodationDetails(self, student):
403        """Determine the accommodation data of a student.
404        """
405        d = {}
406        d['error'] = u''
407        hostels = grok.getSite()['hostels']
408        d['booking_session'] = hostels.accommodation_session
409        d['allowed_states'] = hostels.accommodation_states
410        d['startdate'] = hostels.startdate
411        d['enddate'] = hostels.enddate
412        d['expired'] = hostels.expired
413        # Determine bed type
414        studycourse = student['studycourse']
415        certificate = getattr(studycourse,'certificate',None)
416        current_level = studycourse.current_level
417        if None in (current_level, certificate):
418            return d
419        end_level = certificate.end_level
420        if current_level == 10:
421            bt = 'pr'
422        elif current_level == 100:
423            bt = 'fr'
424        elif current_level >= 300:
425            bt = 'fi'
426        else:
427            bt = 're'
428        if student.sex == 'f':
429            sex = 'female'
430        else:
431            sex = 'male'
432        special_handling = 'regular'
[13614]433        if certificate.study_mode == 'ug_ft':
434            special_handling = 'ugft'
[9207]435        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
436        return d
437
[14617]438    #def warnCreditsOOR(self, studylevel, course=None):
439    #    """Return message if credits are out of range.
440    #    """
441    #    # adding a course ticket
442    #    if course:
443    #        if course.semester == 1:
444    #            if studylevel.total_credits_s1 + course.credits > 24:
445    #                return _('Maximum credits in 1st semester exceeded.')
446    #        if course.semester == 2:
447    #            if studylevel.total_credits_s2 + course.credits > 24:
448    #                return _('Maximum credits in 2nd semester exceeded.')
449    #    # registering course list
450    #    else:
451    #        if studylevel.total_credits_s1 > 24:
452    #            return _('Maximum credits in 1st semester exceeded.')
453    #        if studylevel.total_credits_s1 < 18:
454    #            return _('Minimum credits in 1st semester not reached.')
455    #        if studylevel.total_credits_s2 > 24:
456    #            return _('Maximum credits in 2nd semester exceeded.')
457    #        if studylevel.total_credits_s2 < 18:
458    #            return _('Minimum credits in 2nd semester not reached.')
459    #    return
460
[14586]461    def warnCreditsOOR(self, studylevel, course=None):
[14591]462        """Return message if credits are out of range.
[9903]463        """
[14591]464        # adding a course ticket
465        if course:
[14617]466            if studylevel.total_credits + course.credits > 52:
467                return _('Maximum credits exceeded.')
[14591]468        # registering course list
469        else:
[14617]470            if studylevel.total_credits > 52:
471                return _('Maximum credits exceeded.')
[14618]472            if studylevel.__parent__.previous_verdict == 'O':
473                return
[14591]474            if studylevel.total_credits_s1 < 18:
475                return _('Minimum credits in 1st semester not reached.')
476            if studylevel.total_credits_s2 < 18:
477                return _('Minimum credits in 2nd semester not reached.')
[14586]478        return
[9903]479
[9950]480    def getPDFCreator(self, context):
481        """Get a pdf creator suitable for `context`.
482
483        The default implementation always returns the default creator.
484        """
485        mode = getattr(context, 'current_mode', None)
486        if mode and mode.startswith('ug'):
487            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
488        return getUtility(IPDFCreator)
489
[9982]490    def _admissionText(self, student, portal_language):
491        mode = getattr(student, 'current_mode', None)
492        if mode and mode.startswith('ug'):
493            text = trans(_(
[17576]494                'With reference to your application for admission into '
495                'Bachelor Degree Programme of the University of Ibadan, '
496                'you have been provisionally admitted to a full-time '
497                'Bachelor of Arts in Education Degree Programme as follows: '),
[9982]498                portal_language)
499        else:
500            inst_name = grok.getSite()['configuration'].name
501            text = trans(_(
[17576]502                'You have been provisionally admitted into Federal College '
503                'of Education Okene as follows: '
[17577]504                ),
[9982]505                portal_language)
506        return text
507
[9989]508    def getBedCoordinates(self, bedticket):
509        """Return bed coordinates.
510
511        Bed coordinates are invisible in FCEOkene.
512        """
513        return _('(see payment slip)')
514
[13030]515    def _isPaymentDisabled(self, p_session, category, student):
516        academic_session = self._getSessionConfiguration(p_session)
517        if category == 'schoolfee':
518            if 'sf_all' in academic_session.payment_disabled:
519                return True
520            if 'sf_nce1' in academic_session.payment_disabled and \
521                student.current_level == 100 and student.state == CLEARED and \
522                student.current_mode == 'nce_ft':
523                return True
[16554]524        if category == 'clearance':
525            if 'cl_except_ug' in academic_session.payment_disabled and \
526                student.current_mode != 'ug_ft':
527                return True
[13030]528        return False
529
[10019]530    SEPARATORS_DICT = {
531        'form.fst_sit_fname': _(u'First Sitting Record'),
532        'form.scd_sit_fname': _(u'Second Sitting Record'),
533        #'form.alr_fname': _(u'Advanced Level Record'),
534        'form.hq_type': _(u'Advanced Level Record'),
535        'form.hq2_type': _(u'Second Higher Education Record'),
536        'form.nysc_year': _(u'NYSC Information'),
537        'form.employer': _(u'Employment History'),
538        'form.former_matric': _(u'Former Student'),
539        }
540
[10023]541    SKIP_UPLOAD_VIEWLETS = (
542        'higherqualificationresultupload',
543        'secondHigherqualificationresultupload',
544        'certificateupload',
545        'secondcertificateupload',
546        'thirdcertificateupload',
547        'resultstatementupload',
548        'secondrefereeletterupload',
549        'thirdrefereeletterupload',)
550
[17178]551    ACCOMMODATION_SPAN = 1
552
[8460]553    # FCEOkene prefix
[10520]554    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.