[7419] | 1 | ## $Id: utils.py 9523 2012-11-04 10:27:40Z 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 |
---|
[9403] | 19 | import random |
---|
[8598] | 20 | from time import time |
---|
| 21 | from zope.component import createObject |
---|
[8473] | 22 | from waeup.kofa.interfaces import CLEARED, RETURNING, PAID |
---|
[8833] | 23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[8247] | 24 | from waeup.kofa.accesscodes import create_accesscode |
---|
[8619] | 25 | from waeup.futminna.interfaces import MessageFactory as _ |
---|
[6902] | 26 | |
---|
[8833] | 27 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 28 | """A collection of customized methods. |
---|
| 29 | |
---|
| 30 | """ |
---|
| 31 | |
---|
[9403] | 32 | def selectBed(self, available_beds): |
---|
| 33 | """Randomly select a bed from a list of available beds. |
---|
| 34 | |
---|
| 35 | """ |
---|
| 36 | return random.choice(available_beds) |
---|
| 37 | |
---|
[8270] | 38 | def getReturningData(self, student): |
---|
| 39 | """ This method defines what happens after school fee payment |
---|
[8319] | 40 | of returning students depending on the student's senate verdict. |
---|
[8270] | 41 | """ |
---|
[8319] | 42 | prev_level = student['studycourse'].current_level |
---|
| 43 | cur_verdict = student['studycourse'].current_verdict |
---|
| 44 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 45 | # Successful student |
---|
| 46 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 47 | elif cur_verdict == 'C': |
---|
| 48 | # Student on probation |
---|
| 49 | new_level = int(prev_level) + 10 |
---|
| 50 | else: |
---|
| 51 | # Student is somehow in an undefined state. |
---|
| 52 | # Level has to be set manually. |
---|
| 53 | new_level = prev_level |
---|
[8270] | 54 | new_session = student['studycourse'].current_session + 1 |
---|
| 55 | return new_session, new_level |
---|
| 56 | |
---|
[9155] | 57 | def setPaymentDetails(self, category, student, |
---|
| 58 | previous_session=None, previous_level=None): |
---|
[8598] | 59 | """Create Payment object and set the payment data of a student for |
---|
| 60 | the payment category specified. |
---|
| 61 | |
---|
| 62 | """ |
---|
[9244] | 63 | p_item = u'' |
---|
| 64 | amount = 0.0 |
---|
| 65 | if previous_session: |
---|
| 66 | return _('Previous session payment not yet implemented.'), None |
---|
| 67 | p_session = student['studycourse'].current_session |
---|
| 68 | p_level = student['studycourse'].current_level |
---|
| 69 | p_current = True |
---|
[9523] | 70 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 71 | if academic_session == None: |
---|
[9244] | 72 | return _(u'Session configuration object is not available.'), None |
---|
[9523] | 73 | # Determine fee. |
---|
[9244] | 74 | if category == 'schoolfee': |
---|
| 75 | try: |
---|
| 76 | certificate = student['studycourse'].certificate |
---|
| 77 | p_item = certificate.code |
---|
| 78 | except (AttributeError, TypeError): |
---|
| 79 | return _('Study course data are incomplete.'), None |
---|
| 80 | if student.current_mode.endswith('_ft'): |
---|
| 81 | # fresh remedial |
---|
| 82 | if student.current_level == 10 and student.state == CLEARED: |
---|
| 83 | if student['studycourse'].entry_mode == 'rmd_ft': |
---|
| 84 | amount = 80200.0 |
---|
| 85 | else: |
---|
| 86 | amount = 74200.0 |
---|
| 87 | # fresh |
---|
| 88 | elif student.state == CLEARED: |
---|
| 89 | if student.current_mode == 'jm_ft': |
---|
| 90 | amount = 72700.0 |
---|
| 91 | elif student.is_foreigner: |
---|
| 92 | amount = 131500.0 |
---|
| 93 | else: |
---|
| 94 | amount = 37000.0 # School Fee reduced by 8000 |
---|
| 95 | # returning |
---|
| 96 | elif student.state == RETURNING: |
---|
| 97 | if student.current_mode == 'jm_ft': |
---|
| 98 | amount = 37000.0 |
---|
| 99 | elif student.is_foreigner: |
---|
| 100 | amount = 109500.0 |
---|
| 101 | else: |
---|
| 102 | amount = 20000.0 |
---|
| 103 | else: |
---|
| 104 | amount = 0.0 |
---|
[9298] | 105 | if student.state == RETURNING: |
---|
[9523] | 106 | # Override p_session and p_level |
---|
[9298] | 107 | p_session, p_level = self.getReturningData(student) |
---|
[9523] | 108 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 109 | if academic_session == None: |
---|
| 110 | return _(u'Session configuration object is not available.'), None |
---|
[9244] | 111 | elif category == 'clearance': |
---|
| 112 | try: |
---|
| 113 | p_item = student['studycourse'].certificate.code |
---|
| 114 | except (AttributeError, TypeError): |
---|
| 115 | return _('Study course data are incomplete.'), None |
---|
| 116 | if student.faccode in ['EET','ICT'] or student.depcode in ['ARC']: |
---|
| 117 | amount = 25000.0 |
---|
| 118 | else: |
---|
| 119 | amount = 20000.0 |
---|
[9404] | 120 | elif category == 'hostel_maintenance': |
---|
[9431] | 121 | current_session = student['studycourse'].current_session |
---|
| 122 | bedticket = student['accommodation'].get(str(current_session), None) |
---|
| 123 | if bedticket: |
---|
| 124 | p_item = bedticket.bed_coordinates |
---|
| 125 | else: |
---|
| 126 | return _(u'You have not yet booked accommodation.'), None |
---|
[9404] | 127 | acc_details = self.getAccommodationDetails(student) |
---|
[9431] | 128 | if current_session != acc_details['booking_session']: |
---|
[9404] | 129 | return _(u'Current session does not match accommodation session.'), None |
---|
[9431] | 130 | if bedticket.bed.bed_id.startswith('block-h'): |
---|
| 131 | amount = 15000.0 |
---|
| 132 | elif student.current_level in (100,200,300,400,500) and \ |
---|
[9404] | 133 | student.faccode in ('EET','SET','AAT','ICT','EMT'): |
---|
| 134 | amount = 12000.0 |
---|
| 135 | else: |
---|
| 136 | amount = 10000.0 |
---|
[9244] | 137 | elif category == 'bed_allocation': |
---|
| 138 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
| 139 | amount = academic_session.booking_fee |
---|
| 140 | if amount in (0.0, None): |
---|
| 141 | return _('Amount could not be determined.'), None |
---|
| 142 | for key in student['payments'].keys(): |
---|
| 143 | ticket = student['payments'][key] |
---|
| 144 | if ticket.p_state == 'paid' and\ |
---|
| 145 | ticket.p_category == category and \ |
---|
| 146 | ticket.p_item == p_item and \ |
---|
| 147 | ticket.p_session == p_session: |
---|
| 148 | return _('This type of payment has already been made.'), None |
---|
| 149 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 150 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 151 | payment.p_id = "p%s" % timestamp |
---|
| 152 | payment.p_category = category |
---|
| 153 | payment.p_item = p_item |
---|
| 154 | payment.p_session = p_session |
---|
| 155 | payment.p_level = p_level |
---|
| 156 | payment.p_current = p_current |
---|
| 157 | payment.amount_auth = amount |
---|
| 158 | return None, payment |
---|
[9155] | 159 | |
---|
[9402] | 160 | def getAccommodationDetails(self, student): |
---|
| 161 | """Determine the accommodation data of a student. |
---|
| 162 | """ |
---|
| 163 | d = {} |
---|
| 164 | d['error'] = u'' |
---|
| 165 | hostels = grok.getSite()['hostels'] |
---|
| 166 | d['booking_session'] = hostels.accommodation_session |
---|
| 167 | d['allowed_states'] = hostels.accommodation_states |
---|
| 168 | d['startdate'] = hostels.startdate |
---|
| 169 | d['enddate'] = hostels.enddate |
---|
| 170 | d['expired'] = hostels.expired |
---|
| 171 | # Determine bed type |
---|
| 172 | studycourse = student['studycourse'] |
---|
| 173 | certificate = getattr(studycourse,'certificate',None) |
---|
| 174 | entry_session = studycourse.entry_session |
---|
| 175 | current_level = studycourse.current_level |
---|
| 176 | if None in (entry_session, current_level, certificate): |
---|
| 177 | return d |
---|
| 178 | end_level = certificate.end_level |
---|
| 179 | if current_level == 10: |
---|
| 180 | bt = 'pr' |
---|
| 181 | elif entry_session == grok.getSite()['hostels'].accommodation_session: |
---|
| 182 | bt = 'fr' |
---|
| 183 | elif current_level >= end_level: |
---|
| 184 | bt = 'fi' |
---|
| 185 | else: |
---|
| 186 | bt = 're' |
---|
| 187 | sex = 'male' |
---|
| 188 | if student.sex == 'f': |
---|
| 189 | sex = 'female' |
---|
| 190 | special_handling = 'regular' |
---|
| 191 | if student.faccode == 'SSE': |
---|
| 192 | special_handling = 'sse' |
---|
| 193 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 194 | return d |
---|
[9244] | 195 | |
---|
[9402] | 196 | |
---|
[8619] | 197 | # FUTMinna prefix |
---|
| 198 | STUDENT_ID_PREFIX = u'M' |
---|