## $Id: utils.py 13418 2015-11-09 11:53:23Z 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 from time import time from zope.component import createObject from waeup.kofa.interfaces import ( ADMITTED, CLEARED, RETURNING, PAID, academic_sessions_vocab) from kofacustom.nigeria.students.utils import NigeriaStudentsUtils from waeup.kofa.accesscodes import create_accesscode from waeup.kofa.students.utils import trans from waeup.aaue.interswitch.browser import gateway_net_amt from waeup.aaue.interfaces import MessageFactory as _ class CustomStudentsUtils(NigeriaStudentsUtils): """A collection of customized methods. """ PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING) gpa_boundaries = ((1, 'FRNS'), (1.5, 'Pass'), (2.4, '3rd Class Honours'), (3.5, '2nd Class Honours Lower Division'), (4.5, '2nd Class Honours Upper Division'), (5, '1st Class Honours')) def increaseMatricInteger(self, student): """Increase counter for matric numbers. This counter can be a centrally stored attribute or an attribute of faculties, departments or certificates. In the base package the counter is as an attribute of the site configuration container. """ if student.current_mode in ('ug_pt', 'de_pt'): grok.getSite()['configuration'].next_matric_integer += 1 return grok.getSite()['configuration'].next_matric_integer_2 += 1 return def constructMatricNumber(self, student): faccode = student.faccode depcode = student.depcode year = unicode(student.entry_session)[2:] if not student.state in (PAID, ) or not student.is_fresh or \ student.current_mode == 'found': return _('Matriculation number cannot be set.'), None if student.current_mode in ('ug_pt', 'de_pt'): next_integer = grok.getSite()['configuration'].next_matric_integer if next_integer == 0: return _('Matriculation number cannot be set.'), None return None, "PTP/%s/%s/%s/%05d" % ( faccode, depcode, year, next_integer) next_integer = grok.getSite()['configuration'].next_matric_integer_2 if next_integer == 0: return _('Matriculation number cannot be set.'), None if student.faccode in ('FBM', 'FCS'): return None, "CMS/%s/%s/%s/%05d" % ( faccode, depcode, year, next_integer) return None, "%s/%s/%s/%05d" % (faccode, depcode, year, next_integer) 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. """ details = {} p_item = u'' amount = 0.0 error = u'' 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 == 'transfer': amount = academic_session.transfer_fee elif category == 'transcript': amount = academic_session.transcript_fee elif category == 'bed_allocation': amount = academic_session.booking_fee elif category == 'hostel_maintenance': amount = 0.0 bedticket = student['accommodation'].get( str(student.current_session), None) if bedticket: p_item = bedticket.bed_coordinates if bedticket.bed.__parent__.maint_fee > 0: amount = bedticket.bed.__parent__.maint_fee else: # fallback amount = academic_session.maint_fee else: # Should not happen because this is already checked # in the browser module, but anyway ... portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE p_item = trans(_('no bed allocated'), portal_language) elif category == 'welfare': amount = academic_session.welfare_fee elif category == 'union': amount = academic_session.union_fee elif category == 'lapel': amount = academic_session.lapel_fee elif category == 'matric_gown': amount = academic_session.matric_gown_fee elif category == 'concessional': amount = academic_session.concession_fee elif category.startswith('clearance'): if student.faccode == 'FP': amount = academic_session.clearance_fee_fp elif student.current_mode.endswith('_pt'): amount = academic_session.clearance_fee_pt elif student.faccode in ('FBM', 'FCS'): amount = academic_session.clearance_fee_med else: amount = academic_session.clearance_fee p_item = student['studycourse'].certificate.code # Add Matric Gown Fee and Lapel Fee if category.endswith('_incl'): if amount is None: # Otherwise we can't add somtehing amount = 0.0 amount += gateway_net_amt(academic_session.matric_gown_fee) + \ gateway_net_amt(academic_session.lapel_fee) elif category == 'late_registration': amount = academic_session.late_registration_fee elif category.startswith('schoolfee'): try: certificate = student['studycourse'].certificate p_item = certificate.code except (AttributeError, TypeError): return _('Study course data are incomplete.'), None if student.state == CLEARED: if student.is_foreigner: amount = getattr(certificate, 'school_fee_3', 0.0) else: amount = getattr(certificate, 'school_fee_1', 0.0) elif student.state == RETURNING: # In case of returning school fee payment the payment session # and level contain the values of the session the student # has paid for. p_session, p_level = self.getReturningData(student) try: academic_session = grok.getSite()[ 'configuration'][str(p_session)] except KeyError: return _(u'Session configuration object is not available.'), None if student.is_foreigner: amount = getattr(certificate, 'school_fee_4', 0.0) else: amount = getattr(certificate, 'school_fee_2', 0.0) else: return _('Wrong state.'), None if amount in (0.0, None): return _(u'Amount could not be determined.'), None # Add Student Union Fee and Welfare Assurance if category == 'schoolfee_incl': amount += gateway_net_amt(academic_session.welfare_fee) + \ gateway_net_amt(academic_session.union_fee) if amount in (0.0, None): return _(u'Amount could not be determined.'), None # Add session specific penalty fee. if category.startswith('schoolfee') and student.is_postgrad: amount += academic_session.penalty_pg elif category.startswith('schoolfee'): amount += academic_session.penalty_ug # Create ticket. 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 if self._isPaymentDisabled(p_session, category, student): return _('Payment temporarily disabled.'), None 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 _admissionText(self, student, portal_language): inst_name = grok.getSite()['configuration'].name entry_session = student['studycourse'].entry_session entry_session = academic_sessions_vocab.getTerm(entry_session).title text = trans(_( 'This is to inform you that you have been offered provisional' ' admission into ${a} for the ${b} academic session as follows:', mapping = {'a': inst_name, 'b': entry_session}), portal_language) return text def maxCredits(self, studylevel): """Return maximum credits. """ return 48 def getBedCoordinates(self, bedticket): """Return descriptive bed coordinates. This method can be used to customize the `display_coordinates` property method in order to display a customary description of the bed space. """ bc = bedticket.bed_coordinates.split(',') if len(bc) == 4: return bc[0] return bedticket.bed_coordinates 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 bt = 'all' if student.sex == 'f': sex = 'female' else: sex = 'male' special_handling = 'regular' d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) return d # AAUE prefix STUDENT_ID_PREFIX = u'E'