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

Last change on this file since 9951 was 9950, checked in by Henrik Bettermann, 12 years ago

Define another (named) PDFCreator for Okene/Ibadan? certificates and render logos on pdf slips depending on study_mode.

  • Property svn:keywords set to Id
File size: 12.0 KB
RevLine 
[7419]1## $Id: utils.py 9950 2013-02-15 06:54:39Z 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##
[7151]18import grok
[9190]19import random
[8599]20from time import time
[9950]21from zope.component import createObject, getUtility
[8475]22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
[8834]23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]24from waeup.kofa.accesscodes import create_accesscode
[9143]25from waeup.kofa.interfaces import CLEARED, RETURNING
[8460]26from waeup.fceokene.interfaces import MessageFactory as _
[9950]27from waeup.kofa.browser.interfaces import IPDFCreator
[6902]28
[8834]29class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]30    """A collection of customized methods.
31
32    """
33
[9190]34    def selectBed(self, available_beds):
35        """Randomly select a bed from a list of available beds.
36
37        """
38        return random.choice(available_beds)
39
[8270]40    def getReturningData(self, student):
41        """ This method defines what happens after school fee payment
[8319]42        of returning students depending on the student's senate verdict.
[8270]43        """
[8319]44        prev_level = student['studycourse'].current_level
45        cur_verdict = student['studycourse'].current_verdict
46        if cur_verdict in ('A','B','L','M','N','Z',):
47            # Successful student
48            new_level = divmod(int(prev_level),100)[0]*100 + 100
[9923]49        elif cur_verdict in ('C','O'):
[8319]50            # Student on probation
51            new_level = int(prev_level) + 10
52        else:
53            # Student is somehow in an undefined state.
54            # Level has to be set manually.
55            new_level = prev_level
[9923]56        if cur_verdict == 'O':
57            new_session = student['studycourse'].current_session
58        else:
59            new_session = student['studycourse'].current_session + 1
[8270]60        return new_session, new_level
61
[9153]62    def setPaymentDetails(self, category, student,
63            previous_session=None, previous_level=None):
[8599]64        """Create Payment object and set the payment data of a student for
65        the payment category specified.
66
67        """
[8306]68        details = {}
[8599]69        p_item = u''
70        amount = 0.0
71        error = u''
[9153]72        if previous_session:
73            return _('Previous session payment not yet implemented.'), None
[8599]74        p_session = student['studycourse'].current_session
75        p_level = student['studycourse'].current_level
[9153]76        p_current = True
[9525]77        academic_session = self._getSessionConfiguration(p_session)
78        if academic_session == None:
[8599]79            return _(u'Session configuration object is not available.'), None
[9525]80        # Determine fee.
[7151]81        if category == 'transfer':
[8599]82            amount = academic_session.transfer_fee
[7151]83        elif category == 'gown':
[8599]84            amount = academic_session.gown_fee
[7151]85        elif category == 'bed_allocation':
[8599]86            amount = academic_session.booking_fee
[7151]87        elif category == 'hostel_maintenance':
[9611]88            current_session = student['studycourse'].current_session
89            bedticket = student['accommodation'].get(str(current_session), None)
90            if bedticket is not None and bedticket.bed is not None:
91                p_item = bedticket.bed_coordinates
92            else:
93                return _(u'You have not yet booked accommodation.'), None
94            acc_details = self.getAccommodationDetails(student)
95            if current_session != acc_details['booking_session']:
96                return _(u'Current session does not match accommodation session.'), None
[9612]97            if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft':
[9629]98                amount = 2650.0
[9612]99            else:
[9628]100                amount = 4150.0
[7151]101        elif category == 'clearance':
[9143]102            amount = academic_session.clearance_fee
[8599]103            try:
104                p_item = student['studycourse'].certificate.code
105            except (AttributeError, TypeError):
106                return _('Study course data are incomplete.'), None
[7151]107        elif category == 'schoolfee':
[8599]108            try:
109                certificate = student['studycourse'].certificate
110                p_item = certificate.code
111            except (AttributeError, TypeError):
112                return _('Study course data are incomplete.'), None
[9143]113
114            # Very special school fee configuration, should be moved to
115            # a seperate file.
116
117            ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
118                    'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
119                    'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
120                    'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
121                    'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
122
123            #PDE Students
124            if student.current_mode == 'pd_ft':
125                amount = 35000
126            elif not student.current_mode.endswith('_sw'):
127                # PRENCE
128                if student.current_level == 10 and student.state == CLEARED:
129                    if student.depcode in ARTS:
130                        amount = 14900
131                    else:
132                        amount = 15400
133                # NCE I fresh
134                elif student.current_level == 100 and student.state == CLEARED:
135                    if student.depcode in ARTS:
136                        amount = 12020
137                    else:
138                        amount = 12495
139                # NCE II
140                elif student.current_level in (100, 110, 120) and \
141                    student.state == RETURNING:
142                    if student.depcode in ARTS:
143                        amount = 11070
144                    else:
145                        amount = 11545
146                # NCE III
147                elif student.current_level in (200, 210, 220):
148                    if student.depcode in ARTS:
149                        amount = 11070
150                    else:
151                        amount = 11545
152                # NCE III repeater
153                elif student.current_level in (300, 310, 320) and \
154                    student.current_verdict == 'O':
155                    if student.depcode in ARTS:
156                        amount = 6535
157                    else:
158                        amount = 6773
159                # NCE III spillover
160                elif student.current_level in (300, 310, 320) and \
161                    student.current_verdict == 'B':
162                    if student.depcode in ARTS:
163                        amount = 9170
164                    else:
165                        amount = 9645
166                # NCE III second spillover
167                elif student.current_level in (400, 410, 420) and \
168                    student.current_verdict == 'B':
169                    if student.depcode in ARTS:
170                        amount = 9170
171                    else:
172                        amount = 9645
173            else:
174                if student.current_level == 100 and student.state == CLEARED:
175                    if student.depcode in ARTS:
176                        amount = 21900
177                    else:
178                        amount = 22400
179                # NCE II
180                elif student.current_level in (100, 110, 120) and \
181                    student.state == RETURNING:
182                    if student.depcode in ARTS:
183                        amount = 18400
184                    else:
185                        amount = 18900
186                # NCE III
187                elif student.current_level in (200, 210, 220):
188                    if student.depcode in ARTS:
189                        amount = 20400
190                    else:
191                        amount = 20900
192                # NCE IV
193                elif student.current_level in (300, 310, 320):
194                    if student.depcode in ARTS:
195                        amount = 18400
196                    else:
197                        amount = 18900
198                # NCE V
199                elif student.current_level in (400, 410, 420):
200                    if student.depcode in ARTS:
201                        amount = 18400
202                    else:
203                        amount = 18900
204                # NCE V spillover
205                elif student.current_level in (500, 510, 520) and \
206                    student.current_verdict == 'B':
207                    if student.depcode in ARTS:
208                        amount = 16900
209                    else:
210                        amount = 17400
211                # NCE V second spillover
212                elif student.current_level in (600, 610, 620) and \
213                    student.current_verdict == 'B':
214                    if student.depcode in ARTS:
215                        amount = 16900
216                    else:
217                        amount = 17400
[9297]218            if student.state == RETURNING:
[9525]219                # Override p_session and p_level
[9297]220                p_session, p_level = self.getReturningData(student)
[9525]221                academic_session = self._getSessionConfiguration(p_session)
222                if academic_session == None:
223                    return _(u'Session configuration object is not available.'), None
[9143]224
[8599]225        if amount in (0.0, None):
226            return _(u'Amount could not be determined.'), None
227        for key in student['payments'].keys():
228            ticket = student['payments'][key]
229            if ticket.p_state == 'paid' and\
230               ticket.p_category == category and \
231               ticket.p_item == p_item and \
232               ticket.p_session == p_session:
233                  return _('This type of payment has already been made.'), None
[8713]234        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]235        timestamp = ("%d" % int(time()*10000))[1:]
[8599]236        payment.p_id = "p%s" % timestamp
237        payment.p_category = category
238        payment.p_item = p_item
239        payment.p_session = p_session
240        payment.p_level = p_level
[9153]241        payment.p_current = p_current
[9143]242        payment.amount_auth = float(amount)
[8599]243        return None, payment
[7621]244
[9207]245    def getAccommodationDetails(self, student):
246        """Determine the accommodation data of a student.
247        """
248        d = {}
249        d['error'] = u''
250        hostels = grok.getSite()['hostels']
251        d['booking_session'] = hostels.accommodation_session
252        d['allowed_states'] = hostels.accommodation_states
253        d['startdate'] = hostels.startdate
254        d['enddate'] = hostels.enddate
255        d['expired'] = hostels.expired
256        # Determine bed type
257        studycourse = student['studycourse']
258        certificate = getattr(studycourse,'certificate',None)
259        current_level = studycourse.current_level
260        if None in (current_level, certificate):
261            return d
262        end_level = certificate.end_level
263        if current_level == 10:
264            bt = 'pr'
265        elif current_level == 100:
266            bt = 'fr'
267        elif current_level >= 300:
268            bt = 'fi'
269        else:
270            bt = 're'
271        if student.sex == 'f':
272            sex = 'female'
273        else:
274            sex = 'male'
275        special_handling = 'regular'
276        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
277        return d
278
[9903]279    def maxCredits(self, studylevel):
280        """Return maximum credits.
281
282        """
283        return 58
284
[9950]285    def getPDFCreator(self, context):
286        """Get a pdf creator suitable for `context`.
287
288        The default implementation always returns the default creator.
289        """
290        mode = getattr(context, 'current_mode', None)
291        if mode and mode.startswith('ug'):
292            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
293        return getUtility(IPDFCreator)
294
[8460]295    # FCEOkene prefix
[8528]296    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.