[7419] | 1 | ## $Id: utils.py 8678 2012-06-11 11:18:51Z 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 |
---|
[8598] | 19 | from time import time |
---|
| 20 | from zope.component import createObject |
---|
[8473] | 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 |
---|
[8619] | 25 | from waeup.futminna.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 | |
---|
[8598] | 33 | paymentfactory = u'waeup.CustomStudentOnlinePayment' |
---|
| 34 | |
---|
[8270] | 35 | def getReturningData(self, student): |
---|
| 36 | """ This method defines what happens after school fee payment |
---|
[8319] | 37 | of returning students depending on the student's senate verdict. |
---|
[8270] | 38 | """ |
---|
[8319] | 39 | prev_level = student['studycourse'].current_level |
---|
| 40 | cur_verdict = student['studycourse'].current_verdict |
---|
| 41 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 42 | # Successful student |
---|
| 43 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 44 | elif cur_verdict == 'C': |
---|
| 45 | # Student on probation |
---|
| 46 | new_level = int(prev_level) + 10 |
---|
| 47 | else: |
---|
| 48 | # Student is somehow in an undefined state. |
---|
| 49 | # Level has to be set manually. |
---|
| 50 | new_level = prev_level |
---|
[8270] | 51 | new_session = student['studycourse'].current_session + 1 |
---|
| 52 | return new_session, new_level |
---|
| 53 | |
---|
[8598] | 54 | def setPaymentDetails(self, category, student): |
---|
| 55 | """Create Payment object and set the payment data of a student for |
---|
| 56 | the payment category specified. |
---|
| 57 | |
---|
| 58 | """ |
---|
[8306] | 59 | details = {} |
---|
[8598] | 60 | p_item = u'' |
---|
| 61 | amount = 0.0 |
---|
| 62 | error = u'' |
---|
| 63 | p_session = student['studycourse'].current_session |
---|
| 64 | p_level = student['studycourse'].current_level |
---|
| 65 | session = str(p_session) |
---|
[7151] | 66 | try: |
---|
| 67 | academic_session = grok.getSite()['configuration'][session] |
---|
| 68 | except KeyError: |
---|
[8598] | 69 | return _(u'Session configuration object is not available.'), None |
---|
[8678] | 70 | # Determine fee. |
---|
[7151] | 71 | if category == 'transfer': |
---|
[8598] | 72 | amount = academic_session.transfer_fee |
---|
[7151] | 73 | elif category == 'gown': |
---|
[8598] | 74 | amount = academic_session.gown_fee |
---|
[7151] | 75 | elif category == 'bed_allocation': |
---|
[8598] | 76 | amount = academic_session.booking_fee |
---|
[7151] | 77 | elif category == 'hostel_maintenance': |
---|
[8598] | 78 | amount = academic_session.maint_fee |
---|
[7151] | 79 | elif category == 'clearance': |
---|
[8598] | 80 | try: |
---|
| 81 | p_item = student['studycourse'].certificate.code |
---|
| 82 | except (AttributeError, TypeError): |
---|
| 83 | return _('Study course data are incomplete.'), None |
---|
| 84 | if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
[8294] | 85 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
[8598] | 86 | amount = 17250.0 |
---|
[8294] | 87 | else: |
---|
[8598] | 88 | amount = 34250.0 |
---|
[7151] | 89 | elif category == 'schoolfee': |
---|
[8598] | 90 | try: |
---|
| 91 | certificate = student['studycourse'].certificate |
---|
| 92 | p_item = certificate.code |
---|
| 93 | except (AttributeError, TypeError): |
---|
| 94 | return _('Study course data are incomplete.'), None |
---|
| 95 | if student.state == CLEARED: |
---|
| 96 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 97 | elif student.state == RETURNING: |
---|
[8306] | 98 | # In case of returning school fee payment the payment session |
---|
| 99 | # and level contain the values of the session the student |
---|
| 100 | # has paid for. |
---|
[8598] | 101 | p_session, p_level = self.getReturningData(student) |
---|
| 102 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 103 | elif student.is_postgrad and student.state == PAID: |
---|
[8473] | 104 | # Returning postgraduate students also pay for the next session |
---|
| 105 | # but their level always remains the same. |
---|
[8598] | 106 | p_session += 1 |
---|
| 107 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 108 | if amount in (0.0, None): |
---|
| 109 | return _(u'Amount could not be determined.'), None |
---|
[8678] | 110 | # Add session specific penalty fee. |
---|
| 111 | if category == 'schoolfee' and student.is_postgrad: |
---|
| 112 | amount += academic_session.penalty_pg |
---|
| 113 | elif category == 'schoolfee': |
---|
| 114 | amount += academic_session.penalty_ug |
---|
| 115 | # Create ticket. |
---|
[8598] | 116 | for key in student['payments'].keys(): |
---|
| 117 | ticket = student['payments'][key] |
---|
| 118 | if ticket.p_state == 'paid' and\ |
---|
| 119 | ticket.p_category == category and \ |
---|
| 120 | ticket.p_item == p_item and \ |
---|
| 121 | ticket.p_session == p_session: |
---|
| 122 | return _('This type of payment has already been made.'), None |
---|
| 123 | payment = createObject(self.paymentfactory) |
---|
| 124 | timestamp = "%d" % int(time()*1000) |
---|
| 125 | payment.p_id = "p%s" % timestamp |
---|
| 126 | payment.p_category = category |
---|
| 127 | payment.p_item = p_item |
---|
| 128 | payment.p_session = p_session |
---|
| 129 | payment.p_level = p_level |
---|
| 130 | payment.amount_auth = amount |
---|
| 131 | return None, payment |
---|
[7621] | 132 | |
---|
[7845] | 133 | VERDICTS_DICT = { |
---|
[8625] | 134 | 'NY': 'not yet', |
---|
[7845] | 135 | 'A': 'Successful student', |
---|
| 136 | 'B': 'Student with carryover courses', |
---|
| 137 | 'C': 'Student on probation', |
---|
| 138 | 'D': 'Withdrawn from the faculty', |
---|
| 139 | 'E': 'Student who were previously on probation', |
---|
| 140 | 'F': 'Medical case', |
---|
| 141 | 'G': 'Absent from examination', |
---|
| 142 | 'H': 'Withheld results', |
---|
| 143 | 'I': 'Expelled/rusticated/suspended student', |
---|
| 144 | 'J': 'Temporary withdrawn from the university', |
---|
| 145 | 'K': 'Unregistered student', |
---|
| 146 | 'L': 'Referred student', |
---|
| 147 | 'M': 'Reinstatement', |
---|
| 148 | 'N': 'Student on transfer', |
---|
| 149 | 'O': 'NCE-III repeater', |
---|
| 150 | 'Y': 'No previous verdict', |
---|
| 151 | 'X': 'New 300 level student', |
---|
| 152 | 'Z': 'Successful student (provisional)', |
---|
| 153 | 'A1': 'First Class', |
---|
| 154 | 'A2': 'Second Class Upper', |
---|
| 155 | 'A3': 'Second Class Lower', |
---|
| 156 | 'A4': 'Third Class', |
---|
| 157 | 'A5': 'Pass', |
---|
| 158 | 'A6': 'Distinction', |
---|
| 159 | 'A7': 'Credit', |
---|
| 160 | 'A8': 'Merit', |
---|
| 161 | } |
---|
[8101] | 162 | |
---|
[8619] | 163 | # FUTMinna separators |
---|
[8101] | 164 | SEPARATORS_DICT = { |
---|
[8265] | 165 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
[8101] | 166 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
| 167 | 'form.alr_fname': _(u'Advanced Level Record'), |
---|
| 168 | 'form.hq_type': _(u'Higher Education Record'), |
---|
| 169 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
| 170 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 171 | 'form.employer': _(u'Employment History'), |
---|
[8619] | 172 | 'form.former_matric': _(u'Former FUTMinna Student'), |
---|
[8413] | 173 | } |
---|
| 174 | |
---|
[8619] | 175 | # FUTMinna prefix |
---|
| 176 | STUDENT_ID_PREFIX = u'M' |
---|