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

Last change on this file since 16281 was 16011, checked in by Henrik Bettermann, 5 years ago

Only NCE 3 students pay third semester fee.

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