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

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

Disable acceptance fee payments except for ug_ft.

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