source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py @ 9370

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

Disable school fee payment so that no KwaraPoly? student accidentally pays FCEOkene school fees.

  • Property svn:keywords set to Id
File size: 10.4 KB
Line 
1## $Id: utils.py 9370 2012-10-20 19:58:10Z 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.kwarapoly.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        session = str(p_session)
74        try:
75            academic_session = grok.getSite()['configuration'][session]
76        except KeyError:
77            return _(u'Session configuration object is not available.'), None
78        if category == 'transfer':
79            amount = academic_session.transfer_fee
80        elif category == 'gown':
81            amount = academic_session.gown_fee
82        elif category == 'bed_allocation':
83            amount = academic_session.booking_fee
84        elif category == 'hostel_maintenance':
85            amount = academic_session.maint_fee
86        elif category == 'clearance':
87            amount = academic_session.clearance_fee
88            try:
89                p_item = student['studycourse'].certificate.code
90            except (AttributeError, TypeError):
91                return _('Study course data are incomplete.'), None
92        elif category == 'schoolfee':
93            try:
94                certificate = student['studycourse'].certificate
95                p_item = certificate.code
96            except (AttributeError, TypeError):
97                return _('Study course data are incomplete.'), None
98
99            # Very special school fee configuration, should be moved to
100            # a seperate file.
101
102            ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
103                    'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
104                    'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
105                    'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
106                    'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
107
108            #PDE Students
109            if student.current_mode == 'pd_ft':
110                amount = 35000
111            elif not student.current_mode.endswith('_sw'):
112                # PRENCE
113                if student.current_level == 10 and student.state == CLEARED:
114                    if student.depcode in ARTS:
115                        amount = 14900
116                    else:
117                        amount = 15400
118                # NCE I fresh
119                elif student.current_level == 100 and student.state == CLEARED:
120                    if student.depcode in ARTS:
121                        amount = 12020
122                    else:
123                        amount = 12495
124                # NCE II
125                elif student.current_level in (100, 110, 120) and \
126                    student.state == RETURNING:
127                    if student.depcode in ARTS:
128                        amount = 11070
129                    else:
130                        amount = 11545
131                # NCE III
132                elif student.current_level in (200, 210, 220):
133                    if student.depcode in ARTS:
134                        amount = 11070
135                    else:
136                        amount = 11545
137                # NCE III repeater
138                elif student.current_level in (300, 310, 320) and \
139                    student.current_verdict == 'O':
140                    if student.depcode in ARTS:
141                        amount = 6535
142                    else:
143                        amount = 6773
144                # NCE III spillover
145                elif student.current_level in (300, 310, 320) and \
146                    student.current_verdict == 'B':
147                    if student.depcode in ARTS:
148                        amount = 9170
149                    else:
150                        amount = 9645
151                # NCE III second spillover
152                elif student.current_level in (400, 410, 420) and \
153                    student.current_verdict == 'B':
154                    if student.depcode in ARTS:
155                        amount = 9170
156                    else:
157                        amount = 9645
158            else:
159                if student.current_level == 100 and student.state == CLEARED:
160                    if student.depcode in ARTS:
161                        amount = 21900
162                    else:
163                        amount = 22400
164                # NCE II
165                elif student.current_level in (100, 110, 120) and \
166                    student.state == RETURNING:
167                    if student.depcode in ARTS:
168                        amount = 18400
169                    else:
170                        amount = 18900
171                # NCE III
172                elif student.current_level in (200, 210, 220):
173                    if student.depcode in ARTS:
174                        amount = 20400
175                    else:
176                        amount = 20900
177                # NCE IV
178                elif student.current_level in (300, 310, 320):
179                    if student.depcode in ARTS:
180                        amount = 18400
181                    else:
182                        amount = 18900
183                # NCE V
184                elif student.current_level in (400, 410, 420):
185                    if student.depcode in ARTS:
186                        amount = 18400
187                    else:
188                        amount = 18900
189                # NCE V spillover
190                elif student.current_level in (500, 510, 520) and \
191                    student.current_verdict == 'B':
192                    if student.depcode in ARTS:
193                        amount = 16900
194                    else:
195                        amount = 17400
196                # NCE V second spillover
197                elif student.current_level in (600, 610, 620) and \
198                    student.current_verdict == 'B':
199                    if student.depcode in ARTS:
200                        amount = 16900
201                    else:
202                        amount = 17400
203            if student.state == RETURNING:
204                p_session, p_level = self.getReturningData(student)
205
206
207            amount = 0.0
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    # KwaraPoly prefix
264    STUDENT_ID_PREFIX = u'W'
Note: See TracBrowser for help on using the repository browser.