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

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

Change fee for NCE III repeaters.

  • Property svn:keywords set to Id
File size: 14.7 KB
Line 
1## $Id: utils.py 10660 2013-10-04 14:37: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##
18import grok
19import random
20from time import time
21from zope.component import createObject, getUtility
22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from waeup.kofa.accesscodes import create_accesscode
25from waeup.kofa.interfaces import CLEARED, RETURNING
26from waeup.fceokene.interfaces import MessageFactory as _
27from waeup.kofa.browser.interfaces import IPDFCreator
28from waeup.kofa.students.utils import trans
29from waeup.fceokene.interswitch.browser import GATEWAY_AMT
30
31class CustomStudentsUtils(NigeriaStudentsUtils):
32    """A collection of customized methods.
33
34    """
35
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
42    def getReturningData(self, student):
43        """ This method defines what happens after school fee payment
44        of returning students depending on the student's senate verdict.
45        """
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
51        elif cur_verdict in ('C','O'):
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
58        if cur_verdict == 'O':
59            new_session = student['studycourse'].current_session
60        else:
61            new_session = student['studycourse'].current_session + 1
62        return new_session, new_level
63
64    def setPaymentDetails(self, category, student,
65            previous_session=None, previous_level=None):
66        """Create Payment object and set the payment data of a student for
67        the payment category specified.
68
69        """
70        details = {}
71        p_item = u''
72        amount = 0.0
73        error = u''
74        if previous_session:
75            return _('Previous session payment not yet implemented.'), None
76        p_session = student['studycourse'].current_session
77        p_level = student['studycourse'].current_level
78        p_current = True
79        academic_session = self._getSessionConfiguration(p_session)
80        if academic_session == None:
81            return _(u'Session configuration object is not available.'), None
82        # Determine fee.
83        if category == 'transfer':
84            amount = academic_session.transfer_fee
85        elif category == 'gown':
86            amount = academic_session.gown_fee
87        elif category == 'bed_allocation':
88            amount = academic_session.booking_fee
89        elif category == 'hostel_maintenance':
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
99            if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft':
100                amount = 2500.0 #removed interswitch fee
101            else:
102                amount = 4000.0 #removed interswitch fee
103        elif category == 'clearance':
104            amount = academic_session.clearance_fee
105            try:
106                p_item = student['studycourse'].certificate.code
107            except (AttributeError, TypeError):
108                return _('Study course data are incomplete.'), None
109        elif category == 'schoolfee':
110            try:
111                certificate = student['studycourse'].certificate
112                p_item = certificate.code
113            except (AttributeError, TypeError):
114                return _('Study course data are incomplete.'), None
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
125            if student.state not in (CLEARED, RETURNING):
126                return _('Wrong state.'), None
127
128            # NCE-III repeater
129            if student.current_verdict == 'O':
130                amount = 20150
131            # PDE
132            elif student.current_mode == 'pd_ft':
133                amount = 35000
134            # UG
135            elif student.current_mode == 'ug_ft':
136                amount = 65650
137            # NCE
138            elif not student.current_mode.endswith('_sw'):
139                # PRENCE
140                if student.current_level == 10 and student.state == CLEARED:
141                    if student.depcode in ARTS:
142                        amount = 14900
143                    else:
144                        amount = 15400
145                # NCE I fresh
146                elif student.current_level == 100 and student.state == CLEARED:
147                    if student.depcode in ARTS:
148                        amount = 12020
149                    else:
150                        amount = 12495
151                # NCE II
152                elif student.current_level in (100, 110, 120) and \
153                    student.state == RETURNING:
154                    if student.depcode in ARTS:
155                        amount = 11070
156                    else:
157                        amount = 11545
158                # NCE III
159                elif student.current_level in (200, 210, 220):
160                    if student.depcode in ARTS:
161                        amount = 11070
162                    else:
163                        amount = 11545
164                # NCE III repeater
165                elif student.current_level in (300, 310, 320) and \
166                    student.current_verdict == 'O':
167                    if student.depcode in ARTS:
168                        amount = 6535
169                    else:
170                        amount = 6773
171                # NCE III spillover
172                elif student.current_level in (300, 310, 320) and \
173                    student.current_verdict == 'B':
174                    if student.depcode in ARTS:
175                        amount = 9170
176                    else:
177                        amount = 9645
178                # NCE III second spillover
179                elif student.current_level in (400, 410, 420) and \
180                    student.current_verdict == 'B':
181                    if student.depcode in ARTS:
182                        amount = 9170
183                    else:
184                        amount = 9645
185            else:
186                if student.current_level == 100 and student.state == CLEARED:
187                    if student.depcode in ARTS:
188                        amount = 21900
189                    else:
190                        amount = 22400
191                # NCE II sw
192                elif student.current_level in (100, 110, 120) and \
193                    student.state == RETURNING:
194                    if student.depcode in ARTS:
195                        amount = 18400
196                    else:
197                        amount = 18900
198                # NCE III sw
199                elif student.current_level in (200, 210, 220):
200                    if student.depcode in ARTS:
201                        amount = 20400
202                    else:
203                        amount = 20900
204                # NCE IV sw
205                elif student.current_level in (300, 310, 320):
206                    if student.depcode in ARTS:
207                        amount = 18400
208                    else:
209                        amount = 18900
210                # NCE V sw
211                elif student.current_level in (400, 410, 420):
212                    if student.depcode in ARTS:
213                        amount = 18400
214                    else:
215                        amount = 18900
216                # NCE V spillover sw
217                elif student.current_level in (500, 510, 520) and \
218                    student.current_verdict == 'B':
219                    if student.depcode in ARTS:
220                        amount = 16900
221                    else:
222                        amount = 17400
223                # NCE V second spillover sw
224                elif student.current_level in (600, 610, 620) and \
225                    student.current_verdict == 'B':
226                    if student.depcode in ARTS:
227                        amount = 16900
228                    else:
229                        amount = 17400
230            # NCE student payment can be disabled by
231            # setting the base school fee to -1
232            if academic_session.school_fee_base == -1 and \
233                student.current_mode.startswith('nce'):
234                return _(u'School fee payment is disabled.'), None
235            if student.state == RETURNING:
236                # Override p_session and p_level
237                p_session, p_level = self.getReturningData(student)
238                academic_session = self._getSessionConfiguration(p_session)
239                if academic_session == None:
240                    return _(u'Session configuration object is not available.'), None
241
242        if amount in (0.0, None):
243            return _(u'Amount could not be determined.'), None
244        for key in student['payments'].keys():
245            ticket = student['payments'][key]
246            if ticket.p_state == 'paid' and\
247               ticket.p_category == category and \
248               ticket.p_item == p_item and \
249               ticket.p_session == p_session:
250                  return _('This type of payment has already been made.'), None
251        payment = createObject(u'waeup.StudentOnlinePayment')
252        timestamp = ("%d" % int(time()*10000))[1:]
253        payment.p_id = "p%s" % timestamp
254        payment.p_category = category
255        payment.p_item = p_item
256        payment.p_session = p_session
257        payment.p_level = p_level
258        payment.p_current = p_current
259        # On June 26, 2013 FCEOkene realized that the Interswitch fee
260        # is deducted from their amount. Therefore, we add this fee here.
261        payment.amount_auth = float(amount) + GATEWAY_AMT
262        return None, payment
263
264    def getAccommodationDetails(self, student):
265        """Determine the accommodation data of a student.
266        """
267        d = {}
268        d['error'] = u''
269        hostels = grok.getSite()['hostels']
270        d['booking_session'] = hostels.accommodation_session
271        d['allowed_states'] = hostels.accommodation_states
272        d['startdate'] = hostels.startdate
273        d['enddate'] = hostels.enddate
274        d['expired'] = hostels.expired
275        # Determine bed type
276        studycourse = student['studycourse']
277        certificate = getattr(studycourse,'certificate',None)
278        current_level = studycourse.current_level
279        if None in (current_level, certificate):
280            return d
281        end_level = certificate.end_level
282        if current_level == 10:
283            bt = 'pr'
284        elif current_level == 100:
285            bt = 'fr'
286        elif current_level >= 300:
287            bt = 'fi'
288        else:
289            bt = 're'
290        if student.sex == 'f':
291            sex = 'female'
292        else:
293            sex = 'male'
294        special_handling = 'regular'
295        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
296        return d
297
298    def maxCredits(self, studylevel):
299        """Return maximum credits.
300
301        """
302        return 58
303
304    def getPDFCreator(self, context):
305        """Get a pdf creator suitable for `context`.
306
307        The default implementation always returns the default creator.
308        """
309        mode = getattr(context, 'current_mode', None)
310        if mode and mode.startswith('ug'):
311            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
312        return getUtility(IPDFCreator)
313
314    def _admissionText(self, student, portal_language):
315        mode = getattr(student, 'current_mode', None)
316        if mode and mode.startswith('ug'):
317            text = trans(_(
318                'With reference to your application for admission into Bachelor Degree '
319                'Programme of the University of Ibadan, this is to inform you that you have '
320                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
321                'Education Degree Programme as follows:'),
322                portal_language)
323        else:
324            inst_name = grok.getSite()['configuration'].name
325            text = trans(_(
326                'This is to inform you that you have been provisionally'
327                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
328                portal_language)
329        return text
330
331    def getBedCoordinates(self, bedticket):
332        """Return bed coordinates.
333
334        Bed coordinates are invisible in FCEOkene.
335        """
336        return _('(see payment slip)')
337
338    SEPARATORS_DICT = {
339        'form.fst_sit_fname': _(u'First Sitting Record'),
340        'form.scd_sit_fname': _(u'Second Sitting Record'),
341        #'form.alr_fname': _(u'Advanced Level Record'),
342        'form.hq_type': _(u'Advanced Level Record'),
343        'form.hq2_type': _(u'Second Higher Education Record'),
344        'form.nysc_year': _(u'NYSC Information'),
345        'form.employer': _(u'Employment History'),
346        'form.former_matric': _(u'Former Student'),
347        }
348
349    SKIP_UPLOAD_VIEWLETS = (
350        'higherqualificationresultupload',
351        'secondHigherqualificationresultupload',
352        'certificateupload',
353        'secondcertificateupload',
354        'thirdcertificateupload',
355        'resultstatementupload',
356        'secondrefereeletterupload',
357        'thirdrefereeletterupload',)
358
359    # FCEOkene prefix
360    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.