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

Last change on this file since 13025 was 13022, checked in by Henrik Bettermann, 10 years ago

Temporarily disable NCE I payment.

Unfortunately, many tests are based on nce_ft level 100 students. They all failed and had to be changed.

School fee configuration in FCEOkene is too complex and error-prone. WAeUP Germany recommends to slim down and optimize administrative processes.

  • Property svn:keywords set to Id
File size: 16.6 KB
RevLine 
[7419]1## $Id: utils.py 13022 2015-05-29 06:03:24Z 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
[8475]22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
[8834]23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]24from waeup.kofa.accesscodes import create_accesscode
[9143]25from waeup.kofa.interfaces import CLEARED, RETURNING
[8460]26from waeup.fceokene.interfaces import MessageFactory as _
[9950]27from waeup.kofa.browser.interfaces import IPDFCreator
[9982]28from waeup.kofa.students.utils import trans
[10388]29from waeup.fceokene.interswitch.browser import GATEWAY_AMT
[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
[8834]40class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]41    """A collection of customized methods.
42
43    """
44
[10661]45    VERDICTS_DICT = {
46        '0': 'not yet',
47        'A': 'Successful student',
48        'B': 'Student with carryover courses',
49        'C': 'Student on probation',
50        'D': 'Withdrawn from the faculty',
51        #'E': 'Student who were previously on probation',
52        #'F': 'Medical case',
53        'G': 'Absent from examination',
54        #'H': 'Withheld results',
55        'I': 'Expelled/rusticated/suspended student',
56        'J': 'Temporary withdrawn from the university',
57        #'K': 'Unregistered student',
58        'L': 'Referred student',
59        'M': 'Reinstatement',
60        #'N': 'Student on transfer',
61        'O': 'NCE-III repeater',
62        #'Y': 'No previous verdict',
63        #'X': 'New 300 level student (Uniben)',
[12629]64        'Z': 'Successful student (provisional)',
[10661]65        'A1': 'First Class',
66        'A2': 'Second Class Upper',
67        'A3': 'Second Class Lower',
68        'A4': 'Third Class',
69        'A5': 'Pass',
70        'A6': 'Distinction',
71        'A7': 'Credit',
72        'A8': 'Merit',
73        'OPDE': 'PDE repeater',
74        }
75
[9190]76    def selectBed(self, available_beds):
77        """Randomly select a bed from a list of available beds.
78
79        """
80        return random.choice(available_beds)
81
[8270]82    def getReturningData(self, student):
83        """ This method defines what happens after school fee payment
[8319]84        of returning students depending on the student's senate verdict.
[8270]85        """
[8319]86        prev_level = student['studycourse'].current_level
87        cur_verdict = student['studycourse'].current_verdict
88        if cur_verdict in ('A','B','L','M','N','Z',):
89            # Successful student
90            new_level = divmod(int(prev_level),100)[0]*100 + 100
[9923]91        elif cur_verdict in ('C','O'):
[8319]92            # Student on probation
93            new_level = int(prev_level) + 10
94        else:
95            # Student is somehow in an undefined state.
96            # Level has to be set manually.
97            new_level = prev_level
[9923]98        if cur_verdict == 'O':
99            new_session = student['studycourse'].current_session
100        else:
101            new_session = student['studycourse'].current_session + 1
[8270]102        return new_session, new_level
103
[9153]104    def setPaymentDetails(self, category, student,
105            previous_session=None, previous_level=None):
[8599]106        """Create Payment object and set the payment data of a student for
107        the payment category specified.
108
109        """
[8306]110        details = {}
[8599]111        p_item = u''
112        amount = 0.0
113        error = u''
[9153]114        if previous_session:
115            return _('Previous session payment not yet implemented.'), None
[8599]116        p_session = student['studycourse'].current_session
117        p_level = student['studycourse'].current_level
[9153]118        p_current = True
[9525]119        academic_session = self._getSessionConfiguration(p_session)
120        if academic_session == None:
[8599]121            return _(u'Session configuration object is not available.'), None
[9525]122        # Determine fee.
[7151]123        if category == 'transfer':
[8599]124            amount = academic_session.transfer_fee
[7151]125        elif category == 'gown':
[8599]126            amount = academic_session.gown_fee
[7151]127        elif category == 'bed_allocation':
[8599]128            amount = academic_session.booking_fee
[7151]129        elif category == 'hostel_maintenance':
[9611]130            current_session = student['studycourse'].current_session
131            bedticket = student['accommodation'].get(str(current_session), None)
132            if bedticket is not None and bedticket.bed is not None:
133                p_item = bedticket.bed_coordinates
134            else:
135                return _(u'You have not yet booked accommodation.'), None
136            acc_details = self.getAccommodationDetails(student)
137            if current_session != acc_details['booking_session']:
138                return _(u'Current session does not match accommodation session.'), None
[9612]139            if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft':
[10520]140                amount = 2500.0 #removed interswitch fee
[9612]141            else:
[12628]142                amount = 4000.0 #removed interswitch fee
[7151]143        elif category == 'clearance':
[9143]144            amount = academic_session.clearance_fee
[8599]145            try:
146                p_item = student['studycourse'].certificate.code
147            except (AttributeError, TypeError):
148                return _('Study course data are incomplete.'), None
[11932]149        elif category == 'third_semester' and student.current_mode == 'nce_ft':
[11919]150            if student.depcode in ARTS:
[11932]151                amount = 6835
[11919]152            else:
[11932]153                amount = 7763
[7151]154        elif category == 'schoolfee':
[12602]155            p_item =  student.certcode
156            if not p_item:
[8599]157                return _('Study course data are incomplete.'), None
[9143]158
[10012]159            if student.state not in (CLEARED, RETURNING):
160                return _('Wrong state.'), None
161
[10661]162            # PDE repeater
163            if student.current_verdict == 'OPDE':
[11850]164                amount = 23000
[10660]165            # PDE
166            elif student.current_mode == 'pd_ft':
[11850]167                amount = 35300
[12602]168
169            #Short Duration ICT Programs
170            elif p_item in ('CCO','DPMTS','DTPGD') and \
171                 student.state == CLEARED:
172                amount = 15000
173            elif p_item in ('ADTPGD','ADPMTS') and \
174                 student.state == CLEARED:
175                amount = 16000
176            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
177                 student.state == CLEARED:
178                amount = 25000
179            elif p_item in ('ADPMTSA','ADTPGDA') and \
180               student.state == CLEARED:
181                amount = 35000
182
[10012]183            # UG
184            elif student.current_mode == 'ug_ft':
[10876]185            # Introducing returning students fee for 'ug_ft' for 1st time
186            # on 07/01/2014
187                if student.state == CLEARED:
188                    amount = 65650
189                else:
190                    amount = 56150
[10012]191            # NCE
[9143]192            elif not student.current_mode.endswith('_sw'):
193                # PRENCE
194                if student.current_level == 10 and student.state == CLEARED:
195                    if student.depcode in ARTS:
[12188]196                        amount = 17500
[9143]197                    else:
[12188]198                        amount = 18000
[10012]199                # NCE I fresh
[9143]200                elif student.current_level == 100 and student.state == CLEARED:
201                    if student.depcode in ARTS:
[12188]202                        amount = 14325
[9143]203                    else:
[12188]204                        amount = 14825
[13022]205                    ################################
206                    # Payment disabled on 29/05/15 #
207                    ################################
208                    amount = 0.0
[10012]209                # NCE II
[9143]210                elif student.current_level in (100, 110, 120) and \
211                    student.state == RETURNING:
212                    if student.depcode in ARTS:
[12188]213                        amount = 13375
[9143]214                    else:
[12188]215                        amount = 13875
[10012]216                # NCE III
[9143]217                elif student.current_level in (200, 210, 220):
218                    if student.depcode in ARTS:
[12188]219                        amount = 13375
[9143]220                    else:
[12188]221                        amount = 13875
[10012]222                # NCE III repeater
[9143]223                elif student.current_level in (300, 310, 320) and \
224                    student.current_verdict == 'O':
225                    if student.depcode in ARTS:
[12188]226                        amount = 11475
[9143]227                    else:
[12188]228                        amount = 11975
[10012]229                # NCE III spillover
[9143]230                elif student.current_level in (300, 310, 320) and \
231                    student.current_verdict == 'B':
232                    if student.depcode in ARTS:
[12188]233                        amount = 11975
[9143]234                    else:
[12188]235                        amount = 11975
[10012]236                # NCE III second spillover
[9143]237                elif student.current_level in (400, 410, 420) and \
238                    student.current_verdict == 'B':
239                    if student.depcode in ARTS:
[12188]240                        amount = 11975
[9143]241                    else:
[12188]242                        amount = 11975
[9143]243            else:
244                if student.current_level == 100 and student.state == CLEARED:
245                    if student.depcode in ARTS:
[11850]246                        amount = 22500
[9143]247                    else:
[11850]248                        amount = 23000
[10012]249                # NCE II sw
[9143]250                elif student.current_level in (100, 110, 120) and \
251                    student.state == RETURNING:
252                    if student.depcode in ARTS:
[11850]253                        amount = 19000
[9143]254                    else:
[11882]255                        amount = 19500
[10012]256                # NCE III sw
[9143]257                elif student.current_level in (200, 210, 220):
258                    if student.depcode in ARTS:
[11850]259                        amount = 21000
[9143]260                    else:
[11850]261                        amount = 21000
[10012]262                # NCE IV sw
[9143]263                elif student.current_level in (300, 310, 320):
264                    if student.depcode in ARTS:
[11850]265                        amount = 19000
[9143]266                    else:
[11850]267                        amount = 19500
[10012]268                # NCE V sw
[9143]269                elif student.current_level in (400, 410, 420):
270                    if student.depcode in ARTS:
[11850]271                        amount = 19000
[9143]272                    else:
[11850]273                        amount = 19500
[10012]274                # NCE V spillover sw
[9143]275                elif student.current_level in (500, 510, 520) and \
276                    student.current_verdict == 'B':
277                    if student.depcode in ARTS:
[11850]278                        amount = 17500
[9143]279                    else:
[11850]280                        amount = 18000
[10012]281                # NCE V second spillover sw
[9143]282                elif student.current_level in (600, 610, 620) and \
283                    student.current_verdict == 'B':
284                    if student.depcode in ARTS:
[11850]285                        amount = 17500
[9143]286                    else:
[11850]287                        amount = 18000
[10009]288            # NCE student payment can be disabled by
289            # setting the base school fee to -1
290            if academic_session.school_fee_base == -1 and \
291                student.current_mode.startswith('nce'):
[10010]292                return _(u'School fee payment is disabled.'), None
[9297]293            if student.state == RETURNING:
[9525]294                # Override p_session and p_level
[9297]295                p_session, p_level = self.getReturningData(student)
[9525]296                academic_session = self._getSessionConfiguration(p_session)
297                if academic_session == None:
298                    return _(u'Session configuration object is not available.'), None
[9143]299
[8599]300        if amount in (0.0, None):
301            return _(u'Amount could not be determined.'), None
[11649]302        if self.samePaymentMade(student, category, p_item, p_session):
303            return _('This type of payment has already been made.'), None
[11457]304        if self._isPaymentDisabled(p_session, category, student):
305            return _('Payment temporarily disabled.'), None
[8713]306        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]307        timestamp = ("%d" % int(time()*10000))[1:]
[8599]308        payment.p_id = "p%s" % timestamp
309        payment.p_category = category
310        payment.p_item = p_item
311        payment.p_session = p_session
312        payment.p_level = p_level
[9153]313        payment.p_current = p_current
[10388]314        # On June 26, 2013 FCEOkene realized that the Interswitch fee
315        # is deducted from their amount. Therefore, we add this fee here.
316        payment.amount_auth = float(amount) + GATEWAY_AMT
[8599]317        return None, payment
[7621]318
[9207]319    def getAccommodationDetails(self, student):
320        """Determine the accommodation data of a student.
321        """
322        d = {}
323        d['error'] = u''
324        hostels = grok.getSite()['hostels']
325        d['booking_session'] = hostels.accommodation_session
326        d['allowed_states'] = hostels.accommodation_states
327        d['startdate'] = hostels.startdate
328        d['enddate'] = hostels.enddate
329        d['expired'] = hostels.expired
330        # Determine bed type
331        studycourse = student['studycourse']
332        certificate = getattr(studycourse,'certificate',None)
333        current_level = studycourse.current_level
334        if None in (current_level, certificate):
335            return d
336        end_level = certificate.end_level
337        if current_level == 10:
338            bt = 'pr'
339        elif current_level == 100:
340            bt = 'fr'
341        elif current_level >= 300:
342            bt = 'fi'
343        else:
344            bt = 're'
345        if student.sex == 'f':
346            sex = 'female'
347        else:
348            sex = 'male'
349        special_handling = 'regular'
350        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
351        return d
352
[9903]353    def maxCredits(self, studylevel):
354        """Return maximum credits.
355
356        """
357        return 58
358
[9950]359    def getPDFCreator(self, context):
360        """Get a pdf creator suitable for `context`.
361
362        The default implementation always returns the default creator.
363        """
364        mode = getattr(context, 'current_mode', None)
365        if mode and mode.startswith('ug'):
366            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
367        return getUtility(IPDFCreator)
368
[9982]369    def _admissionText(self, student, portal_language):
370        mode = getattr(student, 'current_mode', None)
371        if mode and mode.startswith('ug'):
372            text = trans(_(
373                'With reference to your application for admission into Bachelor Degree '
374                'Programme of the University of Ibadan, this is to inform you that you have '
375                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
376                'Education Degree Programme as follows:'),
377                portal_language)
378        else:
379            inst_name = grok.getSite()['configuration'].name
380            text = trans(_(
381                'This is to inform you that you have been provisionally'
382                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
383                portal_language)
384        return text
385
[9989]386    def getBedCoordinates(self, bedticket):
387        """Return bed coordinates.
388
389        Bed coordinates are invisible in FCEOkene.
390        """
391        return _('(see payment slip)')
392
[10019]393    SEPARATORS_DICT = {
394        'form.fst_sit_fname': _(u'First Sitting Record'),
395        'form.scd_sit_fname': _(u'Second Sitting Record'),
396        #'form.alr_fname': _(u'Advanced Level Record'),
397        'form.hq_type': _(u'Advanced Level Record'),
398        'form.hq2_type': _(u'Second Higher Education Record'),
399        'form.nysc_year': _(u'NYSC Information'),
400        'form.employer': _(u'Employment History'),
401        'form.former_matric': _(u'Former Student'),
402        }
403
[10023]404    SKIP_UPLOAD_VIEWLETS = (
405        'higherqualificationresultupload',
406        'secondHigherqualificationresultupload',
407        'certificateupload',
408        'secondcertificateupload',
409        'thirdcertificateupload',
410        'resultstatementupload',
411        'secondrefereeletterupload',
412        'thirdrefereeletterupload',)
413
[8460]414    # FCEOkene prefix
[10520]415    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.