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