## $Id: utils.py 15679 2019-10-13 21:31:36Z 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 ## from time import time import grok from zope.component import createObject, getUtility from waeup.kofa.interfaces import (IKofaUtils, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) from kofacustom.nigeria.students.utils import NigeriaStudentsUtils from kofacustom.edopoly.interfaces import MessageFactory as _ class CustomStudentsUtils(NigeriaStudentsUtils): """A collection of customized methods. """ # prefix STUDENT_ID_PREFIX = u'U' def warnCreditsOOR(self, studylevel, course=None): """No maximum credits. """ return def GPABoundaries(self, faccode=None, depcode=None, certcode=None, student=None): if student and student.current_mode.startswith('dp'): return ((1, 'IRNS / NER / NYV'), (2, 'Pass'), (2.5, 'Lower Credit'), (3, 'Upper Credit'), (3.5, 'Distinction')) elif student: return ((1, 'FRNS / NER / NYV'), (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')) # Session Results Presentations depend on certificate results = None if certcode: cat = queryUtility(ICatalog, name='certificates_catalog') results = list( cat.searchResults(code=(certcode, certcode))) if results and results[0].study_mode.startswith('dp'): return ((1, 'IRNS / NER / NYV'), (2, 'Pass'), (2.5, 'Lower Credit'), (3, 'Upper Credit'), (3.5, 'Distinction')) else: return ((1, 'FRNS / NER / NYV'), (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 getClassFromCGPA(self, gpa, student): gpa_boundaries = self.GPABoundaries(student=student) if gpa < gpa_boundaries[0][0]: return 0, gpa_boundaries[0][1] if gpa < gpa_boundaries[1][0]: return 1, gpa_boundaries[1][1] if gpa < gpa_boundaries[2][0]: return 2, gpa_boundaries[2][1] if gpa < gpa_boundaries[3][0]: return 3, gpa_boundaries[3][1] if gpa < gpa_boundaries[4][0]: return 4, gpa_boundaries[4][1] if gpa <= gpa_boundaries[5][0]: return 5, gpa_boundaries[5][1] return 'N/A' def _requiredPaymentsMade(self, student, session): # SIWESS fee requirement removed on 18/01/2019 req_payments = ('ict_entre', 'logbook_combo') req_payments_titles = 'ICT and Logbook' # All ND and HND part time do not pay for LOGBOOK if student.current_mode.endswith('_pt'): req_payments = ('ict_entre',) req_payments_titles = 'ICT' # HND1 and HND2 full time do not pay for LOGBOOK elif student.current_mode == 'hnd_ft' and student.state in ( CLEARED, RETURNING): req_payments = ('ict_entre',) req_payments_titles = 'ICT' # ND2 FULL TIME do not pay LOGBOOK elif student.current_mode == 'nd_ft' and student.state == RETURNING: req_payments = ('ict_entre',) req_payments_titles = 'ICT' num = 0 if len(student['payments']): for ticket in student['payments'].values(): if ticket.p_state == 'paid' and \ ticket.p_category in req_payments and \ ticket.p_session == session: num += 1 if num == len(req_payments): return True, None return False, req_payments_titles def samePaymentMade(self, student, category, p_item, p_session): if category in ('transcript',): return False 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 True return False def setPaymentDetails(self, category, student, previous_session=None, previous_level=None, combi=[]): """Create a payment ticket and set the payment data of a student for the payment category specified. """ p_item = u'' amount = 0.0 if previous_session: if previous_session < student['studycourse'].entry_session: return _('The previous session must not fall below ' 'your entry session.'), None if category == 'schoolfee': # School fee is always paid for the following session if previous_session > student['studycourse'].current_session: return _('This is not a previous session.'), None else: if previous_session > student['studycourse'].current_session - 1: return _('This is not a previous session.'), None p_session = previous_session p_level = previous_level p_current = False else: p_session = student['studycourse'].current_session p_level = student['studycourse'].current_level p_current = True # The following three fees are part of the school fee which must be # paid before tuition fee. They are paid for next session. if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \ student.state == RETURNING and not previous_session: 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 # 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 previous_session: amount = getattr(certificate, 'school_fee_1', 0.0) else: if student.state == CLEARED: amount = getattr(certificate, 'school_fee_1', 0.0) elif student.state == RETURNING: amount = getattr(certificate, 'school_fee_1', 0.0) # In case of returning school fee payment the # payment session and level contain the values of # the session the student has paid for. Payment # session is always next session. 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 student.is_postgrad and student.state == PAID: # Returning postgraduate students also pay for the # next session but their level always remains the # same. amount = getattr(certificate, 'school_fee_1', 0.0) p_session += 1 academic_session = self._getSessionConfiguration(p_session) if academic_session == None: return _( u'Session configuration object is not available.' ), None rpm, rpt = self._requiredPaymentsMade(student, p_session) if not rpm: return 'Pay %s fee(s) first.' % rpt, 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 elif category == 'bed_allocation': p_item = self.getAccommodationDetails(student)['bt'] amount = academic_session.booking_fee elif category == 'hostel_maintenance': amount = 0.0 bedticket = student['accommodation'].get( str(student.current_session), None) if bedticket is not None and bedticket.bed is not None: 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: return _(u'No bed allocated.'), None elif category == 'ict_entre': amount = 11000.0 if student['studycourse'].entry_session < 2018: amount = 16000.0 else: fee_name = category + '_fee' amount = getattr(academic_session, fee_name, 0.0) if amount in (0.0, None): return _('Amount could not be determined.'), None if self.samePaymentMade(student, category, p_item, p_session): return _('This type of payment has already been made.'), None if self._isPaymentDisabled(p_session, category, student): return _('This category of payments has been 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 constructMatricNumber(self, student): faccode = student.faccode #depcode = student.depcode #certcode = student.certcode year = unicode(student.entry_session)[2:] if not student.state in (PAID, ) or not student.is_fresh: return _('Matriculation number cannot be set.'), None # SASND1809001 if student.current_mode == 'nd_ft': next_integer = grok.getSite()['configuration'].next_matric_integer if next_integer == 0: return _('Matriculation number cannot be set.'), None return None, "%s/ND/%s/%05d" % (faccode, year, next_integer) # SASNH1809001 if student.current_mode == 'hnd_ft': next_integer = grok.getSite()['configuration'].next_matric_integer_2 if next_integer == 0: return _('Matriculation number cannot be set.'), None return None, "%s/HD/%s/%05d" % (faccode, year, next_integer) # SASPT1809001 if student.current_mode in ('nd_pt', 'hnd_pt'): next_integer = grok.getSite()['configuration'].next_matric_integer_3 if next_integer == 0: return _('Matriculation number cannot be set.'), None return None, "%s/PT/%s/%05d" % (faccode, year, next_integer) return _('Matriculation number cannot be set.'), None def increaseMatricInteger(self, student): """Increase counter for matric numbers. """ if student.current_mode == 'nd_ft': grok.getSite()['configuration'].next_matric_integer += 1 return elif student.current_mode == 'hnd_ft': grok.getSite()['configuration'].next_matric_integer_2 += 1 return elif student.current_mode in ('nd_pt', 'hnd_pt'): grok.getSite()['configuration'].next_matric_integer_3 += 1 return return 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 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