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

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

Third semester fee applies to nce_ft and not nce_sw.
Increase fees.

  • Property svn:keywords set to Id
File size: 16.0 KB
Line 
1## $Id: utils.py 11932 2014-11-03 12:19:35Z 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
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
40class CustomStudentsUtils(NigeriaStudentsUtils):
41    """A collection of customized methods.
42
43    """
44
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)',
64        #'Z': 'Successful student (provisional)',
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
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
82    def getReturningData(self, student):
83        """ This method defines what happens after school fee payment
84        of returning students depending on the student's senate verdict.
85        """
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
91        elif cur_verdict in ('C','O'):
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
98        if cur_verdict == 'O':
99            new_session = student['studycourse'].current_session
100        else:
101            new_session = student['studycourse'].current_session + 1
102        return new_session, new_level
103
104    def setPaymentDetails(self, category, student,
105            previous_session=None, previous_level=None):
106        """Create Payment object and set the payment data of a student for
107        the payment category specified.
108
109        """
110        details = {}
111        p_item = u''
112        amount = 0.0
113        error = u''
114        if previous_session:
115            return _('Previous session payment not yet implemented.'), None
116        p_session = student['studycourse'].current_session
117        p_level = student['studycourse'].current_level
118        p_current = True
119        academic_session = self._getSessionConfiguration(p_session)
120        if academic_session == None:
121            return _(u'Session configuration object is not available.'), None
122        # Determine fee.
123        if category == 'transfer':
124            amount = academic_session.transfer_fee
125        elif category == 'gown':
126            amount = academic_session.gown_fee
127        elif category == 'bed_allocation':
128            amount = academic_session.booking_fee
129        elif category == 'hostel_maintenance':
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
139            if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft':
140                amount = 2500.0 #removed interswitch fee
141            else:
142                amount = 4000.0 #removed interswitch fee
143        elif category == 'clearance':
144            amount = academic_session.clearance_fee
145            try:
146                p_item = student['studycourse'].certificate.code
147            except (AttributeError, TypeError):
148                return _('Study course data are incomplete.'), None
149        elif category == 'third_semester' and student.current_mode == 'nce_ft':
150            if student.depcode in ARTS:
151                amount = 6835
152            else:
153                amount = 7763
154        elif category == 'schoolfee':
155            try:
156                certificate = student['studycourse'].certificate
157                p_item = certificate.code
158            except (AttributeError, TypeError):
159                return _('Study course data are incomplete.'), None
160
161            if student.state not in (CLEARED, RETURNING):
162                return _('Wrong state.'), None
163
164            # PDE repeater
165            if student.current_verdict == 'OPDE':
166                amount = 23000
167            # PDE
168            elif student.current_mode == 'pd_ft':
169                amount = 35300
170            # UG
171            elif student.current_mode == 'ug_ft':
172            # Introducing returning students fee for 'ug_ft' for 1st time
173            # on 07/01/2014
174                if student.state == CLEARED:
175                    amount = 65650
176                else:
177                    amount = 56150
178            # NCE
179            elif not student.current_mode.endswith('_sw'):
180                # PRENCE
181                if student.current_level == 10 and student.state == CLEARED:
182                    if student.depcode in ARTS:
183                        amount = 15500
184                    else:
185                        amount = 16000
186                # NCE I fresh
187                elif student.current_level == 100 and student.state == CLEARED:
188                    if student.depcode in ARTS:
189                        amount = 12620
190                    else:
191                        amount = 13095
192                # NCE II
193                elif student.current_level in (100, 110, 120) and \
194                    student.state == RETURNING:
195                    if student.depcode in ARTS:
196                        amount = 12100
197                    else:
198                        amount = 12575
199                # NCE III
200                elif student.current_level in (200, 210, 220):
201                    if student.depcode in ARTS:
202                        amount = 12100
203                    else:
204                        amount = 12575
205                # NCE III repeater
206                elif student.current_level in (300, 310, 320) and \
207                    student.current_verdict == 'O':
208                    if student.depcode in ARTS:
209                        amount = 10200
210                    else:
211                        amount = 10675
212                # NCE III spillover
213                elif student.current_level in (300, 310, 320) and \
214                    student.current_verdict == 'B':
215                    if student.depcode in ARTS:
216                        amount = 9170
217                    else:
218                        amount = 9645
219                # NCE III second spillover
220                elif student.current_level in (400, 410, 420) and \
221                    student.current_verdict == 'B':
222                    if student.depcode in ARTS:
223                        amount = 9170
224                    else:
225                        amount = 9645
226            else:
227                if student.current_level == 100 and student.state == CLEARED:
228                    if student.depcode in ARTS:
229                        amount = 22500
230                    else:
231                        amount = 23000
232                # NCE II sw
233                elif student.current_level in (100, 110, 120) and \
234                    student.state == RETURNING:
235                    if student.depcode in ARTS:
236                        amount = 19000
237                    else:
238                        amount = 19500
239                # NCE III sw
240                elif student.current_level in (200, 210, 220):
241                    if student.depcode in ARTS:
242                        amount = 21000
243                    else:
244                        amount = 21000
245                # NCE IV sw
246                elif student.current_level in (300, 310, 320):
247                    if student.depcode in ARTS:
248                        amount = 19000
249                    else:
250                        amount = 19500
251                # NCE V sw
252                elif student.current_level in (400, 410, 420):
253                    if student.depcode in ARTS:
254                        amount = 19000
255                    else:
256                        amount = 19500
257                # NCE V spillover sw
258                elif student.current_level in (500, 510, 520) and \
259                    student.current_verdict == 'B':
260                    if student.depcode in ARTS:
261                        amount = 17500
262                    else:
263                        amount = 18000
264                # NCE V second spillover sw
265                elif student.current_level in (600, 610, 620) and \
266                    student.current_verdict == 'B':
267                    if student.depcode in ARTS:
268                        amount = 17500
269                    else:
270                        amount = 18000
271            # NCE student payment can be disabled by
272            # setting the base school fee to -1
273            if academic_session.school_fee_base == -1 and \
274                student.current_mode.startswith('nce'):
275                return _(u'School fee payment is disabled.'), None
276            if student.state == RETURNING:
277                # Override p_session and p_level
278                p_session, p_level = self.getReturningData(student)
279                academic_session = self._getSessionConfiguration(p_session)
280                if academic_session == None:
281                    return _(u'Session configuration object is not available.'), None
282
283        if amount in (0.0, None):
284            return _(u'Amount could not be determined.'), None
285        if self.samePaymentMade(student, category, p_item, p_session):
286            return _('This type of payment has already been made.'), None
287        if self._isPaymentDisabled(p_session, category, student):
288            return _('Payment temporarily disabled.'), None
289        payment = createObject(u'waeup.StudentOnlinePayment')
290        timestamp = ("%d" % int(time()*10000))[1:]
291        payment.p_id = "p%s" % timestamp
292        payment.p_category = category
293        payment.p_item = p_item
294        payment.p_session = p_session
295        payment.p_level = p_level
296        payment.p_current = p_current
297        # On June 26, 2013 FCEOkene realized that the Interswitch fee
298        # is deducted from their amount. Therefore, we add this fee here.
299        payment.amount_auth = float(amount) + GATEWAY_AMT
300        return None, payment
301
302    def getAccommodationDetails(self, student):
303        """Determine the accommodation data of a student.
304        """
305        d = {}
306        d['error'] = u''
307        hostels = grok.getSite()['hostels']
308        d['booking_session'] = hostels.accommodation_session
309        d['allowed_states'] = hostels.accommodation_states
310        d['startdate'] = hostels.startdate
311        d['enddate'] = hostels.enddate
312        d['expired'] = hostels.expired
313        # Determine bed type
314        studycourse = student['studycourse']
315        certificate = getattr(studycourse,'certificate',None)
316        current_level = studycourse.current_level
317        if None in (current_level, certificate):
318            return d
319        end_level = certificate.end_level
320        if current_level == 10:
321            bt = 'pr'
322        elif current_level == 100:
323            bt = 'fr'
324        elif current_level >= 300:
325            bt = 'fi'
326        else:
327            bt = 're'
328        if student.sex == 'f':
329            sex = 'female'
330        else:
331            sex = 'male'
332        special_handling = 'regular'
333        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
334        return d
335
336    def maxCredits(self, studylevel):
337        """Return maximum credits.
338
339        """
340        return 58
341
342    def getPDFCreator(self, context):
343        """Get a pdf creator suitable for `context`.
344
345        The default implementation always returns the default creator.
346        """
347        mode = getattr(context, 'current_mode', None)
348        if mode and mode.startswith('ug'):
349            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
350        return getUtility(IPDFCreator)
351
352    def _admissionText(self, student, portal_language):
353        mode = getattr(student, 'current_mode', None)
354        if mode and mode.startswith('ug'):
355            text = trans(_(
356                'With reference to your application for admission into Bachelor Degree '
357                'Programme of the University of Ibadan, this is to inform you that you have '
358                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
359                'Education Degree Programme as follows:'),
360                portal_language)
361        else:
362            inst_name = grok.getSite()['configuration'].name
363            text = trans(_(
364                'This is to inform you that you have been provisionally'
365                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
366                portal_language)
367        return text
368
369    def getBedCoordinates(self, bedticket):
370        """Return bed coordinates.
371
372        Bed coordinates are invisible in FCEOkene.
373        """
374        return _('(see payment slip)')
375
376    SEPARATORS_DICT = {
377        'form.fst_sit_fname': _(u'First Sitting Record'),
378        'form.scd_sit_fname': _(u'Second Sitting Record'),
379        #'form.alr_fname': _(u'Advanced Level Record'),
380        'form.hq_type': _(u'Advanced Level Record'),
381        'form.hq2_type': _(u'Second Higher Education Record'),
382        'form.nysc_year': _(u'NYSC Information'),
383        'form.employer': _(u'Employment History'),
384        'form.former_matric': _(u'Former Student'),
385        }
386
387    SKIP_UPLOAD_VIEWLETS = (
388        'higherqualificationresultupload',
389        'secondHigherqualificationresultupload',
390        'certificateupload',
391        'secondcertificateupload',
392        'thirdcertificateupload',
393        'resultstatementupload',
394        'secondrefereeletterupload',
395        'thirdrefereeletterupload',)
396
397    # FCEOkene prefix
398    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.