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