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

Last change on this file since 17178 was 17178, checked in by Henrik Bettermann, 22 months ago

Increase accommodation span.

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