[7419] | 1 | ## $Id: utils.py 8775 2012-06-22 16:40: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 |
---|
[7822] | 22 | from waeup.kofa.students.utils import StudentsUtils |
---|
| 23 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[8247] | 24 | from waeup.kofa.accesscodes import create_accesscode |
---|
[8444] | 25 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[6902] | 26 | |
---|
[8204] | 27 | class CustomStudentsUtils(StudentsUtils): |
---|
[7151] | 28 | """A collection of customized methods. |
---|
| 29 | |
---|
| 30 | """ |
---|
| 31 | grok.implements(IStudentsUtils) |
---|
| 32 | |
---|
[8270] | 33 | def getReturningData(self, student): |
---|
| 34 | """ This method defines what happens after school fee payment |
---|
[8319] | 35 | of returning students depending on the student's senate verdict. |
---|
[8270] | 36 | """ |
---|
[8319] | 37 | prev_level = student['studycourse'].current_level |
---|
| 38 | cur_verdict = student['studycourse'].current_verdict |
---|
| 39 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 40 | # Successful student |
---|
| 41 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 42 | elif cur_verdict == 'C': |
---|
| 43 | # Student on probation |
---|
| 44 | new_level = int(prev_level) + 10 |
---|
| 45 | else: |
---|
| 46 | # Student is somehow in an undefined state. |
---|
| 47 | # Level has to be set manually. |
---|
| 48 | new_level = prev_level |
---|
[8270] | 49 | new_session = student['studycourse'].current_session + 1 |
---|
| 50 | return new_session, new_level |
---|
| 51 | |
---|
[8600] | 52 | def setPaymentDetails(self, category, student): |
---|
| 53 | """Create Payment object and set the payment data of a student for |
---|
| 54 | the payment category specified. |
---|
| 55 | |
---|
| 56 | """ |
---|
[8306] | 57 | details = {} |
---|
[8600] | 58 | p_item = u'' |
---|
| 59 | amount = 0.0 |
---|
| 60 | error = u'' |
---|
| 61 | p_session = student['studycourse'].current_session |
---|
| 62 | p_level = student['studycourse'].current_level |
---|
| 63 | session = str(p_session) |
---|
[7151] | 64 | try: |
---|
| 65 | academic_session = grok.getSite()['configuration'][session] |
---|
| 66 | except KeyError: |
---|
[8600] | 67 | return _(u'Session configuration object is not available.'), None |
---|
[8677] | 68 | # Determine fee. |
---|
[8769] | 69 | if category == 'schoolfee': |
---|
| 70 | return _('School fee has to be paid by two instalments.'), None |
---|
[7151] | 71 | if category == 'transfer': |
---|
[8600] | 72 | amount = academic_session.transfer_fee |
---|
[7151] | 73 | elif category == 'gown': |
---|
[8600] | 74 | amount = academic_session.gown_fee |
---|
[7151] | 75 | elif category == 'bed_allocation': |
---|
[8600] | 76 | amount = academic_session.booking_fee |
---|
[7151] | 77 | elif category == 'hostel_maintenance': |
---|
[8600] | 78 | amount = academic_session.maint_fee |
---|
[7151] | 79 | elif category == 'clearance': |
---|
[8753] | 80 | amount = academic_session.clearance_fee |
---|
| 81 | p_item = student['studycourse'].certificate.code |
---|
| 82 | elif category == 'schoolfee_1': |
---|
[8600] | 83 | try: |
---|
[8753] | 84 | certificate = student['studycourse'].certificate |
---|
| 85 | p_item = certificate.code |
---|
[8600] | 86 | except (AttributeError, TypeError): |
---|
| 87 | return _('Study course data are incomplete.'), None |
---|
[8753] | 88 | payment_allowed = False |
---|
| 89 | if student.state == CLEARED: |
---|
| 90 | payment_allowed = True |
---|
| 91 | amount = academic_session.school_fee_base |
---|
| 92 | elif student.state == RETURNING: |
---|
| 93 | p_session, p_level = self.getReturningData(student) |
---|
| 94 | initial_instalment_made = False |
---|
| 95 | for key in student['payments'].keys(): |
---|
| 96 | ticket = student['payments'][key] |
---|
[8775] | 97 | if ticket.p_category == 'schoolfee_1' and \ |
---|
| 98 | ticket.p_state == 'paid': |
---|
[8753] | 99 | initial_instalment_made = True |
---|
| 100 | if ticket.p_state == 'paid' and\ |
---|
[8775] | 101 | ticket.p_category == 'schoolfee_2' and \ |
---|
| 102 | ticket.p_item == p_item and \ |
---|
| 103 | ticket.p_session == p_session-1: # = current session |
---|
| 104 | payment_allowed = True |
---|
[8753] | 105 | if not initial_instalment_made: |
---|
| 106 | payment_allowed = True |
---|
| 107 | amount = academic_session.school_fee_base |
---|
[8600] | 108 | else: |
---|
[8753] | 109 | return _('Wrong state.'), None |
---|
| 110 | if not payment_allowed: |
---|
| 111 | return _('The previous 2nd school fee instalment ' |
---|
| 112 | 'has not yet been paid.'), None |
---|
| 113 | elif category == 'schoolfee_2': |
---|
[8600] | 114 | try: |
---|
| 115 | certificate = student['studycourse'].certificate |
---|
| 116 | p_item = certificate.code |
---|
| 117 | except (AttributeError, TypeError): |
---|
| 118 | return _('Study course data are incomplete.'), None |
---|
[8753] | 119 | payment_allowed = False |
---|
| 120 | for key in student['payments'].keys(): |
---|
| 121 | ticket = student['payments'][key] |
---|
| 122 | if ticket.p_state == 'paid' and\ |
---|
| 123 | ticket.p_category == 'schoolfee_1' and \ |
---|
| 124 | ticket.p_item == p_item and \ |
---|
| 125 | ticket.p_session == p_session: |
---|
| 126 | payment_allowed = True |
---|
| 127 | if not payment_allowed: |
---|
| 128 | return _('The 1st school fee instalment ' |
---|
[8775] | 129 | 'has not yet been paid or session has ' |
---|
| 130 | 'not yet been started.'), None |
---|
[8753] | 131 | amount = academic_session.school_fee_base |
---|
[8600] | 132 | if amount in (0.0, None): |
---|
| 133 | return _(u'Amount could not be determined.'), None |
---|
[8677] | 134 | # Add session specific penalty fee. |
---|
[8753] | 135 | if category == 'schoolfee_1' and student.is_postgrad: |
---|
[8677] | 136 | amount += academic_session.penalty_pg |
---|
[8753] | 137 | elif category == 'schoolfee_1': |
---|
[8677] | 138 | amount += academic_session.penalty_ug |
---|
| 139 | # Create ticket. |
---|
[8600] | 140 | for key in student['payments'].keys(): |
---|
| 141 | ticket = student['payments'][key] |
---|
| 142 | if ticket.p_state == 'paid' and\ |
---|
| 143 | ticket.p_category == category and \ |
---|
| 144 | ticket.p_item == p_item and \ |
---|
| 145 | ticket.p_session == p_session: |
---|
| 146 | return _('This type of payment has already been made.'), None |
---|
[8712] | 147 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8600] | 148 | timestamp = "%d" % int(time()*1000) |
---|
| 149 | payment.p_id = "p%s" % timestamp |
---|
| 150 | payment.p_category = category |
---|
| 151 | payment.p_item = p_item |
---|
| 152 | payment.p_session = p_session |
---|
| 153 | payment.p_level = p_level |
---|
| 154 | payment.amount_auth = amount |
---|
| 155 | return None, payment |
---|
[7621] | 156 | |
---|
[7845] | 157 | VERDICTS_DICT = { |
---|
[8623] | 158 | 'NY': 'not yet', |
---|
[7845] | 159 | 'A': 'Successful student', |
---|
| 160 | 'B': 'Student with carryover courses', |
---|
| 161 | 'C': 'Student on probation', |
---|
| 162 | 'D': 'Withdrawn from the faculty', |
---|
| 163 | 'E': 'Student who were previously on probation', |
---|
| 164 | 'F': 'Medical case', |
---|
| 165 | 'G': 'Absent from examination', |
---|
| 166 | 'H': 'Withheld results', |
---|
| 167 | 'I': 'Expelled/rusticated/suspended student', |
---|
| 168 | 'J': 'Temporary withdrawn from the university', |
---|
| 169 | 'K': 'Unregistered student', |
---|
| 170 | 'L': 'Referred student', |
---|
| 171 | 'M': 'Reinstatement', |
---|
| 172 | 'N': 'Student on transfer', |
---|
| 173 | 'O': 'NCE-III repeater', |
---|
| 174 | 'Y': 'No previous verdict', |
---|
| 175 | 'X': 'New 300 level student', |
---|
| 176 | 'Z': 'Successful student (provisional)', |
---|
| 177 | 'A1': 'First Class', |
---|
| 178 | 'A2': 'Second Class Upper', |
---|
| 179 | 'A3': 'Second Class Lower', |
---|
| 180 | 'A4': 'Third Class', |
---|
| 181 | 'A5': 'Pass', |
---|
| 182 | 'A6': 'Distinction', |
---|
| 183 | 'A7': 'Credit', |
---|
| 184 | 'A8': 'Merit', |
---|
| 185 | } |
---|
[8101] | 186 | |
---|
[8444] | 187 | # AAUE separators |
---|
[8101] | 188 | SEPARATORS_DICT = { |
---|
[8265] | 189 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
[8101] | 190 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
| 191 | 'form.alr_fname': _(u'Advanced Level Record'), |
---|
| 192 | 'form.hq_type': _(u'Higher Education Record'), |
---|
| 193 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
| 194 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 195 | 'form.employer': _(u'Employment History'), |
---|
[8444] | 196 | 'form.former_matric': _(u'Former AAUE Student'), |
---|
[8413] | 197 | } |
---|
| 198 | |
---|
[8444] | 199 | # AAUE prefix |
---|
| 200 | STUDENT_ID_PREFIX = u'E' |
---|