1 | ## $Id: utils.py 15184 2018-10-04 06:41:49Z 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 | ADMITTED, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
22 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
23 | from kofacustom.dspg.interfaces import MessageFactory as _ |
---|
24 | |
---|
25 | |
---|
26 | def local(student): |
---|
27 | lga = getattr(student, 'lga') |
---|
28 | if lga and lga.startswith('delta'): |
---|
29 | return True |
---|
30 | return False |
---|
31 | |
---|
32 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
33 | """A collection of customized methods. |
---|
34 | """ |
---|
35 | |
---|
36 | # prefix |
---|
37 | STUDENT_ID_PREFIX = u'P' |
---|
38 | |
---|
39 | def _dep_sug_paymentMade(self, student, session): |
---|
40 | if len(student['payments']): |
---|
41 | for ticket in student['payments'].values(): |
---|
42 | if ticket.p_state == 'paid' and \ |
---|
43 | ticket.p_category == 'dep_sug' and \ |
---|
44 | ticket.p_session == session: |
---|
45 | return True |
---|
46 | return False |
---|
47 | |
---|
48 | def getReturningData(self, student): |
---|
49 | """ This method defines what happens after school fee payment |
---|
50 | of returning students depending on the student's senate verdict. |
---|
51 | """ |
---|
52 | prev_level = student['studycourse'].current_level |
---|
53 | cur_verdict = student['studycourse'].current_verdict |
---|
54 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
55 | # Successful student |
---|
56 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
57 | elif cur_verdict == 'C': |
---|
58 | # Student on probation |
---|
59 | new_level = int(prev_level) + 10 |
---|
60 | else: |
---|
61 | # Student is somehow in an undefined state. |
---|
62 | # Level has to be set manually. |
---|
63 | new_level = prev_level |
---|
64 | new_session = student['studycourse'].current_session + 1 |
---|
65 | return new_session, new_level |
---|
66 | |
---|
67 | def setPaymentDetails(self, category, student, |
---|
68 | previous_session, previous_level): |
---|
69 | """Create a payment ticket and set the payment data of a |
---|
70 | student for the payment category specified. |
---|
71 | """ |
---|
72 | p_item = u'' |
---|
73 | amount = 0.0 |
---|
74 | if previous_session: |
---|
75 | if previous_session < student['studycourse'].entry_session: |
---|
76 | return _('The previous session must not fall below ' |
---|
77 | 'your entry session.'), None |
---|
78 | if category == 'schoolfee': |
---|
79 | # School fee is always paid for the following session |
---|
80 | if previous_session > student['studycourse'].current_session: |
---|
81 | return _('This is not a previous session.'), None |
---|
82 | else: |
---|
83 | if previous_session > student['studycourse'].current_session - 1: |
---|
84 | return _('This is not a previous session.'), None |
---|
85 | p_session = previous_session |
---|
86 | p_level = previous_level |
---|
87 | p_current = False |
---|
88 | else: |
---|
89 | p_session = student['studycourse'].current_session |
---|
90 | p_level = student['studycourse'].current_level |
---|
91 | p_current = True |
---|
92 | academic_session = self._getSessionConfiguration(p_session) |
---|
93 | if academic_session == None: |
---|
94 | return _(u'Session configuration object is not available.'), None |
---|
95 | # Determine fee. |
---|
96 | if category == 'schoolfee': |
---|
97 | try: |
---|
98 | certificate = student['studycourse'].certificate |
---|
99 | p_item = certificate.code |
---|
100 | except (AttributeError, TypeError): |
---|
101 | return _('Study course data are incomplete.'), None |
---|
102 | if previous_session: |
---|
103 | # Students can pay for previous sessions in all |
---|
104 | # workflow states. Fresh students are excluded by the |
---|
105 | # update method of the PreviousPaymentAddFormPage. |
---|
106 | if previous_level == 100: |
---|
107 | if local(student): |
---|
108 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
109 | else: |
---|
110 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
111 | else: |
---|
112 | if local(student): |
---|
113 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
114 | else: |
---|
115 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
116 | else: |
---|
117 | # Students are only allowed to pay school fee |
---|
118 | # if current session dep_sug payment has been made. |
---|
119 | if student.faccode != 'SPAT' and not self._dep_sug_paymentMade( |
---|
120 | student, student.current_session): |
---|
121 | return _('You have to pay NADESU/SA/SUG Dues first.'), None |
---|
122 | if student.state == CLEARED: |
---|
123 | if local(student): |
---|
124 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
125 | else: |
---|
126 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
127 | elif student.state == RETURNING: |
---|
128 | # In case of returning school fee payment the |
---|
129 | # payment session and level contain the values of |
---|
130 | # the session the student has paid for. Payment |
---|
131 | # session is always next session. |
---|
132 | p_session, p_level = self.getReturningData(student) |
---|
133 | academic_session = self._getSessionConfiguration(p_session) |
---|
134 | if academic_session == None: |
---|
135 | return _( |
---|
136 | u'Session configuration object is not available.' |
---|
137 | ), None |
---|
138 | if local(student): |
---|
139 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
140 | else: |
---|
141 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
142 | elif student.is_postgrad and student.state == PAID: |
---|
143 | # Returning postgraduate students also pay for the |
---|
144 | # next session but their level always remains the |
---|
145 | # same. |
---|
146 | p_session += 1 |
---|
147 | academic_session = self._getSessionConfiguration(p_session) |
---|
148 | if academic_session == None: |
---|
149 | return _( |
---|
150 | u'Session configuration object is not available.' |
---|
151 | ), None |
---|
152 | if local(student): |
---|
153 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
154 | else: |
---|
155 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
156 | elif category == 'clearance': |
---|
157 | try: |
---|
158 | p_item = student['studycourse'].certificate.code |
---|
159 | except (AttributeError, TypeError): |
---|
160 | return _('Study course data are incomplete.'), None |
---|
161 | amount = academic_session.clearance_fee |
---|
162 | # Local ND and HND students are given a rebate which has |
---|
163 | # to be adjusted if the basic acceptance fee changes. |
---|
164 | if amount and student.current_mode == 'nd_ft' and local(student): |
---|
165 | amount -= 10000.0 |
---|
166 | if amount and student.current_mode == 'hnd_ft' and local(student): |
---|
167 | amount -= 5000.0 |
---|
168 | elif category == 'bed_allocation': |
---|
169 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
170 | amount = academic_session.booking_fee |
---|
171 | elif category == 'hostel_maintenance': |
---|
172 | amount = 0.0 |
---|
173 | bedticket = student['accommodation'].get( |
---|
174 | str(student.current_session), None) |
---|
175 | if bedticket is not None and bedticket.bed is not None: |
---|
176 | p_item = bedticket.bed_coordinates |
---|
177 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
178 | amount = bedticket.bed.__parent__.maint_fee |
---|
179 | else: |
---|
180 | # fallback |
---|
181 | amount = academic_session.maint_fee |
---|
182 | else: |
---|
183 | return _(u'No bed allocated.'), None |
---|
184 | elif category == 'carryover1': |
---|
185 | amount = 10000.0 |
---|
186 | elif category == 'carryover2': |
---|
187 | amount = 10000.0 |
---|
188 | elif category == 'carryover3': |
---|
189 | amount = 10000.0 |
---|
190 | elif category == 'carryover4': |
---|
191 | amount = 13000.0 |
---|
192 | elif category == 'dep_sug': |
---|
193 | amount = 3150.0 # includes GATEWAY_AMT |
---|
194 | if student.faccode == 'SPAT': |
---|
195 | # amount = 1650.0 # includes GATEWAY_AMT |
---|
196 | amount = 0.0 |
---|
197 | else: |
---|
198 | fee_name = category + '_fee' |
---|
199 | amount = getattr(academic_session, fee_name, 0.0) |
---|
200 | if amount in (0.0, None): |
---|
201 | return _('Amount could not be determined.'), None |
---|
202 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
203 | return _('This type of payment has already been made.'), None |
---|
204 | if self._isPaymentDisabled(p_session, category, student): |
---|
205 | return _('This category of payments has been disabled.'), None |
---|
206 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
207 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
208 | payment.p_id = "p%s" % timestamp |
---|
209 | payment.p_category = category |
---|
210 | payment.p_item = p_item |
---|
211 | payment.p_session = p_session |
---|
212 | payment.p_level = p_level |
---|
213 | payment.p_current = p_current |
---|
214 | payment.amount_auth = amount |
---|
215 | return None, payment |
---|
216 | |
---|
217 | def warnCreditsOOR(self, studylevel, course=None): |
---|
218 | """Return message if credits are out of range. In the base |
---|
219 | package only maximum credits is set. |
---|
220 | """ |
---|
221 | if course and studylevel.total_credits + course.credits > 80: |
---|
222 | return _('Maximum credits exceeded.') |
---|
223 | elif studylevel.total_credits > 80: |
---|
224 | return _('Maximum credits exceeded.') |
---|
225 | return |
---|
226 | |
---|
227 | #: A tuple containing names of file upload viewlets which are not shown |
---|
228 | #: on the `StudentClearanceManageFormPage`. Nothing is being skipped |
---|
229 | #: in the base package. This attribute makes only sense, if intermediate |
---|
230 | #: custom packages are being used, like we do for all Nigerian portals. |
---|
231 | SKIP_UPLOAD_VIEWLETS = ('acceptanceletterupload', |
---|
232 | 'higherqualificationresultupload', |
---|
233 | 'advancedlevelresultupload', |
---|
234 | 'evidencenameupload', |
---|
235 | 'refereeletterupload', |
---|
236 | 'statutorydeclarationupload', |
---|
237 | 'firstsittingresultupload', |
---|
238 | 'secondsittingresultupload', |
---|
239 | 'certificateupload', |
---|
240 | 'resultstatementupload', |
---|
241 | ) |
---|
242 | |
---|
243 | #: A tuple containing the names of registration states in which changing of |
---|
244 | #: passport pictures is allowed. |
---|
245 | PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING,) |
---|