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