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

Last change on this file since 17501 was 17501, checked in by Henrik Bettermann, 16 months ago

Do not just charge the increment.

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