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

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

Check if bed has been booked and save bed coordinates in payment ticket.

  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1## $Id: utils.py 9611 2012-11-10 21:02:02Z 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            current_session = student['studycourse'].current_session
85            bedticket = student['accommodation'].get(str(current_session), None)
86            if bedticket is not None and bedticket.bed is not None:
87                p_item = bedticket.bed_coordinates
88            else:
89                return _(u'You have not yet booked accommodation.'), None
90            acc_details = self.getAccommodationDetails(student)
91            if current_session != acc_details['booking_session']:
92                return _(u'Current session does not match accommodation session.'), None
93            amount = academic_session.maint_fee
94        elif category == 'clearance':
95            amount = academic_session.clearance_fee
96            try:
97                p_item = student['studycourse'].certificate.code
98            except (AttributeError, TypeError):
99                return _('Study course data are incomplete.'), None
100        elif category == 'schoolfee':
101            try:
102                certificate = student['studycourse'].certificate
103                p_item = certificate.code
104            except (AttributeError, TypeError):
105                return _('Study course data are incomplete.'), None
106
107            # Very special school fee configuration, should be moved to
108            # a seperate file.
109
110            ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
111                    'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
112                    'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
113                    'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
114                    'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
115
116            #PDE Students
117            if student.current_mode == 'pd_ft':
118                amount = 35000
119            elif not student.current_mode.endswith('_sw'):
120                # PRENCE
121                if student.current_level == 10 and student.state == CLEARED:
122                    if student.depcode in ARTS:
123                        amount = 14900
124                    else:
125                        amount = 15400
126                # NCE I fresh
127                elif student.current_level == 100 and student.state == CLEARED:
128                    if student.depcode in ARTS:
129                        amount = 12020
130                    else:
131                        amount = 12495
132                # NCE II
133                elif student.current_level in (100, 110, 120) and \
134                    student.state == RETURNING:
135                    if student.depcode in ARTS:
136                        amount = 11070
137                    else:
138                        amount = 11545
139                # NCE III
140                elif student.current_level in (200, 210, 220):
141                    if student.depcode in ARTS:
142                        amount = 11070
143                    else:
144                        amount = 11545
145                # NCE III repeater
146                elif student.current_level in (300, 310, 320) and \
147                    student.current_verdict == 'O':
148                    if student.depcode in ARTS:
149                        amount = 6535
150                    else:
151                        amount = 6773
152                # NCE III spillover
153                elif student.current_level in (300, 310, 320) and \
154                    student.current_verdict == 'B':
155                    if student.depcode in ARTS:
156                        amount = 9170
157                    else:
158                        amount = 9645
159                # NCE III second spillover
160                elif student.current_level in (400, 410, 420) and \
161                    student.current_verdict == 'B':
162                    if student.depcode in ARTS:
163                        amount = 9170
164                    else:
165                        amount = 9645
166            else:
167                if student.current_level == 100 and student.state == CLEARED:
168                    if student.depcode in ARTS:
169                        amount = 21900
170                    else:
171                        amount = 22400
172                # NCE II
173                elif student.current_level in (100, 110, 120) and \
174                    student.state == RETURNING:
175                    if student.depcode in ARTS:
176                        amount = 18400
177                    else:
178                        amount = 18900
179                # NCE III
180                elif student.current_level in (200, 210, 220):
181                    if student.depcode in ARTS:
182                        amount = 20400
183                    else:
184                        amount = 20900
185                # NCE IV
186                elif student.current_level in (300, 310, 320):
187                    if student.depcode in ARTS:
188                        amount = 18400
189                    else:
190                        amount = 18900
191                # NCE V
192                elif student.current_level in (400, 410, 420):
193                    if student.depcode in ARTS:
194                        amount = 18400
195                    else:
196                        amount = 18900
197                # NCE V spillover
198                elif student.current_level in (500, 510, 520) and \
199                    student.current_verdict == 'B':
200                    if student.depcode in ARTS:
201                        amount = 16900
202                    else:
203                        amount = 17400
204                # NCE V second spillover
205                elif student.current_level in (600, 610, 620) and \
206                    student.current_verdict == 'B':
207                    if student.depcode in ARTS:
208                        amount = 16900
209                    else:
210                        amount = 17400
211            if student.state == RETURNING:
212                # Override p_session and p_level
213                p_session, p_level = self.getReturningData(student)
214                academic_session = self._getSessionConfiguration(p_session)
215                if academic_session == None:
216                    return _(u'Session configuration object is not available.'), None
217
218        if amount in (0.0, None):
219            return _(u'Amount could not be determined.'), None
220        for key in student['payments'].keys():
221            ticket = student['payments'][key]
222            if ticket.p_state == 'paid' and\
223               ticket.p_category == category and \
224               ticket.p_item == p_item and \
225               ticket.p_session == p_session:
226                  return _('This type of payment has already been made.'), None
227        payment = createObject(u'waeup.StudentOnlinePayment')
228        timestamp = ("%d" % int(time()*10000))[1:]
229        payment.p_id = "p%s" % timestamp
230        payment.p_category = category
231        payment.p_item = p_item
232        payment.p_session = p_session
233        payment.p_level = p_level
234        payment.p_current = p_current
235        payment.amount_auth = float(amount)
236        return None, payment
237
238    def getAccommodationDetails(self, student):
239        """Determine the accommodation data of a student.
240        """
241        d = {}
242        d['error'] = u''
243        hostels = grok.getSite()['hostels']
244        d['booking_session'] = hostels.accommodation_session
245        d['allowed_states'] = hostels.accommodation_states
246        d['startdate'] = hostels.startdate
247        d['enddate'] = hostels.enddate
248        d['expired'] = hostels.expired
249        # Determine bed type
250        studycourse = student['studycourse']
251        certificate = getattr(studycourse,'certificate',None)
252        current_level = studycourse.current_level
253        if None in (current_level, certificate):
254            return d
255        end_level = certificate.end_level
256        if current_level == 10:
257            bt = 'pr'
258        elif current_level == 100:
259            bt = 'fr'
260        elif current_level >= 300:
261            bt = 'fi'
262        else:
263            bt = 're'
264        if student.sex == 'f':
265            sex = 'female'
266        else:
267            sex = 'male'
268        special_handling = 'regular'
269        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
270        return d
271
272    # FCEOkene prefix
273    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.