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

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

Adjust to changes made in base package.

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