## $Id: utils.py 9732 2012-11-27 15:50:05Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import grok import random from time import time from zope.component import createObject from waeup.kofa.interfaces import CLEARED, RETURNING, PAID from kofacustom.nigeria.students.utils import NigeriaStudentsUtils from waeup.kofa.accesscodes import create_accesscode from waeup.futminna.interfaces import MessageFactory as _ class CustomStudentsUtils(NigeriaStudentsUtils): """A collection of customized methods. """ def selectBed(self, available_beds): """Randomly select a bed from a list of available beds. """ return random.choice(available_beds) def getReturningData(self, student): """ This method defines what happens after school fee payment of returning students depending on the student's senate verdict. """ prev_level = student['studycourse'].current_level cur_verdict = student['studycourse'].current_verdict if cur_verdict in ('A','B','L','M','N','Z',): # Successful student new_level = divmod(int(prev_level),100)[0]*100 + 100 elif cur_verdict == 'C': # Student on probation new_level = int(prev_level) + 10 else: # Student is somehow in an undefined state. # Level has to be set manually. new_level = prev_level new_session = student['studycourse'].current_session + 1 return new_session, new_level def setPaymentDetails(self, category, student, previous_session=None, previous_level=None): """Create Payment object and set the payment data of a student for the payment category specified. """ p_item = u'' amount = 0.0 if previous_session: return _('Previous session payment not yet implemented.'), None p_session = student['studycourse'].current_session p_level = student['studycourse'].current_level p_current = True academic_session = self._getSessionConfiguration(p_session) if academic_session == None: return _(u'Session configuration object is not available.'), None # Determine fee. if category == 'schoolfee': try: certificate = student['studycourse'].certificate p_item = certificate.code except (AttributeError, TypeError): return _('Study course data are incomplete.'), None if student.current_mode.endswith('_ft'): # fresh remedial if student.current_level == 10 and student.state == CLEARED: if student['studycourse'].entry_mode == 'rmd_ft': amount = 80200.0 else: amount = 74200.0 # fresh elif student.state == CLEARED: if student.current_mode == 'jm_ft': amount = 72700.0 elif student.is_foreigner: amount = 131500.0 else: amount = 37000.0 # School Fee reduced by 8000 # returning elif student.state == RETURNING: if student.current_mode == 'jm_ft': amount = 37000.0 elif student.is_foreigner: amount = 109500.0 else: amount = 20000.0 else: amount = 0.0 if student.state == RETURNING: # Override p_session and p_level p_session, p_level = self.getReturningData(student) academic_session = self._getSessionConfiguration(p_session) if academic_session == None: return _(u'Session configuration object is not available.'), None elif category == 'clearance': try: p_item = student['studycourse'].certificate.code except (AttributeError, TypeError): return _('Study course data are incomplete.'), None amount = academic_session.clearance_fee if amount and (student.faccode in [ 'EET','ICT'] or student.depcode in ['ARC']): amount += 5000.0 elif category == 'hostel_maintenance': current_session = student['studycourse'].current_session bedticket = student['accommodation'].get(str(current_session), None) if bedticket is not None and bedticket.bed is not None: p_item = bedticket.bed_coordinates else: return _(u'You have not yet booked accommodation.'), None acc_details = self.getAccommodationDetails(student) if current_session != acc_details['booking_session']: return _(u'Current session does not match accommodation session.'), None if bedticket.bed.bed_id.startswith('block-h'): amount = 15000.0 elif student.current_level in (100,200,300,400,500) and \ student.faccode in ('EET','SET','AAT','ICT','EMT'): amount = 12000.0 else: amount = 10000.0 elif category == 'bed_allocation': p_item = self.getAccommodationDetails(student)['bt'] amount = academic_session.booking_fee if amount in (0.0, None): return _('Amount could not be determined.'), None for key in student['payments'].keys(): ticket = student['payments'][key] if ticket.p_state == 'paid' and\ ticket.p_category == category and \ ticket.p_item == p_item and \ ticket.p_session == p_session: return _('This type of payment has already been made.'), None # Add session specific penalty fee. if category == 'schoolfee' and student.is_postgrad: amount += academic_session.penalty_pg elif category == 'schoolfee': amount += academic_session.penalty_ug payment = createObject(u'waeup.StudentOnlinePayment') timestamp = ("%d" % int(time()*10000))[1:] payment.p_id = "p%s" % timestamp payment.p_category = category payment.p_item = p_item payment.p_session = p_session payment.p_level = p_level payment.p_current = p_current payment.amount_auth = amount return None, payment def getAccommodationDetails(self, student): """Determine the accommodation data of a student. """ d = {} d['error'] = u'' hostels = grok.getSite()['hostels'] d['booking_session'] = hostels.accommodation_session d['allowed_states'] = hostels.accommodation_states d['startdate'] = hostels.startdate d['enddate'] = hostels.enddate d['expired'] = hostels.expired # Determine bed type studycourse = student['studycourse'] certificate = getattr(studycourse,'certificate',None) entry_session = studycourse.entry_session current_level = studycourse.current_level if None in (entry_session, current_level, certificate): return d end_level = certificate.end_level if current_level == 10: bt = 'pr' elif entry_session == grok.getSite()['hostels'].accommodation_session: bt = 'fr' elif current_level >= end_level: bt = 'fi' else: bt = 're' sex = 'male' if student.sex == 'f': sex = 'female' special_handling = 'regular' if student.faccode == 'SSE': special_handling = 'sse' d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) return d # FUTMinna prefix STUDENT_ID_PREFIX = u'M'