[7419] | 1 | ## $Id: utils.py 10641 2013-09-23 08:12:39Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[7151] | 18 | import grok |
---|
[8600] | 19 | from time import time |
---|
| 20 | from zope.component import createObject |
---|
[8474] | 21 | from waeup.kofa.interfaces import CLEARED, RETURNING, PAID |
---|
[8823] | 22 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[8247] | 23 | from waeup.kofa.accesscodes import create_accesscode |
---|
[8444] | 24 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[6902] | 25 | |
---|
[8823] | 26 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 27 | """A collection of customized methods. |
---|
| 28 | |
---|
| 29 | """ |
---|
| 30 | |
---|
[10641] | 31 | gpa_boundaries = ((1, 'FRNS'), |
---|
| 32 | (1.5, 'Pass'), |
---|
| 33 | (2.4, '3rd Class Honours'), |
---|
| 34 | (3.5, '2nd Class Honours Lower Division'), |
---|
| 35 | (4.5, '2nd Class Honours Upper Division'), |
---|
| 36 | (5, '1st Class Honours')) |
---|
| 37 | |
---|
[8270] | 38 | def getReturningData(self, student): |
---|
| 39 | """ This method defines what happens after school fee payment |
---|
[8319] | 40 | of returning students depending on the student's senate verdict. |
---|
[8270] | 41 | """ |
---|
[8319] | 42 | prev_level = student['studycourse'].current_level |
---|
| 43 | cur_verdict = student['studycourse'].current_verdict |
---|
| 44 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 45 | # Successful student |
---|
| 46 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 47 | elif cur_verdict == 'C': |
---|
| 48 | # Student on probation |
---|
| 49 | new_level = int(prev_level) + 10 |
---|
| 50 | else: |
---|
| 51 | # Student is somehow in an undefined state. |
---|
| 52 | # Level has to be set manually. |
---|
| 53 | new_level = prev_level |
---|
[8270] | 54 | new_session = student['studycourse'].current_session + 1 |
---|
| 55 | return new_session, new_level |
---|
| 56 | |
---|
[9154] | 57 | def setPaymentDetails(self, category, student, |
---|
| 58 | previous_session=None, previous_level=None): |
---|
[8600] | 59 | """Create Payment object and set the payment data of a student for |
---|
| 60 | the payment category specified. |
---|
| 61 | |
---|
| 62 | """ |
---|
[8306] | 63 | details = {} |
---|
[8600] | 64 | p_item = u'' |
---|
| 65 | amount = 0.0 |
---|
| 66 | error = u'' |
---|
[9154] | 67 | if previous_session: |
---|
| 68 | return _('Previous session payment not yet implemented.'), None |
---|
[8600] | 69 | p_session = student['studycourse'].current_session |
---|
| 70 | p_level = student['studycourse'].current_level |
---|
[9154] | 71 | p_current = True |
---|
[9527] | 72 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 73 | if academic_session == None: |
---|
[8600] | 74 | return _(u'Session configuration object is not available.'), None |
---|
[8677] | 75 | # Determine fee. |
---|
[7151] | 76 | if category == 'transfer': |
---|
[8600] | 77 | amount = academic_session.transfer_fee |
---|
[10467] | 78 | elif category == 'transcript': |
---|
| 79 | amount = academic_session.transcript_fee |
---|
[7151] | 80 | elif category == 'gown': |
---|
[8600] | 81 | amount = academic_session.gown_fee |
---|
[7151] | 82 | elif category == 'bed_allocation': |
---|
[8600] | 83 | amount = academic_session.booking_fee |
---|
[7151] | 84 | elif category == 'hostel_maintenance': |
---|
[8600] | 85 | amount = academic_session.maint_fee |
---|
[7151] | 86 | elif category == 'clearance': |
---|
[8753] | 87 | amount = academic_session.clearance_fee |
---|
| 88 | p_item = student['studycourse'].certificate.code |
---|
[9905] | 89 | elif category == 'schoolfee': |
---|
[8600] | 90 | try: |
---|
[8753] | 91 | certificate = student['studycourse'].certificate |
---|
| 92 | p_item = certificate.code |
---|
[8600] | 93 | except (AttributeError, TypeError): |
---|
| 94 | return _('Study course data are incomplete.'), None |
---|
[8753] | 95 | if student.state == CLEARED: |
---|
[9905] | 96 | amount = academic_session.school_fee |
---|
[8961] | 97 | elif student.state == RETURNING or\ |
---|
| 98 | (student.is_postgrad and student.state == PAID): |
---|
[9527] | 99 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 100 | if academic_session == None: |
---|
| 101 | return _(u'Session configuration object is not available.'), None |
---|
[8961] | 102 | if student.state == RETURNING: |
---|
| 103 | p_session, p_level = self.getReturningData(student) |
---|
| 104 | else: |
---|
| 105 | # Returning postgraduate students also pay for the |
---|
| 106 | # next session but their level always remains the same. |
---|
| 107 | p_session += 1 |
---|
| 108 | try: |
---|
| 109 | academic_session = grok.getSite()[ |
---|
| 110 | 'configuration'][str(p_session)] |
---|
| 111 | except KeyError: |
---|
| 112 | return _(u'Session configuration object is not available.'), None |
---|
[9905] | 113 | amount = academic_session.school_fee |
---|
[8600] | 114 | else: |
---|
[8753] | 115 | return _('Wrong state.'), None |
---|
[8600] | 116 | if amount in (0.0, None): |
---|
| 117 | return _(u'Amount could not be determined.'), None |
---|
[8677] | 118 | # Add session specific penalty fee. |
---|
[9905] | 119 | if category == 'schoolfee' and student.is_postgrad: |
---|
[8677] | 120 | amount += academic_session.penalty_pg |
---|
[9905] | 121 | elif category == 'schoolfee': |
---|
[8677] | 122 | amount += academic_session.penalty_ug |
---|
| 123 | # Create ticket. |
---|
[8600] | 124 | for key in student['payments'].keys(): |
---|
| 125 | ticket = student['payments'][key] |
---|
| 126 | if ticket.p_state == 'paid' and\ |
---|
| 127 | ticket.p_category == category and \ |
---|
| 128 | ticket.p_item == p_item and \ |
---|
| 129 | ticket.p_session == p_session: |
---|
| 130 | return _('This type of payment has already been made.'), None |
---|
[8712] | 131 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8954] | 132 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8600] | 133 | payment.p_id = "p%s" % timestamp |
---|
| 134 | payment.p_category = category |
---|
| 135 | payment.p_item = p_item |
---|
| 136 | payment.p_session = p_session |
---|
| 137 | payment.p_level = p_level |
---|
[9154] | 138 | payment.p_current = p_current |
---|
[8600] | 139 | payment.amount_auth = amount |
---|
| 140 | return None, payment |
---|
[7621] | 141 | |
---|
[10051] | 142 | def maxCredits(self, studylevel): |
---|
| 143 | """Return maximum credits. |
---|
| 144 | |
---|
| 145 | """ |
---|
| 146 | return 48 |
---|
| 147 | |
---|
[8444] | 148 | # AAUE prefix |
---|
| 149 | STUDENT_ID_PREFIX = u'E' |
---|