[16717] | 1 | ## $Id: utils.py 17647 2023-11-22 21:52:19Z henrik $ |
---|
[15614] | 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 | ## |
---|
[16893] | 18 | import grok |
---|
[15614] | 19 | from time import time |
---|
| 20 | from zope.component import createObject, getUtility |
---|
| 21 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
| 22 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
| 23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[16721] | 24 | from kofacustom.unidel.interfaces import MessageFactory as _ |
---|
[15614] | 25 | |
---|
[16790] | 26 | def local(student): |
---|
| 27 | lga = getattr(student, 'lga') |
---|
| 28 | if lga and lga.startswith('delta'): |
---|
| 29 | return True |
---|
| 30 | return False |
---|
| 31 | |
---|
[15614] | 32 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
| 33 | """A collection of customized methods. |
---|
| 34 | |
---|
| 35 | """ |
---|
| 36 | |
---|
| 37 | # refix |
---|
[16789] | 38 | STUDENT_ID_PREFIX = u'D' |
---|
[16788] | 39 | |
---|
[17123] | 40 | def _clearancePaymentMade(self, student): |
---|
| 41 | if len(student['payments']): |
---|
| 42 | for ticket in student['payments'].values(): |
---|
| 43 | if ticket.p_state == 'paid' and \ |
---|
| 44 | ticket.p_category == 'clearance': |
---|
| 45 | return True |
---|
| 46 | return False |
---|
| 47 | |
---|
[17598] | 48 | def _isPaymentDisabled(self, p_session, category, student): |
---|
| 49 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 50 | if category == 'schoolfee': |
---|
| 51 | if 'sf_all' in academic_session.payment_disabled: |
---|
| 52 | return True |
---|
| 53 | if student.current_mode == 'ug_ft' and \ |
---|
| 54 | 'sf_ugft' in academic_session.payment_disabled: |
---|
| 55 | return True |
---|
| 56 | return False |
---|
| 57 | |
---|
[16788] | 58 | def setPaymentDetails(self, category, student, |
---|
| 59 | previous_session=None, previous_level=None, combi=[]): |
---|
| 60 | """Create a payment ticket and set the payment data of a |
---|
| 61 | student for the payment category specified. |
---|
| 62 | """ |
---|
| 63 | p_item = u'' |
---|
| 64 | amount = 0.0 |
---|
| 65 | if previous_session: |
---|
| 66 | if previous_session < student['studycourse'].entry_session: |
---|
| 67 | return _('The previous session must not fall below ' |
---|
| 68 | 'your entry session.'), None |
---|
| 69 | if category == 'schoolfee': |
---|
| 70 | # School fee is always paid for the following session |
---|
| 71 | if previous_session > student['studycourse'].current_session: |
---|
| 72 | return _('This is not a previous session.'), None |
---|
| 73 | else: |
---|
| 74 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 75 | return _('This is not a previous session.'), None |
---|
| 76 | p_session = previous_session |
---|
| 77 | p_level = previous_level |
---|
| 78 | p_current = False |
---|
| 79 | else: |
---|
| 80 | p_session = student['studycourse'].current_session |
---|
| 81 | p_level = student['studycourse'].current_level |
---|
| 82 | p_current = True |
---|
| 83 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 84 | if academic_session == None: |
---|
| 85 | return _(u'Session configuration object is not available.'), None |
---|
| 86 | # Determine fee. |
---|
| 87 | if category == 'schoolfee': |
---|
| 88 | try: |
---|
| 89 | certificate = student['studycourse'].certificate |
---|
| 90 | p_item = certificate.code |
---|
| 91 | except (AttributeError, TypeError): |
---|
| 92 | return _('Study course data are incomplete.'), None |
---|
| 93 | if previous_session: |
---|
| 94 | # Students can pay for previous sessions in all |
---|
| 95 | # workflow states. Fresh students are excluded by the |
---|
| 96 | # update method of the PreviousPaymentAddFormPage. |
---|
| 97 | if previous_level == 100: |
---|
| 98 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 99 | else: |
---|
| 100 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 101 | else: |
---|
[17278] | 102 | if student.faccode == 'JUPEB': |
---|
[17123] | 103 | if not self._clearancePaymentMade(student): |
---|
| 104 | return _(u'Acceptance fee must be paid first.'), None |
---|
[16788] | 105 | if student.state == CLEARED: |
---|
| 106 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 107 | elif student.state == RETURNING: |
---|
| 108 | # In case of returning school fee payment the |
---|
| 109 | # payment session and level contain the values of |
---|
| 110 | # the session the student has paid for. Payment |
---|
| 111 | # session is always next session. |
---|
| 112 | p_session, p_level = self.getReturningData(student) |
---|
| 113 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 114 | if academic_session == None: |
---|
| 115 | return _( |
---|
| 116 | u'Session configuration object is not available.' |
---|
| 117 | ), None |
---|
| 118 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 119 | elif student.is_postgrad and student.state == PAID: |
---|
| 120 | # Returning postgraduate students also pay for the |
---|
| 121 | # next session but their level always remains the |
---|
| 122 | # same. |
---|
| 123 | p_session += 1 |
---|
| 124 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 125 | if academic_session == None: |
---|
| 126 | return _( |
---|
| 127 | u'Session configuration object is not available.' |
---|
| 128 | ), None |
---|
| 129 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[17347] | 130 | if amount and not local(student): |
---|
| 131 | if student.faccode == 'NCE': |
---|
| 132 | amount += 14600 |
---|
[17647] | 133 | elif student.faccode not in ('PRE', 'JUPEB', 'DELSU', 'IJMB'): |
---|
[17347] | 134 | amount += 40000 |
---|
[16788] | 135 | elif category == 'clearance': |
---|
| 136 | try: |
---|
| 137 | p_item = student['studycourse'].certificate.code |
---|
| 138 | except (AttributeError, TypeError): |
---|
| 139 | return _('Study course data are incomplete.'), None |
---|
| 140 | amount = academic_session.clearance_fee |
---|
[17599] | 141 | if student.current_mode in ('ug_ft', 'de_ft'): |
---|
| 142 | if local(student): |
---|
| 143 | amount = academic_session.ugftlocal_clearance_fee |
---|
| 144 | else: |
---|
| 145 | amount = academic_session.ugft_clearance_fee |
---|
[17621] | 146 | elif student.faccode == 'PRE': |
---|
| 147 | amount = 20000.0 |
---|
| 148 | elif student.faccode == 'JUPEB': |
---|
| 149 | amount = 25000.0 |
---|
| 150 | elif student.current_mode.startswith('dp'): |
---|
| 151 | amount = 20000.0 |
---|
[16788] | 152 | elif category == 'bed_allocation': |
---|
[17202] | 153 | acco_details = self.getAccommodationDetails(student) |
---|
| 154 | p_session = acco_details['booking_session'] |
---|
| 155 | p_item = acco_details['bt'] |
---|
| 156 | amount = academic_session.booking_fee |
---|
[16788] | 157 | elif category == 'hostel_maintenance': |
---|
| 158 | amount = 0.0 |
---|
[17202] | 159 | booking_session = grok.getSite()['hostels'].accommodation_session |
---|
| 160 | bedticket = student['accommodation'].get(str(booking_session), None) |
---|
[16788] | 161 | if bedticket is not None and bedticket.bed is not None: |
---|
[17202] | 162 | p_session = booking_session |
---|
[16788] | 163 | p_item = bedticket.bed_coordinates |
---|
| 164 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
| 165 | amount = bedticket.bed.__parent__.maint_fee |
---|
| 166 | else: |
---|
| 167 | # fallback |
---|
| 168 | amount = academic_session.maint_fee |
---|
| 169 | else: |
---|
| 170 | return _(u'No bed allocated.'), None |
---|
| 171 | elif category == 'combi' and combi: |
---|
| 172 | categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES |
---|
| 173 | for cat in combi: |
---|
| 174 | fee_name = cat + '_fee' |
---|
| 175 | cat_amount = getattr(academic_session, fee_name, 0.0) |
---|
| 176 | if not cat_amount: |
---|
| 177 | return _('%s undefined.' % categories[cat]), None |
---|
| 178 | amount += cat_amount |
---|
| 179 | p_item += u'%s + ' % categories[cat] |
---|
| 180 | p_item = p_item.strip(' + ') |
---|
| 181 | else: |
---|
| 182 | fee_name = category + '_fee' |
---|
| 183 | amount = getattr(academic_session, fee_name, 0.0) |
---|
[16882] | 184 | if category != 'bed_allocation' and amount in (0.0, None): |
---|
[16788] | 185 | return _('Amount could not be determined.'), None |
---|
| 186 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 187 | return _('This type of payment has already been made.'), None |
---|
| 188 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 189 | return _('This category of payments has been disabled.'), None |
---|
| 190 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 191 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 192 | payment.p_id = "p%s" % timestamp |
---|
| 193 | payment.p_category = category |
---|
| 194 | payment.p_item = p_item |
---|
| 195 | payment.p_session = p_session |
---|
| 196 | payment.p_level = p_level |
---|
| 197 | payment.p_current = p_current |
---|
| 198 | payment.amount_auth = amount |
---|
| 199 | payment.p_combi = combi |
---|
[16892] | 200 | return None, payment |
---|
| 201 | |
---|
| 202 | def getAccommodationDetails(self, student): |
---|
| 203 | """Determine the accommodation data of a student. |
---|
| 204 | """ |
---|
| 205 | d = {} |
---|
| 206 | d['error'] = u'' |
---|
| 207 | hostels = grok.getSite()['hostels'] |
---|
| 208 | d['booking_session'] = hostels.accommodation_session |
---|
| 209 | d['allowed_states'] = hostels.accommodation_states |
---|
| 210 | d['startdate'] = hostels.startdate |
---|
| 211 | d['enddate'] = hostels.enddate |
---|
| 212 | d['expired'] = hostels.expired |
---|
[17645] | 213 | studycourse = student['studycourse'] |
---|
| 214 | certificate = getattr(studycourse,'certificate',None) |
---|
| 215 | entry_session = studycourse.entry_session |
---|
| 216 | current_level = studycourse.current_level |
---|
| 217 | if None in (entry_session, current_level, certificate): |
---|
| 218 | return d |
---|
| 219 | end_level = certificate.end_level |
---|
[16892] | 220 | # Determine bed type |
---|
[17644] | 221 | if entry_session == grok.getSite()['hostels'].accommodation_session: |
---|
| 222 | bt = 'fr' |
---|
| 223 | elif current_level >= end_level: |
---|
| 224 | bt = 'fi' |
---|
| 225 | else: |
---|
| 226 | bt = 're' |
---|
[17328] | 227 | #if student.current_level >= 300: |
---|
| 228 | # bt = 'na' |
---|
[16892] | 229 | if student.sex == 'f': |
---|
| 230 | sex = 'female' |
---|
| 231 | else: |
---|
| 232 | sex = 'male' |
---|
| 233 | special_handling = 'regular' |
---|
[17328] | 234 | #if student.faccode in ('FLW', 'FMS'): |
---|
| 235 | # special_handling = 'oyibu' |
---|
| 236 | #if student.faccode in ('FET', 'FES'): |
---|
| 237 | # special_handling = 'alero' |
---|
[16892] | 238 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
[17304] | 239 | return d |
---|
| 240 | |
---|