## $Id: utils.py 14956 2018-02-28 17:47: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 ## from time import time from zope.component import createObject, getUtility from waeup.kofa.interfaces import (IKofaUtils, ADMITTED, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) from kofacustom.nigeria.students.utils import NigeriaStudentsUtils from kofacustom.dspg.interfaces import MessageFactory as _ def local(student): lga = getattr(student, 'lga') if lga and lga.startswith('delta'): return True return False class CustomStudentsUtils(NigeriaStudentsUtils): """A collection of customized methods. """ # prefix STUDENT_ID_PREFIX = u'P' def _dep_sug_paymentMade(self, student, session): if len(student['payments']): for ticket in student['payments'].values(): if ticket.p_state == 'paid' and \ ticket.p_category == 'dep_sug' and \ ticket.p_session == session: return True return False 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. 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: # Students can pay for previous sessions in all # workflow states. Fresh students are excluded by the # update method of the PreviousPaymentAddFormPage. if previous_level == 100: if local(student): amount = getattr(certificate, 'school_fee_1', 0.0) else: amount = getattr(certificate, 'school_fee_3', 0.0) else: if local(student): amount = getattr(certificate, 'school_fee_2', 0.0) else: amount = getattr(certificate, 'school_fee_4', 0.0) else: # Students are only allowed to pay school fee # if current session dep_sug payment has been made. if student.faccode != 'SPAT' and not self._dep_sug_paymentMade( student, student.current_session): return _('You have to pay NADESU/SA/SUG Dues first.'), None if student.state == CLEARED: if local(student): amount = getattr(certificate, 'school_fee_1', 0.0) else: amount = getattr(certificate, 'school_fee_3', 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. 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 if local(student): amount = getattr(certificate, 'school_fee_2', 0.0) else: amount = getattr(certificate, 'school_fee_4', 0.0) 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 if local(student): amount = getattr(certificate, 'school_fee_2', 0.0) else: amount = getattr(certificate, 'school_fee_4', 0.0) 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 # Local ND and HND students are given a rebate which has # to be adjusted if the basic acceptance fee changes. if student.current_mode == 'nd_ft' and local(student): amount -= 10000.0 if student.current_mode == 'hnd_ft' and local(student): amount -= 5000.0 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 == 'gown': amount = academic_session.gown_fee elif category == 'transcript': amount = academic_session.transcript_fee elif category == 'transfer': amount = academic_session.transfer_fee elif category == 'late_registration': amount = academic_session.late_registration_fee elif category == 'carryover1': amount = 10000.0 elif category == 'carryover2': amount = 10000.0 elif category == 'carryover3': amount = 10000.0 elif category == 'carryover4': amount = 13000.0 elif category == 'dep_sug': amount = 3150.0 # includes GATEWAY_AMT if student.faccode == 'SPAT': # amount = 1650.0 # includes GATEWAY_AMT amount = 0.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 warnCreditsOOR(self, studylevel, course=None): """Return message if credits are out of range. In the base package only maximum credits is set. """ if course and studylevel.total_credits + course.credits > 80: return _('Maximum credits exceeded.') elif studylevel.total_credits > 80: return _('Maximum credits exceeded.') return #: A tuple containing names of file upload viewlets which are not shown #: on the `StudentClearanceManageFormPage`. Nothing is being skipped #: in the base package. This attribute makes only sense, if intermediate #: custom packages are being used, like we do for all Nigerian portals. SKIP_UPLOAD_VIEWLETS = ('acceptanceletterupload', 'higherqualificationresultupload', 'advancedlevelresultupload', 'evidencenameupload', 'refereeletterupload', 'statutorydeclarationupload', 'firstsittingresultupload', 'secondsittingresultupload', 'certificateupload', 'resultstatementupload', ) #: A tuple containing the names of registration states in which changing of #: passport pictures is allowed. PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING,)