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

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

Change fee again.

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