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

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

Adjust to base package.

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