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

Last change on this file since 16891 was 16891, checked in by Henrik Bettermann, 3 years ago

Make third_semester payment conditional on number registered at p_level.

  • Property svn:keywords set to Id
File size: 21.4 KB
RevLine 
[7419]1## $Id: utils.py 16891 2022-03-16 21:17:42Z 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
[16479]74    def _nce3PaymentMade(self, student, p_level):
[16008]75        if len(student['payments']):
76            for ticket in student['payments'].values():
[16463]77                if ticket.p_state in ('paid', 'scholarship', 'waived') and \
[16479]78                    ticket.p_level == p_level and \
[16008]79                    ticket.p_category == 'schoolfee':
80                    return True
81        return False
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':
[8599]107            amount = academic_session.booking_fee
[7151]108        elif category == 'hostel_maintenance':
[9611]109            current_session = student['studycourse'].current_session
110            bedticket = student['accommodation'].get(str(current_session), None)
111            if bedticket is not None and bedticket.bed is not None:
112                p_item = bedticket.bed_coordinates
[13616]113                if bedticket.bed.__parent__.maint_fee > 0:
114                    amount = bedticket.bed.__parent__.maint_fee
[9611]115            else:
[13616]116                return _(u'No bed space allocated.'), None
117            if student.current_mode.endswith('_sw') \
118                or student.current_mode == 'pd_ft':
119                amount *= 0.625
[7151]120        elif category == 'clearance':
[9143]121            amount = academic_session.clearance_fee
[8599]122            try:
123                p_item = student['studycourse'].certificate.code
124            except (AttributeError, TypeError):
125                return _('Study course data are incomplete.'), None
[13800]126            if student.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
127                return _(u'Acceptance Fee payments not allowed.'), None
[16891]128        elif category == 'third_semester' and student.current_mode == 'nce_ft' \
[16480]129            and p_level in (300, 310, 320, 400, 410, 420):
[16479]130            if not self._nce3PaymentMade(student, p_level):
[16008]131                return _(u'Make NCE 3 school fee payment first.'), None
[11919]132            if student.depcode in ARTS:
[16887]133                amount = 7688.0
[11919]134            else:
[16887]135                amount = 7938.0
136            no_additional_courses = 0
[16891]137            courses_level = student['studycourse'].get(str(p_level))
138            if courses_level and len(courses_level)> 6:
139                no_additional_courses = len(courses_level)-6
[16887]140                amount += 2000.0 * no_additional_courses
[16461]141        elif category.startswith('schoolfee'):
142            if category == 'schoolfee_pde1':
[16462]143                if not student.current_mode.startswith('pd'):
144                    return _('You are not a PDE student.'), None
[16461]145                if student.state != CLEARED:
146                        return _('You are not a fresh student.'), None
[12602]147            p_item =  student.certcode
148            if not p_item:
[8599]149                return _('Study course data are incomplete.'), None
[10012]150            if student.state not in (CLEARED, RETURNING):
151                return _('Wrong state.'), None
[10661]152            # PDE repeater
153            if student.current_verdict == 'OPDE':
[11850]154                amount = 23000
[13274]155            # PDE new
156            elif student.current_mode == 'pd_ft' and student.state == CLEARED:
[15523]157                amount = 70000
[16461]158                if category == 'schoolfee_pde1':
159                    amount = 40000
[10660]160            # PDE
161            elif student.current_mode == 'pd_ft':
[13275]162                amount = 35300
[12602]163
164            #Short Duration ICT Programs
165            elif p_item in ('CCO','DPMTS','DTPGD') and \
166                 student.state == CLEARED:
167                amount = 15000
168            elif p_item in ('ADTPGD','ADPMTS') and \
169                 student.state == CLEARED:
170                amount = 16000
171            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
172                 student.state == CLEARED:
173                amount = 25000
174            elif p_item in ('ADPMTSA','ADTPGDA') and \
175               student.state == CLEARED:
176                amount = 35000
177
[10012]178            # UG
179            elif student.current_mode == 'ug_ft':
[10876]180                if student.state == CLEARED:
181                    amount = 65650
[13779]182                # Introducing repeater fee for 'ug_ft' for 1st time
183                # on 15/03/2016
184                elif student.current_verdict == 'O':
185                    amount = 56150
[10876]186                else:
[14379]187                    amount = 56150
[10012]188            # NCE
[9143]189            elif not student.current_mode.endswith('_sw'):
190                # PRENCE
191                if student.current_level == 10 and student.state == CLEARED:
192                    if student.depcode in ARTS:
[14933]193                        amount = 24500
[9143]194                    else:
[14933]195                        amount = 25000
[10012]196                # NCE I fresh
[9143]197                elif student.current_level == 100 and student.state == CLEARED:
198                    if student.depcode in ARTS:
[15283]199                        amount = 28000
[9143]200                    else:
[15283]201                        amount = 28500
[14931]202                    # SIWES Fee
[16542]203                    if student.depcode in ('AGE', 'BED', 'FAA', 'HEC', 'CSC', 'MUS') \
204                       or student.certcode in ('NCECHECSC', 'NCEBIOCSC', 'NCEPHYCSC', 'NCEPHECSC',):
[14931]205                        amount += 3000
[10012]206                # NCE II
[9143]207                elif student.current_level in (100, 110, 120) and \
208                    student.state == RETURNING:
209                    if student.depcode in ARTS:
[15283]210                        amount = 24500
[9143]211                    else:
[15283]212                        amount = 25000
[10012]213                # NCE III
[9143]214                elif student.current_level in (200, 210, 220):
215                    if student.depcode in ARTS:
[14931]216                        amount = 15375
[9143]217                    else:
[14931]218                        amount = 15875
[10012]219                # NCE III repeater
[9143]220                elif student.current_level in (300, 310, 320) and \
221                    student.current_verdict == 'O':
222                    if student.depcode in ARTS:
[14931]223                        amount = 13475
[9143]224                    else:
[14931]225                        amount = 13975
[10012]226                # NCE III spillover
[9143]227                elif student.current_level in (300, 310, 320) and \
228                    student.current_verdict == 'B':
229                    if student.depcode in ARTS:
[14931]230                        amount = 13475
[9143]231                    else:
[14931]232                        amount = 13975
[10012]233                # NCE III second spillover
[9143]234                elif student.current_level in (400, 410, 420) and \
235                    student.current_verdict == 'B':
236                    if student.depcode in ARTS:
[14931]237                        amount = 13475
[9143]238                    else:
[14931]239                        amount = 13975
[9143]240            else:
[14265]241                # NCE I fresh sw
[9143]242                if student.current_level == 100 and student.state == CLEARED:
243                    if student.depcode in ARTS:
[14193]244                        amount = 23100
[9143]245                    else:
[14193]246                        amount = 23600
[14265]247                # NCE II fresh sw
248                elif student.current_level == 200 and student.state == CLEARED:
249                    if student.depcode in ARTS:
250                        amount = 19000
251                    else:
252                        amount = 19500
[10012]253                # NCE II sw
[9143]254                elif student.current_level in (100, 110, 120) and \
255                    student.state == RETURNING:
256                    if student.depcode in ARTS:
[11850]257                        amount = 19000
[9143]258                    else:
[11882]259                        amount = 19500
[10012]260                # NCE III sw
[9143]261                elif student.current_level in (200, 210, 220):
262                    if student.depcode in ARTS:
[11850]263                        amount = 21000
[9143]264                    else:
[14193]265                        amount = 21500
[10012]266                # NCE IV sw
[9143]267                elif student.current_level in (300, 310, 320):
268                    if student.depcode in ARTS:
[11850]269                        amount = 19000
[9143]270                    else:
[11850]271                        amount = 19500
[10012]272                # NCE V sw
[9143]273                elif student.current_level in (400, 410, 420):
274                    if student.depcode in ARTS:
[11850]275                        amount = 19000
[9143]276                    else:
[11850]277                        amount = 19500
[10012]278                # NCE V spillover sw
[9143]279                elif student.current_level in (500, 510, 520) and \
280                    student.current_verdict == 'B':
281                    if student.depcode in ARTS:
[11850]282                        amount = 17500
[9143]283                    else:
[11850]284                        amount = 18000
[10012]285                # NCE V second spillover sw
[9143]286                elif student.current_level in (600, 610, 620) and \
287                    student.current_verdict == 'B':
288                    if student.depcode in ARTS:
[11850]289                        amount = 17500
[9143]290                    else:
[11850]291                        amount = 18000
[10009]292            # NCE student payment can be disabled by
293            # setting the base school fee to -1
294            if academic_session.school_fee_base == -1 and \
295                student.current_mode.startswith('nce'):
[10010]296                return _(u'School fee payment is disabled.'), None
[9297]297            if student.state == RETURNING:
[9525]298                # Override p_session and p_level
[9297]299                p_session, p_level = self.getReturningData(student)
[9525]300                academic_session = self._getSessionConfiguration(p_session)
301                if academic_session == None:
302                    return _(u'Session configuration object is not available.'), None
[9143]303
[8599]304        if amount in (0.0, None):
305            return _(u'Amount could not be determined.'), None
[14566]306
307        # Add session and level specific penalty fee.
[13881]308        if category == 'schoolfee' and student.current_mode in (
[14617]309            'ug_ft', 'de_ft') and student.state != CLEARED:
[13881]310            amount += academic_session.penalty_ug_ft
311        elif category == 'schoolfee' and student.current_mode in (
[14556]312            'nce_ft',) and student['studycourse'].previous_verdict != 'O':
[14566]313            # NCE I fresh
314            if student.current_level == 100 and student.state == CLEARED:
315                amount += academic_session.penalty_nce1_ft
316            # NCE II
317            elif student.current_level in (100, 110, 120) and \
318                student.state == RETURNING:
319                amount += academic_session.penalty_nce2_ft
320            # NCE III (except repeaters and spillovers)
321            elif student.current_level in (200, 210, 220):
322                amount += academic_session.penalty_nce3_ft
[14618]323        elif category == 'schoolfee' and student.current_mode in ('nce_sw',
324            'nce_pt') and student['studycourse'].previous_verdict != 'O':
[14566]325            # NCE I fresh
326            if student.current_level == 100 and student.state == CLEARED:
327                amount += academic_session.penalty_nce1_pt
328            # NCE II
329            elif student.current_level in (100, 110, 120) and \
330                student.state == RETURNING:
331                amount += academic_session.penalty_nce2_pt
332            # NCE III (except repeaters and spillovers)
333            elif student.current_level in (200, 210, 220):
334                amount += academic_session.penalty_nce3_pt
[13881]335        elif category == 'schoolfee' and student.current_mode in ('prence',):
336            amount += academic_session.penalty_prence
[11649]337        if self.samePaymentMade(student, category, p_item, p_session):
338            return _('This type of payment has already been made.'), None
[11457]339        if self._isPaymentDisabled(p_session, category, student):
[13800]340            return _('This category of payments has been disabled.'), None
[8713]341        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]342        timestamp = ("%d" % int(time()*10000))[1:]
[8599]343        payment.p_id = "p%s" % timestamp
344        payment.p_category = category
345        payment.p_item = p_item
346        payment.p_session = p_session
347        payment.p_level = p_level
[9153]348        payment.p_current = p_current
[10388]349        payment.amount_auth = float(amount) + GATEWAY_AMT
[8599]350        return None, payment
[7621]351
[9207]352    def getAccommodationDetails(self, student):
353        """Determine the accommodation data of a student.
354        """
355        d = {}
356        d['error'] = u''
357        hostels = grok.getSite()['hostels']
358        d['booking_session'] = hostels.accommodation_session
359        d['allowed_states'] = hostels.accommodation_states
360        d['startdate'] = hostels.startdate
361        d['enddate'] = hostels.enddate
362        d['expired'] = hostels.expired
363        # Determine bed type
364        studycourse = student['studycourse']
365        certificate = getattr(studycourse,'certificate',None)
366        current_level = studycourse.current_level
367        if None in (current_level, certificate):
368            return d
369        end_level = certificate.end_level
370        if current_level == 10:
371            bt = 'pr'
372        elif current_level == 100:
373            bt = 'fr'
374        elif current_level >= 300:
375            bt = 'fi'
376        else:
377            bt = 're'
378        if student.sex == 'f':
379            sex = 'female'
380        else:
381            sex = 'male'
382        special_handling = 'regular'
[13614]383        if certificate.study_mode == 'ug_ft':
384            special_handling = 'ugft'
[9207]385        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
386        return d
387
[14617]388    #def warnCreditsOOR(self, studylevel, course=None):
389    #    """Return message if credits are out of range.
390    #    """
391    #    # adding a course ticket
392    #    if course:
393    #        if course.semester == 1:
394    #            if studylevel.total_credits_s1 + course.credits > 24:
395    #                return _('Maximum credits in 1st semester exceeded.')
396    #        if course.semester == 2:
397    #            if studylevel.total_credits_s2 + course.credits > 24:
398    #                return _('Maximum credits in 2nd semester exceeded.')
399    #    # registering course list
400    #    else:
401    #        if studylevel.total_credits_s1 > 24:
402    #            return _('Maximum credits in 1st semester exceeded.')
403    #        if studylevel.total_credits_s1 < 18:
404    #            return _('Minimum credits in 1st semester not reached.')
405    #        if studylevel.total_credits_s2 > 24:
406    #            return _('Maximum credits in 2nd semester exceeded.')
407    #        if studylevel.total_credits_s2 < 18:
408    #            return _('Minimum credits in 2nd semester not reached.')
409    #    return
410
[14586]411    def warnCreditsOOR(self, studylevel, course=None):
[14591]412        """Return message if credits are out of range.
[9903]413        """
[14591]414        # adding a course ticket
415        if course:
[14617]416            if studylevel.total_credits + course.credits > 52:
417                return _('Maximum credits exceeded.')
[14591]418        # registering course list
419        else:
[14617]420            if studylevel.total_credits > 52:
421                return _('Maximum credits exceeded.')
[14618]422            if studylevel.__parent__.previous_verdict == 'O':
423                return
[14591]424            if studylevel.total_credits_s1 < 18:
425                return _('Minimum credits in 1st semester not reached.')
426            if studylevel.total_credits_s2 < 18:
427                return _('Minimum credits in 2nd semester not reached.')
[14586]428        return
[9903]429
[9950]430    def getPDFCreator(self, context):
431        """Get a pdf creator suitable for `context`.
432
433        The default implementation always returns the default creator.
434        """
435        mode = getattr(context, 'current_mode', None)
436        if mode and mode.startswith('ug'):
437            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
438        return getUtility(IPDFCreator)
439
[9982]440    def _admissionText(self, student, portal_language):
441        mode = getattr(student, 'current_mode', None)
442        if mode and mode.startswith('ug'):
443            text = trans(_(
444                'With reference to your application for admission into Bachelor Degree '
445                'Programme of the University of Ibadan, this is to inform you that you have '
446                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
447                'Education Degree Programme as follows:'),
448                portal_language)
449        else:
450            inst_name = grok.getSite()['configuration'].name
451            text = trans(_(
[15890]452                'This is to inform you that you have been provisionally\n'
[15891]453                'admitted into ${a}\n'
454                'as follows:', mapping = {'a': inst_name}),
[9982]455                portal_language)
456        return text
457
[9989]458    def getBedCoordinates(self, bedticket):
459        """Return bed coordinates.
460
461        Bed coordinates are invisible in FCEOkene.
462        """
463        return _('(see payment slip)')
464
[13030]465    def _isPaymentDisabled(self, p_session, category, student):
466        academic_session = self._getSessionConfiguration(p_session)
467        if category == 'schoolfee':
468            if 'sf_all' in academic_session.payment_disabled:
469                return True
470            if 'sf_nce1' in academic_session.payment_disabled and \
471                student.current_level == 100 and student.state == CLEARED and \
472                student.current_mode == 'nce_ft':
473                return True
[16554]474        if category == 'clearance':
475            if 'cl_except_ug' in academic_session.payment_disabled and \
476                student.current_mode != 'ug_ft':
477                return True
[13030]478        return False
479
[10019]480    SEPARATORS_DICT = {
481        'form.fst_sit_fname': _(u'First Sitting Record'),
482        'form.scd_sit_fname': _(u'Second Sitting Record'),
483        #'form.alr_fname': _(u'Advanced Level Record'),
484        'form.hq_type': _(u'Advanced Level Record'),
485        'form.hq2_type': _(u'Second Higher Education Record'),
486        'form.nysc_year': _(u'NYSC Information'),
487        'form.employer': _(u'Employment History'),
488        'form.former_matric': _(u'Former Student'),
489        }
490
[10023]491    SKIP_UPLOAD_VIEWLETS = (
492        'higherqualificationresultupload',
493        'secondHigherqualificationresultupload',
494        'certificateupload',
495        'secondcertificateupload',
496        'thirdcertificateupload',
497        'resultstatementupload',
498        'secondrefereeletterupload',
499        'thirdrefereeletterupload',)
500
[8460]501    # FCEOkene prefix
[10520]502    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.