[7419] | 1 | ## $Id: utils.py 13248 2015-09-05 10:18:56Z 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 | ## |
---|
[11773] | 18 | import grok |
---|
[8598] | 19 | from time import time |
---|
[9459] | 20 | from zope.component import createObject, getUtility |
---|
[9513] | 21 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
| 22 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
[8821] | 23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[8020] | 24 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[6902] | 25 | |
---|
[8821] | 26 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 27 | """A collection of customized methods. |
---|
| 28 | |
---|
| 29 | """ |
---|
| 30 | |
---|
[8270] | 31 | def getReturningData(self, student): |
---|
| 32 | """ This method defines what happens after school fee payment |
---|
[8319] | 33 | of returning students depending on the student's senate verdict. |
---|
[8270] | 34 | """ |
---|
[8319] | 35 | prev_level = student['studycourse'].current_level |
---|
| 36 | cur_verdict = student['studycourse'].current_verdict |
---|
| 37 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 38 | # Successful student |
---|
| 39 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 40 | elif cur_verdict == 'C': |
---|
| 41 | # Student on probation |
---|
| 42 | new_level = int(prev_level) + 10 |
---|
| 43 | else: |
---|
| 44 | # Student is somehow in an undefined state. |
---|
| 45 | # Level has to be set manually. |
---|
| 46 | new_level = prev_level |
---|
[8270] | 47 | new_session = student['studycourse'].current_session + 1 |
---|
| 48 | return new_session, new_level |
---|
| 49 | |
---|
[13248] | 50 | def checkAccommodationRequirements(self, student, acc_details): |
---|
| 51 | if acc_details.get('expired', False): |
---|
| 52 | startdate = acc_details.get('startdate') |
---|
| 53 | enddate = acc_details.get('enddate') |
---|
| 54 | if startdate and enddate: |
---|
| 55 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 56 | startdate = to_timezone( |
---|
| 57 | startdate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 58 | enddate = to_timezone( |
---|
| 59 | enddate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 60 | return _("Outside booking period: ${a} - ${b}", |
---|
| 61 | mapping = {'a': startdate, 'b': enddate}) |
---|
| 62 | else: |
---|
| 63 | return _("Outside booking period.") |
---|
| 64 | if not acc_details.get('bt'): |
---|
| 65 | return _("Your data are incomplete.") |
---|
| 66 | if not student.state in acc_details['allowed_states']: |
---|
| 67 | return _("You are in the wrong registration state.") |
---|
| 68 | if student['studycourse'].current_session != acc_details[ |
---|
| 69 | 'booking_session']: |
---|
| 70 | return _('Your current session does not ' |
---|
| 71 | 'match accommodation session.') |
---|
| 72 | if str(acc_details['booking_session']) in student['accommodation'].keys(): |
---|
| 73 | return _('You already booked a bed space in ' |
---|
| 74 | 'current accommodation session.') |
---|
| 75 | return |
---|
[13244] | 76 | |
---|
[9520] | 77 | def _paymentMade(self, student, session): |
---|
| 78 | if len(student['payments']): |
---|
| 79 | for ticket in student['payments'].values(): |
---|
| 80 | if ticket.p_state == 'paid' and \ |
---|
| 81 | ticket.p_category == 'schoolfee' and \ |
---|
| 82 | ticket.p_session == session: |
---|
| 83 | return True |
---|
| 84 | return False |
---|
| 85 | |
---|
[12566] | 86 | def _hostelApplicationPaymentMade(self, student, session): |
---|
| 87 | if len(student['payments']): |
---|
| 88 | for ticket in student['payments'].values(): |
---|
| 89 | if ticket.p_state == 'paid' and \ |
---|
| 90 | ticket.p_category == 'hostel_application' and \ |
---|
| 91 | ticket.p_session == session: |
---|
| 92 | return True |
---|
| 93 | return False |
---|
| 94 | |
---|
[9152] | 95 | def setPaymentDetails(self, category, student, |
---|
| 96 | previous_session, previous_level): |
---|
[8598] | 97 | """Create Payment object and set the payment data of a student for |
---|
| 98 | the payment category specified. |
---|
| 99 | |
---|
| 100 | """ |
---|
| 101 | p_item = u'' |
---|
| 102 | amount = 0.0 |
---|
[9152] | 103 | if previous_session: |
---|
[9520] | 104 | if previous_session < student['studycourse'].entry_session: |
---|
| 105 | return _('The previous session must not fall below ' |
---|
| 106 | 'your entry session.'), None |
---|
| 107 | if category == 'schoolfee': |
---|
| 108 | # School fee is always paid for the following session |
---|
| 109 | if previous_session > student['studycourse'].current_session: |
---|
| 110 | return _('This is not a previous session.'), None |
---|
| 111 | else: |
---|
| 112 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 113 | return _('This is not a previous session.'), None |
---|
[9152] | 114 | p_session = previous_session |
---|
| 115 | p_level = previous_level |
---|
| 116 | p_current = False |
---|
| 117 | else: |
---|
| 118 | p_session = student['studycourse'].current_session |
---|
| 119 | p_level = student['studycourse'].current_level |
---|
| 120 | p_current = True |
---|
[9520] | 121 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 122 | if academic_session == None: |
---|
[8598] | 123 | return _(u'Session configuration object is not available.'), None |
---|
[8676] | 124 | # Determine fee. |
---|
[7151] | 125 | if category == 'transfer': |
---|
[8598] | 126 | amount = academic_session.transfer_fee |
---|
[10469] | 127 | elif category == 'transcript': |
---|
| 128 | amount = academic_session.transcript_fee |
---|
[7151] | 129 | elif category == 'gown': |
---|
[8598] | 130 | amount = academic_session.gown_fee |
---|
[12566] | 131 | #elif category == 'bed_allocation': |
---|
| 132 | # amount = academic_session.booking_fee |
---|
| 133 | #elif category == 'hostel_maintenance': |
---|
| 134 | # amount = academic_session.maint_fee |
---|
| 135 | elif category == 'hostel_application': |
---|
| 136 | amount = 1000.0 |
---|
| 137 | elif category.startswith('tempmaint'): |
---|
| 138 | if not self._hostelApplicationPaymentMade( |
---|
| 139 | student, student.current_session): |
---|
| 140 | return _( |
---|
| 141 | 'You have not yet paid the hostel application fee.'), None |
---|
| 142 | if category == 'tempmaint_1': |
---|
| 143 | amount = 8150.0 |
---|
| 144 | elif category == 'tempmaint_2': |
---|
| 145 | amount = 12650.0 |
---|
| 146 | elif category == 'tempmaint_3': |
---|
| 147 | amount = 9650.0 |
---|
[7151] | 148 | elif category == 'clearance': |
---|
[9796] | 149 | p_item = student.certcode |
---|
| 150 | if p_item is None: |
---|
[8598] | 151 | return _('Study course data are incomplete.'), None |
---|
[11479] | 152 | if student.faccode == 'FCETA': |
---|
| 153 | amount = 22500.0 |
---|
| 154 | elif p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS', |
---|
| 155 | 'MBBSMED', 'MBBSNDU'): |
---|
| 156 | amount = 65000.0 |
---|
| 157 | elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
| 158 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
| 159 | amount = 22500.0 |
---|
| 160 | else: |
---|
[9346] | 161 | amount = 45000.0 |
---|
[7151] | 162 | elif category == 'schoolfee': |
---|
[8598] | 163 | try: |
---|
| 164 | certificate = student['studycourse'].certificate |
---|
| 165 | p_item = certificate.code |
---|
| 166 | except (AttributeError, TypeError): |
---|
| 167 | return _('Study course data are incomplete.'), None |
---|
[9152] | 168 | if previous_session: |
---|
[9520] | 169 | # Students can pay for previous sessions in all workflow states. |
---|
| 170 | # Fresh students are excluded by the update method of the |
---|
| 171 | # PreviousPaymentAddFormPage. |
---|
[9157] | 172 | if previous_session == student['studycourse'].entry_session: |
---|
[9152] | 173 | if student.is_foreigner: |
---|
| 174 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
| 175 | else: |
---|
| 176 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
[9006] | 177 | else: |
---|
[9152] | 178 | if student.is_foreigner: |
---|
| 179 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
| 180 | else: |
---|
| 181 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 182 | else: |
---|
| 183 | if student.state == CLEARED: |
---|
| 184 | if student.is_foreigner: |
---|
| 185 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
| 186 | else: |
---|
| 187 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
[9513] | 188 | elif student.state in (PAID, REGISTERED, VALIDATED): |
---|
| 189 | p_session += 1 |
---|
| 190 | # We don't know which level the student is paying for. |
---|
| 191 | p_level = None |
---|
[9520] | 192 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 193 | if academic_session == None: |
---|
[9513] | 194 | return _(u'Session configuration object is not available.'), None |
---|
[9570] | 195 | |
---|
[9520] | 196 | # Students are only allowed to pay for the next session |
---|
| 197 | # if current session payment |
---|
| 198 | # has really been made, i.e. payment object exists. |
---|
[9570] | 199 | #if not self._paymentMade( |
---|
| 200 | # student, student.current_session): |
---|
| 201 | # return _('You have not yet paid your current/active' + |
---|
| 202 | # ' session. Please use the previous session' + |
---|
| 203 | # ' payment form first.'), None |
---|
| 204 | |
---|
[9513] | 205 | if student.is_foreigner: |
---|
| 206 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
| 207 | else: |
---|
| 208 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[9152] | 209 | elif student.state == RETURNING: |
---|
| 210 | # In case of returning school fee payment the payment session |
---|
| 211 | # and level contain the values of the session the student |
---|
| 212 | # has paid for. |
---|
| 213 | p_session, p_level = self.getReturningData(student) |
---|
[9520] | 214 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 215 | if academic_session == None: |
---|
[9152] | 216 | return _(u'Session configuration object is not available.'), None |
---|
[9570] | 217 | |
---|
[9520] | 218 | # Students are only allowed to pay for the next session |
---|
| 219 | # if current session payment has really been made, |
---|
| 220 | # i.e. payment object exists and is paid. |
---|
[9570] | 221 | #if not self._paymentMade( |
---|
| 222 | # student, student.current_session): |
---|
| 223 | # return _('You have not yet paid your current/active' + |
---|
| 224 | # ' session. Please use the previous session' + |
---|
| 225 | # ' payment form first.'), None |
---|
| 226 | |
---|
[9152] | 227 | if student.is_foreigner: |
---|
| 228 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
| 229 | else: |
---|
| 230 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[9006] | 231 | # Give 50% school fee discount to staff members. |
---|
| 232 | if student.is_staff: |
---|
| 233 | amount /= 2 |
---|
[8598] | 234 | if amount in (0.0, None): |
---|
[9520] | 235 | return _('Amount could not be determined.'), None |
---|
[8676] | 236 | # Add session specific penalty fee. |
---|
| 237 | if category == 'schoolfee' and student.is_postgrad: |
---|
| 238 | amount += academic_session.penalty_pg |
---|
| 239 | elif category == 'schoolfee': |
---|
| 240 | amount += academic_session.penalty_ug |
---|
[9727] | 241 | if category.startswith('tempmaint'): |
---|
| 242 | p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category] |
---|
| 243 | p_item = unicode(p_item) |
---|
| 244 | # Now we change the category because tempmaint payments |
---|
[12566] | 245 | # will be obsolete when Uniben returns to Kofa bed allocation. |
---|
[9727] | 246 | category = 'hostel_maintenance' |
---|
[8676] | 247 | # Create ticket. |
---|
[11644] | 248 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 249 | return _('This type of payment has already been made.'), None |
---|
[11459] | 250 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 251 | return _('Payment temporarily disabled.'), None |
---|
[8715] | 252 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8950] | 253 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8598] | 254 | payment.p_id = "p%s" % timestamp |
---|
| 255 | payment.p_category = category |
---|
| 256 | payment.p_item = p_item |
---|
| 257 | payment.p_session = p_session |
---|
| 258 | payment.p_level = p_level |
---|
[9152] | 259 | payment.p_current = p_current |
---|
[8598] | 260 | payment.amount_auth = amount |
---|
| 261 | return None, payment |
---|
[7621] | 262 | |
---|
[9831] | 263 | def maxCredits(self, studylevel): |
---|
| 264 | """Return maximum credits. |
---|
| 265 | |
---|
| 266 | """ |
---|
| 267 | studycourse = studylevel.__parent__ |
---|
| 268 | certificate = getattr(studycourse,'certificate', None) |
---|
| 269 | current_level = studycourse.current_level |
---|
| 270 | if None in (current_level, certificate): |
---|
| 271 | return 0 |
---|
| 272 | end_level = certificate.end_level |
---|
| 273 | if current_level >= end_level: |
---|
| 274 | return 51 |
---|
| 275 | return 50 |
---|
| 276 | |
---|
[11773] | 277 | def clearance_disabled_message(self, student): |
---|
| 278 | if student.is_postgrad: |
---|
| 279 | return None |
---|
| 280 | try: |
---|
| 281 | session_config = grok.getSite()[ |
---|
| 282 | 'configuration'][str(student.current_session)] |
---|
| 283 | except KeyError: |
---|
| 284 | return _('Session configuration object is not available.') |
---|
| 285 | if not session_config.clearance_enabled: |
---|
| 286 | return _('Clearance is disabled for this session.') |
---|
| 287 | return None |
---|
| 288 | |
---|
[8441] | 289 | # Uniben prefix |
---|
[8413] | 290 | STUDENT_ID_PREFIX = u'B' |
---|