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

Last change on this file since 13785 was 13779, checked in by Henrik Bettermann, 9 years ago

Consider ug_ft repeater school fee.

  • Property svn:keywords set to Id
File size: 16.0 KB
Line 
1## $Id: utils.py 13779 2016-03-15 12:11:52Z 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 CLEARED, RETURNING, PAID
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from waeup.kofa.accesscodes import create_accesscode
25from waeup.kofa.interfaces import CLEARED, RETURNING
26from waeup.fceokene.interfaces import MessageFactory as _
27from waeup.kofa.browser.interfaces import IPDFCreator
28from waeup.kofa.students.utils import trans
29from waeup.fceokene.interswitch.browser import GATEWAY_AMT
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
40class CustomStudentsUtils(NigeriaStudentsUtils):
41    """A collection of customized methods.
42
43    """
44
45    def selectBed(self, available_beds, desired_hostel):
46        """Randomly select a bed from the list of available beds.
47        """
48        return random.choice(available_beds)
49
50    def getReturningData(self, student):
51        """ This method defines what happens after school fee payment
52        of returning students depending on the student's senate verdict.
53        """
54        prev_level = student['studycourse'].current_level
55        cur_verdict = student['studycourse'].current_verdict
56        if cur_verdict in ('A','B','L','M','N','Z',):
57            # Successful student
58            new_level = divmod(int(prev_level),100)[0]*100 + 100
59        elif cur_verdict in ('C','O'):
60            # Student on probation
61            new_level = int(prev_level) + 10
62        else:
63            # Student is somehow in an undefined state.
64            # Level has to be set manually.
65            new_level = prev_level
66        if cur_verdict == 'O':
67            new_session = student['studycourse'].current_session
68        else:
69            new_session = student['studycourse'].current_session + 1
70        return new_session, new_level
71
72    def setPaymentDetails(self, category, student,
73            previous_session=None, previous_level=None):
74        """Create Payment object and set the payment data of a student for
75        the payment category specified.
76
77        """
78        details = {}
79        p_item = u''
80        amount = 0.0
81        error = u''
82        if previous_session:
83            return _('Previous session payment not yet implemented.'), None
84        p_session = student['studycourse'].current_session
85        p_level = student['studycourse'].current_level
86        p_current = True
87        academic_session = self._getSessionConfiguration(p_session)
88        if academic_session == None:
89            return _(u'Session configuration object is not available.'), None
90        # Determine fee.
91        if category == 'transfer':
92            amount = academic_session.transfer_fee
93        elif category == 'gown':
94            amount = academic_session.gown_fee
95        elif category == 'bed_allocation':
96            amount = academic_session.booking_fee
97        elif category == 'hostel_maintenance':
98            current_session = student['studycourse'].current_session
99            bedticket = student['accommodation'].get(str(current_session), None)
100            if bedticket is not None and bedticket.bed is not None:
101                p_item = bedticket.bed_coordinates
102                if bedticket.bed.__parent__.maint_fee > 0:
103                    amount = bedticket.bed.__parent__.maint_fee
104            else:
105                return _(u'No bed space allocated.'), None
106            if student.current_mode.endswith('_sw') \
107                or student.current_mode == 'pd_ft':
108                amount *= 0.625
109        elif category == 'clearance':
110            amount = academic_session.clearance_fee
111            try:
112                p_item = student['studycourse'].certificate.code
113            except (AttributeError, TypeError):
114                return _('Study course data are incomplete.'), None
115        elif category == 'third_semester' and student.current_mode == 'nce_ft':
116            if student.depcode in ARTS:
117                amount = 6835
118            else:
119                amount = 7763
120        elif category == 'schoolfee':
121            p_item =  student.certcode
122            if not p_item:
123                return _('Study course data are incomplete.'), None
124
125            if student.state not in (CLEARED, RETURNING):
126                return _('Wrong state.'), None
127
128            # PDE repeater
129            if student.current_verdict == 'OPDE':
130                amount = 23000
131            # PDE new
132            elif student.current_mode == 'pd_ft' and student.state == CLEARED:
133                amount = 70300
134            # PDE
135            elif student.current_mode == 'pd_ft':
136                amount = 35300
137
138            #Short Duration ICT Programs
139            elif p_item in ('CCO','DPMTS','DTPGD') and \
140                 student.state == CLEARED:
141                amount = 15000
142            elif p_item in ('ADTPGD','ADPMTS') and \
143                 student.state == CLEARED:
144                amount = 16000
145            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
146                 student.state == CLEARED:
147                amount = 25000
148            elif p_item in ('ADPMTSA','ADTPGDA') and \
149               student.state == CLEARED:
150                amount = 35000
151
152            # UG
153            elif student.current_mode == 'ug_ft':
154                if student.state == CLEARED:
155                    amount = 65650
156                # Introducing repeater fee for 'ug_ft' for 1st time
157                # on 15/03/2016
158                elif student.current_verdict == 'O':
159                    amount = 56150
160                else:
161                    amount = 61150 #added 5000 late registration fee on 13-03-2016
162            # NCE
163            elif not student.current_mode.endswith('_sw'):
164                # PRENCE
165                if student.current_level == 10 and student.state == CLEARED:
166                    if student.depcode in ARTS:
167                        amount = 17500
168                    else:
169                        amount = 18000
170                # NCE I fresh
171                elif student.current_level == 100 and student.state == CLEARED:
172                    if student.depcode in ARTS:
173                        amount = 14325
174                    else:
175                        amount = 14825
176                # NCE II
177                elif student.current_level in (100, 110, 120) and \
178                    student.state == RETURNING:
179                    if student.depcode in ARTS:
180                        amount = 13375
181                    else:
182                        amount = 13875
183                # NCE III
184                elif student.current_level in (200, 210, 220):
185                    if student.depcode in ARTS:
186                        amount = 13375
187                    else:
188                        amount = 13875
189                # NCE III repeater
190                elif student.current_level in (300, 310, 320) and \
191                    student.current_verdict == 'O':
192                    if student.depcode in ARTS:
193                        amount = 11475
194                    else:
195                        amount = 11975
196                # NCE III spillover
197                elif student.current_level in (300, 310, 320) and \
198                    student.current_verdict == 'B':
199                    if student.depcode in ARTS:
200                        amount = 11975
201                    else:
202                        amount = 11975
203                # NCE III second spillover
204                elif student.current_level in (400, 410, 420) and \
205                    student.current_verdict == 'B':
206                    if student.depcode in ARTS:
207                        amount = 11975
208                    else:
209                        amount = 11975
210            else:
211                if student.current_level == 100 and student.state == CLEARED:
212                    if student.depcode in ARTS:
213                        amount = 22500
214                    else:
215                        amount = 23000
216                # NCE II sw
217                elif student.current_level in (100, 110, 120) and \
218                    student.state == RETURNING:
219                    if student.depcode in ARTS:
220                        amount = 19000
221                    else:
222                        amount = 19500
223                # NCE III sw
224                elif student.current_level in (200, 210, 220):
225                    if student.depcode in ARTS:
226                        amount = 21000
227                    else:
228                        amount = 21000
229                # NCE IV sw
230                elif student.current_level in (300, 310, 320):
231                    if student.depcode in ARTS:
232                        amount = 19000
233                    else:
234                        amount = 19500
235                # NCE V sw
236                elif student.current_level in (400, 410, 420):
237                    if student.depcode in ARTS:
238                        amount = 19000
239                    else:
240                        amount = 19500
241                # NCE V spillover sw
242                elif student.current_level in (500, 510, 520) and \
243                    student.current_verdict == 'B':
244                    if student.depcode in ARTS:
245                        amount = 17500
246                    else:
247                        amount = 18000
248                # NCE V second spillover sw
249                elif student.current_level in (600, 610, 620) and \
250                    student.current_verdict == 'B':
251                    if student.depcode in ARTS:
252                        amount = 17500
253                    else:
254                        amount = 18000
255            # NCE student payment can be disabled by
256            # setting the base school fee to -1
257            if academic_session.school_fee_base == -1 and \
258                student.current_mode.startswith('nce'):
259                return _(u'School fee payment is disabled.'), None
260            if student.state == RETURNING:
261                # Override p_session and p_level
262                p_session, p_level = self.getReturningData(student)
263                academic_session = self._getSessionConfiguration(p_session)
264                if academic_session == None:
265                    return _(u'Session configuration object is not available.'), None
266
267        if amount in (0.0, None):
268            return _(u'Amount could not be determined.'), None
269        if self.samePaymentMade(student, category, p_item, p_session):
270            return _('This type of payment has already been made.'), None
271        if self._isPaymentDisabled(p_session, category, student):
272            return _('Payment temporarily disabled.'), None
273        payment = createObject(u'waeup.StudentOnlinePayment')
274        timestamp = ("%d" % int(time()*10000))[1:]
275        payment.p_id = "p%s" % timestamp
276        payment.p_category = category
277        payment.p_item = p_item
278        payment.p_session = p_session
279        payment.p_level = p_level
280        payment.p_current = p_current
281        # On June 26, 2013 FCEOkene realized that the Interswitch fee
282        # is deducted from their amount. Therefore, we add this fee here.
283        payment.amount_auth = float(amount) + GATEWAY_AMT
284        return None, payment
285
286    def getAccommodationDetails(self, student):
287        """Determine the accommodation data of a student.
288        """
289        d = {}
290        d['error'] = u''
291        hostels = grok.getSite()['hostels']
292        d['booking_session'] = hostels.accommodation_session
293        d['allowed_states'] = hostels.accommodation_states
294        d['startdate'] = hostels.startdate
295        d['enddate'] = hostels.enddate
296        d['expired'] = hostels.expired
297        # Determine bed type
298        studycourse = student['studycourse']
299        certificate = getattr(studycourse,'certificate',None)
300        current_level = studycourse.current_level
301        if None in (current_level, certificate):
302            return d
303        end_level = certificate.end_level
304        if current_level == 10:
305            bt = 'pr'
306        elif current_level == 100:
307            bt = 'fr'
308        elif current_level >= 300:
309            bt = 'fi'
310        else:
311            bt = 're'
312        if student.sex == 'f':
313            sex = 'female'
314        else:
315            sex = 'male'
316        special_handling = 'regular'
317        if certificate.study_mode == 'ug_ft':
318            special_handling = 'ugft'
319        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
320        return d
321
322    def maxCredits(self, studylevel):
323        """Return maximum credits.
324
325        """
326        return 58
327
328    def getPDFCreator(self, context):
329        """Get a pdf creator suitable for `context`.
330
331        The default implementation always returns the default creator.
332        """
333        mode = getattr(context, 'current_mode', None)
334        if mode and mode.startswith('ug'):
335            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
336        return getUtility(IPDFCreator)
337
338    def _admissionText(self, student, portal_language):
339        mode = getattr(student, 'current_mode', None)
340        if mode and mode.startswith('ug'):
341            text = trans(_(
342                'With reference to your application for admission into Bachelor Degree '
343                'Programme of the University of Ibadan, this is to inform you that you have '
344                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
345                'Education Degree Programme as follows:'),
346                portal_language)
347        else:
348            inst_name = grok.getSite()['configuration'].name
349            text = trans(_(
350                'This is to inform you that you have been provisionally'
351                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
352                portal_language)
353        return text
354
355    def getBedCoordinates(self, bedticket):
356        """Return bed coordinates.
357
358        Bed coordinates are invisible in FCEOkene.
359        """
360        return _('(see payment slip)')
361
362    def _isPaymentDisabled(self, p_session, category, student):
363        academic_session = self._getSessionConfiguration(p_session)
364        if category == 'schoolfee':
365            if 'sf_all' in academic_session.payment_disabled:
366                return True
367            if 'sf_nce1' in academic_session.payment_disabled and \
368                student.current_level == 100 and student.state == CLEARED and \
369                student.current_mode == 'nce_ft':
370                return True
371        return False
372
373    SEPARATORS_DICT = {
374        'form.fst_sit_fname': _(u'First Sitting Record'),
375        'form.scd_sit_fname': _(u'Second Sitting Record'),
376        #'form.alr_fname': _(u'Advanced Level Record'),
377        'form.hq_type': _(u'Advanced Level Record'),
378        'form.hq2_type': _(u'Second Higher Education Record'),
379        'form.nysc_year': _(u'NYSC Information'),
380        'form.employer': _(u'Employment History'),
381        'form.former_matric': _(u'Former Student'),
382        }
383
384    SKIP_UPLOAD_VIEWLETS = (
385        'higherqualificationresultupload',
386        'secondHigherqualificationresultupload',
387        'certificateupload',
388        'secondcertificateupload',
389        'thirdcertificateupload',
390        'resultstatementupload',
391        'secondrefereeletterupload',
392        'thirdrefereeletterupload',)
393
394    # FCEOkene prefix
395    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.