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

Last change on this file since 15283 was 15283, checked in by Henrik Bettermann, 6 years ago

Change fees.

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