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

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

Revert r16920.

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