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

Last change on this file since 10570 was 10520, checked in by Henrik Bettermann, 11 years ago

Reduce maintenance fee.

  • Property svn:keywords set to Id
File size: 14.6 KB
RevLine 
[7419]1## $Id: utils.py 10520 2013-08-21 16:43:41Z 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
[8834]31class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]32    """A collection of customized methods.
33
34    """
35
[9190]36    def selectBed(self, available_beds):
37        """Randomly select a bed from a list of available beds.
38
39        """
40        return random.choice(available_beds)
41
[8270]42    def getReturningData(self, student):
43        """ This method defines what happens after school fee payment
[8319]44        of returning students depending on the student's senate verdict.
[8270]45        """
[8319]46        prev_level = student['studycourse'].current_level
47        cur_verdict = student['studycourse'].current_verdict
48        if cur_verdict in ('A','B','L','M','N','Z',):
49            # Successful student
50            new_level = divmod(int(prev_level),100)[0]*100 + 100
[9923]51        elif cur_verdict in ('C','O'):
[8319]52            # Student on probation
53            new_level = int(prev_level) + 10
54        else:
55            # Student is somehow in an undefined state.
56            # Level has to be set manually.
57            new_level = prev_level
[9923]58        if cur_verdict == 'O':
59            new_session = student['studycourse'].current_session
60        else:
61            new_session = student['studycourse'].current_session + 1
[8270]62        return new_session, new_level
63
[9153]64    def setPaymentDetails(self, category, student,
65            previous_session=None, previous_level=None):
[8599]66        """Create Payment object and set the payment data of a student for
67        the payment category specified.
68
69        """
[8306]70        details = {}
[8599]71        p_item = u''
72        amount = 0.0
73        error = u''
[9153]74        if previous_session:
75            return _('Previous session payment not yet implemented.'), None
[8599]76        p_session = student['studycourse'].current_session
77        p_level = student['studycourse'].current_level
[9153]78        p_current = True
[9525]79        academic_session = self._getSessionConfiguration(p_session)
80        if academic_session == None:
[8599]81            return _(u'Session configuration object is not available.'), None
[9525]82        # Determine fee.
[7151]83        if category == 'transfer':
[8599]84            amount = academic_session.transfer_fee
[7151]85        elif category == 'gown':
[8599]86            amount = academic_session.gown_fee
[7151]87        elif category == 'bed_allocation':
[8599]88            amount = academic_session.booking_fee
[7151]89        elif category == 'hostel_maintenance':
[9611]90            current_session = student['studycourse'].current_session
91            bedticket = student['accommodation'].get(str(current_session), None)
92            if bedticket is not None and bedticket.bed is not None:
93                p_item = bedticket.bed_coordinates
94            else:
95                return _(u'You have not yet booked accommodation.'), None
96            acc_details = self.getAccommodationDetails(student)
97            if current_session != acc_details['booking_session']:
98                return _(u'Current session does not match accommodation session.'), None
[9612]99            if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft':
[10520]100                amount = 2500.0 #removed interswitch fee
[9612]101            else:
[10520]102                amount = 4000.0 #removed interswitch fee
[7151]103        elif category == 'clearance':
[9143]104            amount = academic_session.clearance_fee
[8599]105            try:
106                p_item = student['studycourse'].certificate.code
107            except (AttributeError, TypeError):
108                return _('Study course data are incomplete.'), None
[7151]109        elif category == 'schoolfee':
[8599]110            try:
111                certificate = student['studycourse'].certificate
112                p_item = certificate.code
113            except (AttributeError, TypeError):
114                return _('Study course data are incomplete.'), None
[9143]115
116            # Very special school fee configuration, should be moved to
117            # a seperate file.
118
119            ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
120                    'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
121                    'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
122                    'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
123                    'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
124
[10012]125            if student.state not in (CLEARED, RETURNING):
126                return _('Wrong state.'), None
127
[10009]128            #PDE
[9143]129            if student.current_mode == 'pd_ft':
130                amount = 35000
[10012]131            # UG
132            elif student.current_mode == 'ug_ft':
[10026]133                amount = 65650
[10012]134            # NCE
[9143]135            elif not student.current_mode.endswith('_sw'):
136                # PRENCE
137                if student.current_level == 10 and student.state == CLEARED:
138                    if student.depcode in ARTS:
139                        amount = 14900
140                    else:
141                        amount = 15400
[10012]142                # NCE I fresh
[9143]143                elif student.current_level == 100 and student.state == CLEARED:
144                    if student.depcode in ARTS:
145                        amount = 12020
146                    else:
147                        amount = 12495
[10012]148                # NCE II
[9143]149                elif student.current_level in (100, 110, 120) and \
150                    student.state == RETURNING:
151                    if student.depcode in ARTS:
152                        amount = 11070
153                    else:
154                        amount = 11545
[10012]155                # NCE III
[9143]156                elif student.current_level in (200, 210, 220):
157                    if student.depcode in ARTS:
158                        amount = 11070
159                    else:
160                        amount = 11545
[10012]161                # NCE III repeater
[9143]162                elif student.current_level in (300, 310, 320) and \
163                    student.current_verdict == 'O':
164                    if student.depcode in ARTS:
165                        amount = 6535
166                    else:
167                        amount = 6773
[10012]168                # NCE III spillover
[9143]169                elif student.current_level in (300, 310, 320) and \
170                    student.current_verdict == 'B':
171                    if student.depcode in ARTS:
172                        amount = 9170
173                    else:
174                        amount = 9645
[10012]175                # NCE III second spillover
[9143]176                elif student.current_level in (400, 410, 420) and \
177                    student.current_verdict == 'B':
178                    if student.depcode in ARTS:
179                        amount = 9170
180                    else:
181                        amount = 9645
182            else:
183                if student.current_level == 100 and student.state == CLEARED:
184                    if student.depcode in ARTS:
185                        amount = 21900
186                    else:
187                        amount = 22400
[10012]188                # NCE II sw
[9143]189                elif student.current_level in (100, 110, 120) and \
190                    student.state == RETURNING:
191                    if student.depcode in ARTS:
192                        amount = 18400
193                    else:
194                        amount = 18900
[10012]195                # NCE III sw
[9143]196                elif student.current_level in (200, 210, 220):
197                    if student.depcode in ARTS:
198                        amount = 20400
199                    else:
200                        amount = 20900
[10012]201                # NCE IV sw
[9143]202                elif student.current_level in (300, 310, 320):
203                    if student.depcode in ARTS:
204                        amount = 18400
205                    else:
206                        amount = 18900
[10012]207                # NCE V sw
[9143]208                elif student.current_level in (400, 410, 420):
209                    if student.depcode in ARTS:
210                        amount = 18400
211                    else:
212                        amount = 18900
[10012]213                # NCE V spillover sw
[9143]214                elif student.current_level in (500, 510, 520) and \
215                    student.current_verdict == 'B':
216                    if student.depcode in ARTS:
217                        amount = 16900
218                    else:
219                        amount = 17400
[10012]220                # NCE V second spillover sw
[9143]221                elif student.current_level in (600, 610, 620) and \
222                    student.current_verdict == 'B':
223                    if student.depcode in ARTS:
224                        amount = 16900
225                    else:
226                        amount = 17400
[10009]227            # NCE student payment can be disabled by
228            # setting the base school fee to -1
229            if academic_session.school_fee_base == -1 and \
230                student.current_mode.startswith('nce'):
[10010]231                return _(u'School fee payment is disabled.'), None
[9297]232            if student.state == RETURNING:
[9525]233                # Override p_session and p_level
[9297]234                p_session, p_level = self.getReturningData(student)
[9525]235                academic_session = self._getSessionConfiguration(p_session)
236                if academic_session == None:
237                    return _(u'Session configuration object is not available.'), None
[9143]238
[8599]239        if amount in (0.0, None):
240            return _(u'Amount could not be determined.'), None
241        for key in student['payments'].keys():
242            ticket = student['payments'][key]
243            if ticket.p_state == 'paid' and\
244               ticket.p_category == category and \
245               ticket.p_item == p_item and \
246               ticket.p_session == p_session:
247                  return _('This type of payment has already been made.'), None
[8713]248        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]249        timestamp = ("%d" % int(time()*10000))[1:]
[8599]250        payment.p_id = "p%s" % timestamp
251        payment.p_category = category
252        payment.p_item = p_item
253        payment.p_session = p_session
254        payment.p_level = p_level
[9153]255        payment.p_current = p_current
[10388]256        # On June 26, 2013 FCEOkene realized that the Interswitch fee
257        # is deducted from their amount. Therefore, we add this fee here.
258        payment.amount_auth = float(amount) + GATEWAY_AMT
[8599]259        return None, payment
[7621]260
[9207]261    def getAccommodationDetails(self, student):
262        """Determine the accommodation data of a student.
263        """
264        d = {}
265        d['error'] = u''
266        hostels = grok.getSite()['hostels']
267        d['booking_session'] = hostels.accommodation_session
268        d['allowed_states'] = hostels.accommodation_states
269        d['startdate'] = hostels.startdate
270        d['enddate'] = hostels.enddate
271        d['expired'] = hostels.expired
272        # Determine bed type
273        studycourse = student['studycourse']
274        certificate = getattr(studycourse,'certificate',None)
275        current_level = studycourse.current_level
276        if None in (current_level, certificate):
277            return d
278        end_level = certificate.end_level
279        if current_level == 10:
280            bt = 'pr'
281        elif current_level == 100:
282            bt = 'fr'
283        elif current_level >= 300:
284            bt = 'fi'
285        else:
286            bt = 're'
287        if student.sex == 'f':
288            sex = 'female'
289        else:
290            sex = 'male'
291        special_handling = 'regular'
292        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
293        return d
294
[9903]295    def maxCredits(self, studylevel):
296        """Return maximum credits.
297
298        """
299        return 58
300
[9950]301    def getPDFCreator(self, context):
302        """Get a pdf creator suitable for `context`.
303
304        The default implementation always returns the default creator.
305        """
306        mode = getattr(context, 'current_mode', None)
307        if mode and mode.startswith('ug'):
308            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
309        return getUtility(IPDFCreator)
310
[9982]311    def _admissionText(self, student, portal_language):
312        mode = getattr(student, 'current_mode', None)
313        if mode and mode.startswith('ug'):
314            text = trans(_(
315                'With reference to your application for admission into Bachelor Degree '
316                'Programme of the University of Ibadan, this is to inform you that you have '
317                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
318                'Education Degree Programme as follows:'),
319                portal_language)
320        else:
321            inst_name = grok.getSite()['configuration'].name
322            text = trans(_(
323                'This is to inform you that you have been provisionally'
324                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
325                portal_language)
326        return text
327
[9989]328    def getBedCoordinates(self, bedticket):
329        """Return bed coordinates.
330
331        Bed coordinates are invisible in FCEOkene.
332        """
333        return _('(see payment slip)')
334
[10019]335    SEPARATORS_DICT = {
336        'form.fst_sit_fname': _(u'First Sitting Record'),
337        'form.scd_sit_fname': _(u'Second Sitting Record'),
338        #'form.alr_fname': _(u'Advanced Level Record'),
339        'form.hq_type': _(u'Advanced Level Record'),
340        'form.hq2_type': _(u'Second Higher Education Record'),
341        'form.nysc_year': _(u'NYSC Information'),
342        'form.employer': _(u'Employment History'),
343        'form.former_matric': _(u'Former Student'),
344        }
345
[10023]346    SKIP_UPLOAD_VIEWLETS = (
347        'higherqualificationresultupload',
348        'secondHigherqualificationresultupload',
349        'certificateupload',
350        'secondcertificateupload',
351        'thirdcertificateupload',
352        'resultstatementupload',
353        'secondrefereeletterupload',
354        'thirdrefereeletterupload',)
355
[8460]356    # FCEOkene prefix
[10520]357    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.