## $Id: utils.py 15105 2018-08-13 05:55:02Z 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 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): req_payments = ('ict_entre', 'logbook_combo', 'siwess_combo') req_payments_titles = 'ICT, Logbook and SIWESS' if len(student['payments']): # All ND and HND of part time do not pay LOGBOOK if student.current_mode.endswith('_pt'): req_payments = ('ict_entre', 'siwess_combo') req_payments_titles = 'ICT and SIWESS' # HND2 full time do not pay for SIWES elif student.current_mode == 'hnd_ft' and student.state == RETURNING: req_payments = ('ict_entre', 'logbook_combo') req_payments_titles = 'ICT and Logbook' # HND1 full time do not pay both SIWES and LOGBOOK elif student.current_mode == 'hnd_ft' and student.state == CLEARED: 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', 'siwess_combo') req_payments_titles = 'ICT and SIWESS' # ND1 full time do not pay SIWES elif student.current_mode == 'nd_ft' and student.state == CLEARED: req_payments = ('ict_entre', 'logbook_combo') req_payments_titles = 'ICT and Logbook' num = 0 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 setPaymentDetails(self, category, student, previous_session, previous_level): """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 academic_session = self._getSessionConfiguration(p_session) if academic_session == None: return _(u'Session configuration object is not available.'), None # Determine fee. # The following three fees are part of the school fee which must be # paid before tuition fee. if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \ student.state == RETURNING: p_session, p_level = self.getReturningData(student) 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: amount = getattr(certificate, 'school_fee_1', 0.0) if 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. 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. 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 == 'logbook_combo': amount = academic_session.logbook_combo_fee elif category == 'ict_entre': amount = academic_session.ict_entre_fee elif category == 'siwess_combo': amount = academic_session.siwess_combo_fee elif category == 'transcript': amount = academic_session.transcript_fee elif category == 'certificate': amount = academic_session.certificate_fee elif category == 'certificate_confirm': amount = academic_session.certificate_confirm_fee elif category == 'final_clearance': amount = academic_session.final_clearance_fee elif category == 'late_registration': amount = academic_session.late_registration_fee elif category == 'union': amount = academic_session.union_fee 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