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

Last change on this file since 16887 was 16887, checked in by Henrik Bettermann, 3 years ago

Add more third semester payment categories.

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