1 | ## $Id: utils.py 11479 2014-03-07 18:31:32Z 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 | ## |
---|
18 | from time import time |
---|
19 | from zope.component import createObject, getUtility |
---|
20 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
21 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
22 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
23 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
24 | |
---|
25 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
26 | """A collection of customized methods. |
---|
27 | |
---|
28 | """ |
---|
29 | |
---|
30 | def getReturningData(self, student): |
---|
31 | """ This method defines what happens after school fee payment |
---|
32 | of returning students depending on the student's senate verdict. |
---|
33 | """ |
---|
34 | prev_level = student['studycourse'].current_level |
---|
35 | cur_verdict = student['studycourse'].current_verdict |
---|
36 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
37 | # Successful student |
---|
38 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
39 | elif cur_verdict == 'C': |
---|
40 | # Student on probation |
---|
41 | new_level = int(prev_level) + 10 |
---|
42 | else: |
---|
43 | # Student is somehow in an undefined state. |
---|
44 | # Level has to be set manually. |
---|
45 | new_level = prev_level |
---|
46 | new_session = student['studycourse'].current_session + 1 |
---|
47 | return new_session, new_level |
---|
48 | |
---|
49 | def _paymentMade(self, student, session): |
---|
50 | if len(student['payments']): |
---|
51 | for ticket in student['payments'].values(): |
---|
52 | if ticket.p_state == 'paid' and \ |
---|
53 | ticket.p_category == 'schoolfee' and \ |
---|
54 | ticket.p_session == session: |
---|
55 | return True |
---|
56 | return False |
---|
57 | |
---|
58 | def setPaymentDetails(self, category, student, |
---|
59 | previous_session, previous_level): |
---|
60 | """Create Payment object and set the payment data of a student for |
---|
61 | the payment category specified. |
---|
62 | |
---|
63 | """ |
---|
64 | p_item = u'' |
---|
65 | amount = 0.0 |
---|
66 | if previous_session: |
---|
67 | if previous_session < student['studycourse'].entry_session: |
---|
68 | return _('The previous session must not fall below ' |
---|
69 | 'your entry session.'), None |
---|
70 | if category == 'schoolfee': |
---|
71 | # School fee is always paid for the following session |
---|
72 | if previous_session > student['studycourse'].current_session: |
---|
73 | return _('This is not a previous session.'), None |
---|
74 | else: |
---|
75 | if previous_session > student['studycourse'].current_session - 1: |
---|
76 | return _('This is not a previous session.'), None |
---|
77 | p_session = previous_session |
---|
78 | p_level = previous_level |
---|
79 | p_current = False |
---|
80 | else: |
---|
81 | p_session = student['studycourse'].current_session |
---|
82 | p_level = student['studycourse'].current_level |
---|
83 | p_current = True |
---|
84 | academic_session = self._getSessionConfiguration(p_session) |
---|
85 | if academic_session == None: |
---|
86 | return _(u'Session configuration object is not available.'), None |
---|
87 | # Determine fee. |
---|
88 | if category == 'transfer': |
---|
89 | amount = academic_session.transfer_fee |
---|
90 | elif category == 'transcript': |
---|
91 | amount = academic_session.transcript_fee |
---|
92 | elif category == 'gown': |
---|
93 | amount = academic_session.gown_fee |
---|
94 | elif category == 'bed_allocation': |
---|
95 | amount = academic_session.booking_fee |
---|
96 | elif category == 'hostel_maintenance': |
---|
97 | amount = academic_session.maint_fee |
---|
98 | elif category == 'tempmaint_1': |
---|
99 | amount = 8150.0 |
---|
100 | elif category == 'tempmaint_2': |
---|
101 | amount = 12650.0 |
---|
102 | elif category == 'tempmaint_3': |
---|
103 | amount = 9650.0 |
---|
104 | elif category == 'clearance': |
---|
105 | p_item = student.certcode |
---|
106 | if p_item is None: |
---|
107 | return _('Study course data are incomplete.'), None |
---|
108 | if student.faccode == 'FCETA': |
---|
109 | amount = 22500.0 |
---|
110 | elif p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS', |
---|
111 | 'MBBSMED', 'MBBSNDU'): |
---|
112 | amount = 65000.0 |
---|
113 | elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
114 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
115 | amount = 22500.0 |
---|
116 | else: |
---|
117 | amount = 45000.0 |
---|
118 | elif category == 'schoolfee': |
---|
119 | try: |
---|
120 | certificate = student['studycourse'].certificate |
---|
121 | p_item = certificate.code |
---|
122 | except (AttributeError, TypeError): |
---|
123 | return _('Study course data are incomplete.'), None |
---|
124 | if previous_session: |
---|
125 | # Students can pay for previous sessions in all workflow states. |
---|
126 | # Fresh students are excluded by the update method of the |
---|
127 | # PreviousPaymentAddFormPage. |
---|
128 | if previous_session == student['studycourse'].entry_session: |
---|
129 | if student.is_foreigner: |
---|
130 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
131 | else: |
---|
132 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
133 | else: |
---|
134 | if student.is_foreigner: |
---|
135 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
136 | else: |
---|
137 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
138 | else: |
---|
139 | if student.state == CLEARED: |
---|
140 | if student.is_foreigner: |
---|
141 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
142 | else: |
---|
143 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
144 | elif student.state in (PAID, REGISTERED, VALIDATED): |
---|
145 | p_session += 1 |
---|
146 | # We don't know which level the student is paying for. |
---|
147 | p_level = None |
---|
148 | academic_session = self._getSessionConfiguration(p_session) |
---|
149 | if academic_session == None: |
---|
150 | return _(u'Session configuration object is not available.'), None |
---|
151 | |
---|
152 | # Students are only allowed to pay for the next session |
---|
153 | # if current session payment |
---|
154 | # has really been made, i.e. payment object exists. |
---|
155 | #if not self._paymentMade( |
---|
156 | # student, student.current_session): |
---|
157 | # return _('You have not yet paid your current/active' + |
---|
158 | # ' session. Please use the previous session' + |
---|
159 | # ' payment form first.'), None |
---|
160 | |
---|
161 | if student.is_foreigner: |
---|
162 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
163 | else: |
---|
164 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
165 | elif student.state == RETURNING: |
---|
166 | # In case of returning school fee payment the payment session |
---|
167 | # and level contain the values of the session the student |
---|
168 | # has paid for. |
---|
169 | p_session, p_level = self.getReturningData(student) |
---|
170 | academic_session = self._getSessionConfiguration(p_session) |
---|
171 | if academic_session == None: |
---|
172 | return _(u'Session configuration object is not available.'), None |
---|
173 | |
---|
174 | # Students are only allowed to pay for the next session |
---|
175 | # if current session payment has really been made, |
---|
176 | # i.e. payment object exists and is paid. |
---|
177 | #if not self._paymentMade( |
---|
178 | # student, student.current_session): |
---|
179 | # return _('You have not yet paid your current/active' + |
---|
180 | # ' session. Please use the previous session' + |
---|
181 | # ' payment form first.'), None |
---|
182 | |
---|
183 | if student.is_foreigner: |
---|
184 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
185 | else: |
---|
186 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
187 | # Give 50% school fee discount to staff members. |
---|
188 | if student.is_staff: |
---|
189 | amount /= 2 |
---|
190 | if amount in (0.0, None): |
---|
191 | return _('Amount could not be determined.'), None |
---|
192 | # Add session specific penalty fee. |
---|
193 | if category == 'schoolfee' and student.is_postgrad: |
---|
194 | amount += academic_session.penalty_pg |
---|
195 | elif category == 'schoolfee': |
---|
196 | amount += academic_session.penalty_ug |
---|
197 | # XXX: Obsolete in 2013 |
---|
198 | if category.startswith('tempmaint'): |
---|
199 | p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category] |
---|
200 | p_item = unicode(p_item) |
---|
201 | # Now we change the category because tempmaint payments |
---|
202 | # will be obsolete in 2013 |
---|
203 | category = 'hostel_maintenance' |
---|
204 | # Create ticket. |
---|
205 | for key in student['payments'].keys(): |
---|
206 | ticket = student['payments'][key] |
---|
207 | if ticket.p_state == 'paid' and\ |
---|
208 | ticket.p_category == category and \ |
---|
209 | ticket.p_item == p_item and \ |
---|
210 | ticket.p_session == p_session: |
---|
211 | return _('This type of payment has already been made.'), None |
---|
212 | if self._isPaymentDisabled(p_session, category, student): |
---|
213 | return _('Payment temporarily disabled.'), None |
---|
214 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
215 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
216 | payment.p_id = "p%s" % timestamp |
---|
217 | payment.p_category = category |
---|
218 | payment.p_item = p_item |
---|
219 | payment.p_session = p_session |
---|
220 | payment.p_level = p_level |
---|
221 | payment.p_current = p_current |
---|
222 | payment.amount_auth = amount |
---|
223 | return None, payment |
---|
224 | |
---|
225 | def maxCredits(self, studylevel): |
---|
226 | """Return maximum credits. |
---|
227 | |
---|
228 | """ |
---|
229 | studycourse = studylevel.__parent__ |
---|
230 | certificate = getattr(studycourse,'certificate', None) |
---|
231 | current_level = studycourse.current_level |
---|
232 | if None in (current_level, certificate): |
---|
233 | return 0 |
---|
234 | end_level = certificate.end_level |
---|
235 | if current_level >= end_level: |
---|
236 | return 51 |
---|
237 | return 50 |
---|
238 | |
---|
239 | # Uniben prefix |
---|
240 | STUDENT_ID_PREFIX = u'B' |
---|