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

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

Enable verdict Z.

  • Property svn:keywords set to Id
File size: 16.4 KB
Line 
1## $Id: utils.py 12629 2015-02-24 05:56:37Z 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            p_item =  student.certcode
156            if not p_item:
157                return _('Study course data are incomplete.'), None
158
159            if student.state not in (CLEARED, RETURNING):
160                return _('Wrong state.'), None
161
162            # PDE repeater
163            if student.current_verdict == 'OPDE':
164                amount = 23000
165            # PDE
166            elif student.current_mode == 'pd_ft':
167                amount = 35300
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
183            # UG
184            elif student.current_mode == 'ug_ft':
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
191            # NCE
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:
196                        amount = 17500
197                    else:
198                        amount = 18000
199                # NCE I fresh
200                elif student.current_level == 100 and student.state == CLEARED:
201                    if student.depcode in ARTS:
202                        amount = 14325
203                    else:
204                        amount = 14825
205                # NCE II
206                elif student.current_level in (100, 110, 120) and \
207                    student.state == RETURNING:
208                    if student.depcode in ARTS:
209                        amount = 13375
210                    else:
211                        amount = 13875
212                # NCE III
213                elif student.current_level in (200, 210, 220):
214                    if student.depcode in ARTS:
215                        amount = 13375
216                    else:
217                        amount = 13875
218                # NCE III repeater
219                elif student.current_level in (300, 310, 320) and \
220                    student.current_verdict == 'O':
221                    if student.depcode in ARTS:
222                        amount = 11475
223                    else:
224                        amount = 11975
225                # NCE III spillover
226                elif student.current_level in (300, 310, 320) and \
227                    student.current_verdict == 'B':
228                    if student.depcode in ARTS:
229                        amount = 11975
230                    else:
231                        amount = 11975
232                # NCE III second spillover
233                elif student.current_level in (400, 410, 420) and \
234                    student.current_verdict == 'B':
235                    if student.depcode in ARTS:
236                        amount = 11975
237                    else:
238                        amount = 11975
239            else:
240                if student.current_level == 100 and student.state == CLEARED:
241                    if student.depcode in ARTS:
242                        amount = 22500
243                    else:
244                        amount = 23000
245                # NCE II sw
246                elif student.current_level in (100, 110, 120) and \
247                    student.state == RETURNING:
248                    if student.depcode in ARTS:
249                        amount = 19000
250                    else:
251                        amount = 19500
252                # NCE III sw
253                elif student.current_level in (200, 210, 220):
254                    if student.depcode in ARTS:
255                        amount = 21000
256                    else:
257                        amount = 21000
258                # NCE IV sw
259                elif student.current_level in (300, 310, 320):
260                    if student.depcode in ARTS:
261                        amount = 19000
262                    else:
263                        amount = 19500
264                # NCE V sw
265                elif student.current_level in (400, 410, 420):
266                    if student.depcode in ARTS:
267                        amount = 19000
268                    else:
269                        amount = 19500
270                # NCE V spillover sw
271                elif student.current_level in (500, 510, 520) and \
272                    student.current_verdict == 'B':
273                    if student.depcode in ARTS:
274                        amount = 17500
275                    else:
276                        amount = 18000
277                # NCE V second spillover sw
278                elif student.current_level in (600, 610, 620) and \
279                    student.current_verdict == 'B':
280                    if student.depcode in ARTS:
281                        amount = 17500
282                    else:
283                        amount = 18000
284            # NCE student payment can be disabled by
285            # setting the base school fee to -1
286            if academic_session.school_fee_base == -1 and \
287                student.current_mode.startswith('nce'):
288                return _(u'School fee payment is disabled.'), None
289            if student.state == RETURNING:
290                # Override p_session and p_level
291                p_session, p_level = self.getReturningData(student)
292                academic_session = self._getSessionConfiguration(p_session)
293                if academic_session == None:
294                    return _(u'Session configuration object is not available.'), None
295
296        if amount in (0.0, None):
297            return _(u'Amount could not be determined.'), None
298        if self.samePaymentMade(student, category, p_item, p_session):
299            return _('This type of payment has already been made.'), None
300        if self._isPaymentDisabled(p_session, category, student):
301            return _('Payment temporarily disabled.'), None
302        payment = createObject(u'waeup.StudentOnlinePayment')
303        timestamp = ("%d" % int(time()*10000))[1:]
304        payment.p_id = "p%s" % timestamp
305        payment.p_category = category
306        payment.p_item = p_item
307        payment.p_session = p_session
308        payment.p_level = p_level
309        payment.p_current = p_current
310        # On June 26, 2013 FCEOkene realized that the Interswitch fee
311        # is deducted from their amount. Therefore, we add this fee here.
312        payment.amount_auth = float(amount) + GATEWAY_AMT
313        return None, payment
314
315    def getAccommodationDetails(self, student):
316        """Determine the accommodation data of a student.
317        """
318        d = {}
319        d['error'] = u''
320        hostels = grok.getSite()['hostels']
321        d['booking_session'] = hostels.accommodation_session
322        d['allowed_states'] = hostels.accommodation_states
323        d['startdate'] = hostels.startdate
324        d['enddate'] = hostels.enddate
325        d['expired'] = hostels.expired
326        # Determine bed type
327        studycourse = student['studycourse']
328        certificate = getattr(studycourse,'certificate',None)
329        current_level = studycourse.current_level
330        if None in (current_level, certificate):
331            return d
332        end_level = certificate.end_level
333        if current_level == 10:
334            bt = 'pr'
335        elif current_level == 100:
336            bt = 'fr'
337        elif current_level >= 300:
338            bt = 'fi'
339        else:
340            bt = 're'
341        if student.sex == 'f':
342            sex = 'female'
343        else:
344            sex = 'male'
345        special_handling = 'regular'
346        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
347        return d
348
349    def maxCredits(self, studylevel):
350        """Return maximum credits.
351
352        """
353        return 58
354
355    def getPDFCreator(self, context):
356        """Get a pdf creator suitable for `context`.
357
358        The default implementation always returns the default creator.
359        """
360        mode = getattr(context, 'current_mode', None)
361        if mode and mode.startswith('ug'):
362            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
363        return getUtility(IPDFCreator)
364
365    def _admissionText(self, student, portal_language):
366        mode = getattr(student, 'current_mode', None)
367        if mode and mode.startswith('ug'):
368            text = trans(_(
369                'With reference to your application for admission into Bachelor Degree '
370                'Programme of the University of Ibadan, this is to inform you that you have '
371                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
372                'Education Degree Programme as follows:'),
373                portal_language)
374        else:
375            inst_name = grok.getSite()['configuration'].name
376            text = trans(_(
377                'This is to inform you that you have been provisionally'
378                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
379                portal_language)
380        return text
381
382    def getBedCoordinates(self, bedticket):
383        """Return bed coordinates.
384
385        Bed coordinates are invisible in FCEOkene.
386        """
387        return _('(see payment slip)')
388
389    SEPARATORS_DICT = {
390        'form.fst_sit_fname': _(u'First Sitting Record'),
391        'form.scd_sit_fname': _(u'Second Sitting Record'),
392        #'form.alr_fname': _(u'Advanced Level Record'),
393        'form.hq_type': _(u'Advanced Level Record'),
394        'form.hq2_type': _(u'Second Higher Education Record'),
395        'form.nysc_year': _(u'NYSC Information'),
396        'form.employer': _(u'Employment History'),
397        'form.former_matric': _(u'Former Student'),
398        }
399
400    SKIP_UPLOAD_VIEWLETS = (
401        'higherqualificationresultupload',
402        'secondHigherqualificationresultupload',
403        'certificateupload',
404        'secondcertificateupload',
405        'thirdcertificateupload',
406        'resultstatementupload',
407        'secondrefereeletterupload',
408        'thirdrefereeletterupload',)
409
410    # FCEOkene prefix
411    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.