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

Last change on this file since 15185 was 14933, checked in by Henrik Bettermann, 7 years ago

Change PRENCE school fee.

  • Property svn:keywords set to Id
File size: 20.2 KB
Line 
1## $Id: utils.py 14933 2018-01-06 09:22:44Z 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 (
23    CLEARED, RETURNING, PAID, ADMITTED, CLEARANCE, REQUESTED)
24from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
25from waeup.kofa.accesscodes import create_accesscode
26from waeup.kofa.interfaces import CLEARED, RETURNING
27from waeup.fceokene.interfaces import MessageFactory as _
28from waeup.kofa.browser.interfaces import IPDFCreator
29from waeup.kofa.students.utils import trans
30from waeup.fceokene.interswitch.browser import GATEWAY_AMT
31
32# Very special school fee configuration, should be moved to
33# a seperate file.
34
35ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
36        'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
37        'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
38        'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
39        'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
40
41class CustomStudentsUtils(NigeriaStudentsUtils):
42    """A collection of customized methods.
43
44    """
45
46    def selectBed(self, available_beds, desired_hostel):
47        """Randomly select a bed from the list of available beds.
48        """
49        return random.choice(available_beds)
50
51    def getReturningData(self, student):
52        """ This method defines what happens after school fee payment
53        of returning students depending on the student's senate verdict.
54        """
55        prev_level = student['studycourse'].current_level
56        cur_verdict = student['studycourse'].current_verdict
57        if cur_verdict in ('A','B','L','M','N','Z',):
58            # Successful student
59            new_level = divmod(int(prev_level),100)[0]*100 + 100
60        elif cur_verdict in ('C','O'):
61            # Student on probation
62            new_level = int(prev_level) + 10
63        else:
64            # Student is somehow in an undefined state.
65            # Level has to be set manually.
66            new_level = prev_level
67        if cur_verdict == 'O':
68            new_session = student['studycourse'].current_session
69        else:
70            new_session = student['studycourse'].current_session + 1
71        return new_session, new_level
72
73    def setPaymentDetails(self, category, student,
74            previous_session=None, previous_level=None):
75        """Create Payment object and set the payment data of a student for
76        the payment category specified.
77
78        """
79        details = {}
80        p_item = u''
81        amount = 0.0
82        error = u''
83        if previous_session:
84            return _('Previous session payment not yet implemented.'), None
85        p_session = student['studycourse'].current_session
86        p_level = student['studycourse'].current_level
87        p_current = True
88        academic_session = self._getSessionConfiguration(p_session)
89        if academic_session == None:
90            return _(u'Session configuration object is not available.'), None
91        # Determine fee.
92        if category == 'transfer':
93            amount = academic_session.transfer_fee
94        elif category == 'gown':
95            amount = academic_session.gown_fee
96        elif category == 'bed_allocation':
97            amount = academic_session.booking_fee
98        elif category == 'hostel_maintenance':
99            current_session = student['studycourse'].current_session
100            bedticket = student['accommodation'].get(str(current_session), None)
101            if bedticket is not None and bedticket.bed is not None:
102                p_item = bedticket.bed_coordinates
103                if bedticket.bed.__parent__.maint_fee > 0:
104                    amount = bedticket.bed.__parent__.maint_fee
105            else:
106                return _(u'No bed space allocated.'), None
107            if student.current_mode.endswith('_sw') \
108                or student.current_mode == 'pd_ft':
109                amount *= 0.625
110        elif category == 'clearance':
111            amount = academic_session.clearance_fee
112            try:
113                p_item = student['studycourse'].certificate.code
114            except (AttributeError, TypeError):
115                return _('Study course data are incomplete.'), None
116            if student.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
117                return _(u'Acceptance Fee payments not allowed.'), None
118        elif category == 'third_semester' and student.current_mode == 'nce_ft':
119            if student.depcode in ARTS:
120                amount = 7688
121            else:
122                amount = 7938
123        elif category == 'schoolfee':
124            p_item =  student.certcode
125            if not p_item:
126                return _('Study course data are incomplete.'), None
127
128            if student.state not in (CLEARED, RETURNING):
129                return _('Wrong state.'), None
130
131            # PDE repeater
132            if student.current_verdict == 'OPDE':
133                amount = 23000
134            # PDE new
135            elif student.current_mode == 'pd_ft' and student.state == CLEARED:
136                amount = 70300
137            # PDE
138            elif student.current_mode == 'pd_ft':
139                amount = 35300
140
141            #Short Duration ICT Programs
142            elif p_item in ('CCO','DPMTS','DTPGD') and \
143                 student.state == CLEARED:
144                amount = 15000
145            elif p_item in ('ADTPGD','ADPMTS') and \
146                 student.state == CLEARED:
147                amount = 16000
148            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
149                 student.state == CLEARED:
150                amount = 25000
151            elif p_item in ('ADPMTSA','ADTPGDA') and \
152               student.state == CLEARED:
153                amount = 35000
154
155            # UG
156            elif student.current_mode == 'ug_ft':
157                if student.state == CLEARED:
158                    amount = 65650
159                # Introducing repeater fee for 'ug_ft' for 1st time
160                # on 15/03/2016
161                elif student.current_verdict == 'O':
162                    amount = 56150
163                else:
164                    amount = 56150
165            # NCE
166            elif not student.current_mode.endswith('_sw'):
167                # PRENCE
168                if student.current_level == 10 and student.state == CLEARED:
169                    if student.depcode in ARTS:
170                        amount = 24500
171                    else:
172                        amount = 25000
173                # NCE I fresh
174                elif student.current_level == 100 and student.state == CLEARED:
175                    if student.depcode in ARTS:
176                        amount = 24215
177                    else:
178                        amount = 24915
179                    # SIWES Fee
180                    if student.depcode in ('AGE', 'BED', 'FAA', 'HEC', 'CSC', 'MUS'):
181                        amount += 3000
182                # NCE II
183                elif student.current_level in (100, 110, 120) and \
184                    student.state == RETURNING:
185                    if student.depcode in ARTS:
186                        amount = 15375
187                    else:
188                        amount = 15875
189                    # SIWES Fee
190                    if student.depcode in ('AGE', 'BED', 'FAA', 'HEC', 'CSC', 'MUS'):
191                        amount += 2000
192                # NCE III
193                elif student.current_level in (200, 210, 220):
194                    if student.depcode in ARTS:
195                        amount = 15375
196                    else:
197                        amount = 15875
198                # NCE III repeater
199                elif student.current_level in (300, 310, 320) and \
200                    student.current_verdict == 'O':
201                    if student.depcode in ARTS:
202                        amount = 13475
203                    else:
204                        amount = 13975
205                # NCE III spillover
206                elif student.current_level in (300, 310, 320) and \
207                    student.current_verdict == 'B':
208                    if student.depcode in ARTS:
209                        amount = 13475
210                    else:
211                        amount = 13975
212                # NCE III second spillover
213                elif student.current_level in (400, 410, 420) and \
214                    student.current_verdict == 'B':
215                    if student.depcode in ARTS:
216                        amount = 13475
217                    else:
218                        amount = 13975
219            else:
220                # NCE I fresh sw
221                if student.current_level == 100 and student.state == CLEARED:
222                    if student.depcode in ARTS:
223                        amount = 23100
224                    else:
225                        amount = 23600
226                # NCE II fresh sw
227                elif student.current_level == 200 and student.state == CLEARED:
228                    if student.depcode in ARTS:
229                        amount = 19000
230                    else:
231                        amount = 19500
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 = 21500
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
286        # Add session and level specific penalty fee.
287        if category == 'schoolfee' and student.current_mode in (
288            'ug_ft', 'de_ft') and student.state != CLEARED:
289            amount += academic_session.penalty_ug_ft
290        elif category == 'schoolfee' and student.current_mode in (
291            'nce_ft',) and student['studycourse'].previous_verdict != 'O':
292            # NCE I fresh
293            if student.current_level == 100 and student.state == CLEARED:
294                amount += academic_session.penalty_nce1_ft
295            # NCE II
296            elif student.current_level in (100, 110, 120) and \
297                student.state == RETURNING:
298                amount += academic_session.penalty_nce2_ft
299            # NCE III (except repeaters and spillovers)
300            elif student.current_level in (200, 210, 220):
301                amount += academic_session.penalty_nce3_ft
302        elif category == 'schoolfee' and student.current_mode in ('nce_sw',
303            'nce_pt') and student['studycourse'].previous_verdict != 'O':
304            # NCE I fresh
305            if student.current_level == 100 and student.state == CLEARED:
306                amount += academic_session.penalty_nce1_pt
307            # NCE II
308            elif student.current_level in (100, 110, 120) and \
309                student.state == RETURNING:
310                amount += academic_session.penalty_nce2_pt
311            # NCE III (except repeaters and spillovers)
312            elif student.current_level in (200, 210, 220):
313                amount += academic_session.penalty_nce3_pt
314        elif category == 'schoolfee' and student.current_mode in ('prence',):
315            amount += academic_session.penalty_prence
316        if self.samePaymentMade(student, category, p_item, p_session):
317            return _('This type of payment has already been made.'), None
318        if self._isPaymentDisabled(p_session, category, student):
319            return _('This category of payments has been disabled.'), None
320        payment = createObject(u'waeup.StudentOnlinePayment')
321        timestamp = ("%d" % int(time()*10000))[1:]
322        payment.p_id = "p%s" % timestamp
323        payment.p_category = category
324        payment.p_item = p_item
325        payment.p_session = p_session
326        payment.p_level = p_level
327        payment.p_current = p_current
328        # On June 26, 2013 FCEOkene realized that the Interswitch fee
329        # is deducted from their amount. Therefore, we add this fee here.
330        payment.amount_auth = float(amount) + GATEWAY_AMT
331        return None, payment
332
333    def getAccommodationDetails(self, student):
334        """Determine the accommodation data of a student.
335        """
336        d = {}
337        d['error'] = u''
338        hostels = grok.getSite()['hostels']
339        d['booking_session'] = hostels.accommodation_session
340        d['allowed_states'] = hostels.accommodation_states
341        d['startdate'] = hostels.startdate
342        d['enddate'] = hostels.enddate
343        d['expired'] = hostels.expired
344        # Determine bed type
345        studycourse = student['studycourse']
346        certificate = getattr(studycourse,'certificate',None)
347        current_level = studycourse.current_level
348        if None in (current_level, certificate):
349            return d
350        end_level = certificate.end_level
351        if current_level == 10:
352            bt = 'pr'
353        elif current_level == 100:
354            bt = 'fr'
355        elif current_level >= 300:
356            bt = 'fi'
357        else:
358            bt = 're'
359        if student.sex == 'f':
360            sex = 'female'
361        else:
362            sex = 'male'
363        special_handling = 'regular'
364        if certificate.study_mode == 'ug_ft':
365            special_handling = 'ugft'
366        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
367        return d
368
369    #def warnCreditsOOR(self, studylevel, course=None):
370    #    """Return message if credits are out of range.
371    #    """
372    #    # adding a course ticket
373    #    if course:
374    #        if course.semester == 1:
375    #            if studylevel.total_credits_s1 + course.credits > 24:
376    #                return _('Maximum credits in 1st semester exceeded.')
377    #        if course.semester == 2:
378    #            if studylevel.total_credits_s2 + course.credits > 24:
379    #                return _('Maximum credits in 2nd semester exceeded.')
380    #    # registering course list
381    #    else:
382    #        if studylevel.total_credits_s1 > 24:
383    #            return _('Maximum credits in 1st semester exceeded.')
384    #        if studylevel.total_credits_s1 < 18:
385    #            return _('Minimum credits in 1st semester not reached.')
386    #        if studylevel.total_credits_s2 > 24:
387    #            return _('Maximum credits in 2nd semester exceeded.')
388    #        if studylevel.total_credits_s2 < 18:
389    #            return _('Minimum credits in 2nd semester not reached.')
390    #    return
391
392    def warnCreditsOOR(self, studylevel, course=None):
393        """Return message if credits are out of range.
394        """
395        # adding a course ticket
396        if course:
397            if studylevel.total_credits + course.credits > 52:
398                return _('Maximum credits exceeded.')
399        # registering course list
400        else:
401            if studylevel.total_credits > 52:
402                return _('Maximum credits exceeded.')
403            if studylevel.__parent__.previous_verdict == 'O':
404                return
405            if studylevel.total_credits_s1 < 18:
406                return _('Minimum credits in 1st semester not reached.')
407            if studylevel.total_credits_s2 < 18:
408                return _('Minimum credits in 2nd semester not reached.')
409        return
410
411    def getPDFCreator(self, context):
412        """Get a pdf creator suitable for `context`.
413
414        The default implementation always returns the default creator.
415        """
416        mode = getattr(context, 'current_mode', None)
417        if mode and mode.startswith('ug'):
418            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
419        return getUtility(IPDFCreator)
420
421    def _admissionText(self, student, portal_language):
422        mode = getattr(student, 'current_mode', None)
423        if mode and mode.startswith('ug'):
424            text = trans(_(
425                'With reference to your application for admission into Bachelor Degree '
426                'Programme of the University of Ibadan, this is to inform you that you have '
427                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
428                'Education Degree Programme as follows:'),
429                portal_language)
430        else:
431            inst_name = grok.getSite()['configuration'].name
432            text = trans(_(
433                'This is to inform you that you have been provisionally'
434                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
435                portal_language)
436        return text
437
438    def getBedCoordinates(self, bedticket):
439        """Return bed coordinates.
440
441        Bed coordinates are invisible in FCEOkene.
442        """
443        return _('(see payment slip)')
444
445    def _isPaymentDisabled(self, p_session, category, student):
446        academic_session = self._getSessionConfiguration(p_session)
447        if category == 'schoolfee':
448            if 'sf_all' in academic_session.payment_disabled:
449                return True
450            if 'sf_nce1' in academic_session.payment_disabled and \
451                student.current_level == 100 and student.state == CLEARED and \
452                student.current_mode == 'nce_ft':
453                return True
454        return False
455
456    SEPARATORS_DICT = {
457        'form.fst_sit_fname': _(u'First Sitting Record'),
458        'form.scd_sit_fname': _(u'Second Sitting Record'),
459        #'form.alr_fname': _(u'Advanced Level Record'),
460        'form.hq_type': _(u'Advanced Level Record'),
461        'form.hq2_type': _(u'Second Higher Education Record'),
462        'form.nysc_year': _(u'NYSC Information'),
463        'form.employer': _(u'Employment History'),
464        'form.former_matric': _(u'Former Student'),
465        }
466
467    SKIP_UPLOAD_VIEWLETS = (
468        'higherqualificationresultupload',
469        'secondHigherqualificationresultupload',
470        'certificateupload',
471        'secondcertificateupload',
472        'thirdcertificateupload',
473        'resultstatementupload',
474        'secondrefereeletterupload',
475        'thirdrefereeletterupload',)
476
477    # FCEOkene prefix
478    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.