[7419] | 1 | ## $Id: utils.py 10467 2013-08-07 11:32:20Z 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 | |
---|
[8270] | 31 | def getReturningData(self, student): |
---|
| 32 | """ This method defines what happens after school fee payment |
---|
[8319] | 33 | of returning students depending on the student's senate verdict. |
---|
[8270] | 34 | """ |
---|
[8319] | 35 | prev_level = student['studycourse'].current_level |
---|
| 36 | cur_verdict = student['studycourse'].current_verdict |
---|
| 37 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 38 | # Successful student |
---|
| 39 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 40 | elif cur_verdict == 'C': |
---|
| 41 | # Student on probation |
---|
| 42 | new_level = int(prev_level) + 10 |
---|
| 43 | else: |
---|
| 44 | # Student is somehow in an undefined state. |
---|
| 45 | # Level has to be set manually. |
---|
| 46 | new_level = prev_level |
---|
[8270] | 47 | new_session = student['studycourse'].current_session + 1 |
---|
| 48 | return new_session, new_level |
---|
| 49 | |
---|
[9154] | 50 | def setPaymentDetails(self, category, student, |
---|
| 51 | previous_session=None, previous_level=None): |
---|
[8600] | 52 | """Create Payment object and set the payment data of a student for |
---|
| 53 | the payment category specified. |
---|
| 54 | |
---|
| 55 | """ |
---|
[8306] | 56 | details = {} |
---|
[8600] | 57 | p_item = u'' |
---|
| 58 | amount = 0.0 |
---|
| 59 | error = u'' |
---|
[9154] | 60 | if previous_session: |
---|
| 61 | return _('Previous session payment not yet implemented.'), None |
---|
[8600] | 62 | p_session = student['studycourse'].current_session |
---|
| 63 | p_level = student['studycourse'].current_level |
---|
[9154] | 64 | p_current = True |
---|
[9527] | 65 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 66 | if academic_session == None: |
---|
[8600] | 67 | return _(u'Session configuration object is not available.'), None |
---|
[8677] | 68 | # Determine fee. |
---|
[7151] | 69 | if category == 'transfer': |
---|
[8600] | 70 | amount = academic_session.transfer_fee |
---|
[10467] | 71 | elif category == 'transcript': |
---|
| 72 | amount = academic_session.transcript_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 |
---|
[9905] | 82 | elif category == 'schoolfee': |
---|
[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 | if student.state == CLEARED: |
---|
[9905] | 89 | amount = academic_session.school_fee |
---|
[8961] | 90 | elif student.state == RETURNING or\ |
---|
| 91 | (student.is_postgrad and student.state == PAID): |
---|
[9527] | 92 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 93 | if academic_session == None: |
---|
| 94 | return _(u'Session configuration object is not available.'), None |
---|
[8961] | 95 | if student.state == RETURNING: |
---|
| 96 | p_session, p_level = self.getReturningData(student) |
---|
| 97 | else: |
---|
| 98 | # Returning postgraduate students also pay for the |
---|
| 99 | # next session but their level always remains the same. |
---|
| 100 | p_session += 1 |
---|
| 101 | try: |
---|
| 102 | academic_session = grok.getSite()[ |
---|
| 103 | 'configuration'][str(p_session)] |
---|
| 104 | except KeyError: |
---|
| 105 | return _(u'Session configuration object is not available.'), None |
---|
[9905] | 106 | amount = academic_session.school_fee |
---|
[8600] | 107 | else: |
---|
[8753] | 108 | return _('Wrong state.'), None |
---|
[8600] | 109 | if amount in (0.0, None): |
---|
| 110 | return _(u'Amount could not be determined.'), None |
---|
[8677] | 111 | # Add session specific penalty fee. |
---|
[9905] | 112 | if category == 'schoolfee' and student.is_postgrad: |
---|
[8677] | 113 | amount += academic_session.penalty_pg |
---|
[9905] | 114 | elif category == 'schoolfee': |
---|
[8677] | 115 | amount += academic_session.penalty_ug |
---|
| 116 | # Create ticket. |
---|
[8600] | 117 | for key in student['payments'].keys(): |
---|
| 118 | ticket = student['payments'][key] |
---|
| 119 | if ticket.p_state == 'paid' and\ |
---|
| 120 | ticket.p_category == category and \ |
---|
| 121 | ticket.p_item == p_item and \ |
---|
| 122 | ticket.p_session == p_session: |
---|
| 123 | return _('This type of payment has already been made.'), None |
---|
[8712] | 124 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8954] | 125 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8600] | 126 | payment.p_id = "p%s" % timestamp |
---|
| 127 | payment.p_category = category |
---|
| 128 | payment.p_item = p_item |
---|
| 129 | payment.p_session = p_session |
---|
| 130 | payment.p_level = p_level |
---|
[9154] | 131 | payment.p_current = p_current |
---|
[8600] | 132 | payment.amount_auth = amount |
---|
| 133 | return None, payment |
---|
[7621] | 134 | |
---|
[10051] | 135 | def maxCredits(self, studylevel): |
---|
| 136 | """Return maximum credits. |
---|
| 137 | |
---|
| 138 | """ |
---|
| 139 | return 48 |
---|
| 140 | |
---|
[8444] | 141 | # AAUE prefix |
---|
| 142 | STUDENT_ID_PREFIX = u'E' |
---|