1 | ## $Id: utils.py 15013 2018-05-20 19:44:44Z 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 kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
24 | |
---|
25 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
26 | """A collection of customized methods. |
---|
27 | |
---|
28 | """ |
---|
29 | |
---|
30 | # prefix |
---|
31 | STUDENT_ID_PREFIX = u'U' |
---|
32 | |
---|
33 | def GPABoundaries(self, faccode=None, depcode=None, |
---|
34 | certcode=None, student=None): |
---|
35 | if student and student.current_mode.startswith('dp'): |
---|
36 | return ((1, 'IRNS / NER / NYV'), |
---|
37 | (2, 'Pass'), |
---|
38 | (2.5, 'Lower Credit'), |
---|
39 | (3, 'Upper Credit'), |
---|
40 | (3.5, 'Distinction')) |
---|
41 | elif student: |
---|
42 | return ((1, 'FRNS / NER / NYV'), |
---|
43 | (1.5, 'Pass'), |
---|
44 | (2.4, '3rd Class Honours'), |
---|
45 | (3.5, '2nd Class Honours Lower Division'), |
---|
46 | (4.5, '2nd Class Honours Upper Division'), |
---|
47 | (5, '1st Class Honours')) |
---|
48 | # Session Results Presentations depend on certificate |
---|
49 | results = None |
---|
50 | if certcode: |
---|
51 | cat = queryUtility(ICatalog, name='certificates_catalog') |
---|
52 | results = list( |
---|
53 | cat.searchResults(code=(certcode, certcode))) |
---|
54 | if results and results[0].study_mode.startswith('dp'): |
---|
55 | return ((1, 'IRNS / NER / NYV'), |
---|
56 | (2, 'Pass'), |
---|
57 | (2.5, 'Lower Credit'), |
---|
58 | (3, 'Upper Credit'), |
---|
59 | (3.5, 'Distinction')) |
---|
60 | else: |
---|
61 | return ((1, 'FRNS / NER / NYV'), |
---|
62 | (1.5, 'Pass'), |
---|
63 | (2.4, '3rd Class Honours'), |
---|
64 | (3.5, '2nd Class Honours Lower Division'), |
---|
65 | (4.5, '2nd Class Honours Upper Division'), |
---|
66 | (5, '1st Class Honours')) |
---|
67 | |
---|
68 | def getClassFromCGPA(self, gpa, student): |
---|
69 | gpa_boundaries = self.GPABoundaries(student=student) |
---|
70 | if gpa < gpa_boundaries[0][0]: |
---|
71 | return 0, gpa_boundaries[0][1] |
---|
72 | if gpa < gpa_boundaries[1][0]: |
---|
73 | return 1, gpa_boundaries[1][1] |
---|
74 | if gpa < gpa_boundaries[2][0]: |
---|
75 | return 2, gpa_boundaries[2][1] |
---|
76 | if gpa < gpa_boundaries[3][0]: |
---|
77 | return 3, gpa_boundaries[3][1] |
---|
78 | if gpa < gpa_boundaries[4][0]: |
---|
79 | return 4, gpa_boundaries[4][1] |
---|
80 | if gpa <= gpa_boundaries[5][0]: |
---|
81 | return 5, gpa_boundaries[5][1] |
---|
82 | return 'N/A' |
---|
83 | |
---|
84 | def setPaymentDetails(self, category, student, |
---|
85 | previous_session, previous_level): |
---|
86 | """Create a payment ticket and set the payment data of a |
---|
87 | student for the payment category specified. |
---|
88 | """ |
---|
89 | p_item = u'' |
---|
90 | amount = 0.0 |
---|
91 | if previous_session: |
---|
92 | if previous_session < student['studycourse'].entry_session: |
---|
93 | return _('The previous session must not fall below ' |
---|
94 | 'your entry session.'), None |
---|
95 | if category == 'schoolfee': |
---|
96 | # School fee is always paid for the following session |
---|
97 | if previous_session > student['studycourse'].current_session: |
---|
98 | return _('This is not a previous session.'), None |
---|
99 | else: |
---|
100 | if previous_session > student['studycourse'].current_session - 1: |
---|
101 | return _('This is not a previous session.'), None |
---|
102 | p_session = previous_session |
---|
103 | p_level = previous_level |
---|
104 | p_current = False |
---|
105 | else: |
---|
106 | p_session = student['studycourse'].current_session |
---|
107 | p_level = student['studycourse'].current_level |
---|
108 | p_current = True |
---|
109 | academic_session = self._getSessionConfiguration(p_session) |
---|
110 | if academic_session == None: |
---|
111 | return _(u'Session configuration object is not available.'), None |
---|
112 | # Determine fee. |
---|
113 | if category == 'schoolfee': |
---|
114 | try: |
---|
115 | certificate = student['studycourse'].certificate |
---|
116 | p_item = certificate.code |
---|
117 | except (AttributeError, TypeError): |
---|
118 | return _('Study course data are incomplete.'), None |
---|
119 | if previous_session: |
---|
120 | # Students can pay for previous sessions in all |
---|
121 | # workflow states. Fresh students are excluded by the |
---|
122 | # update method of the PreviousPaymentAddFormPage. |
---|
123 | if previous_level == 100: |
---|
124 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
125 | else: |
---|
126 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
127 | else: |
---|
128 | if student.state == CLEARED: |
---|
129 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
130 | elif student.state == RETURNING: |
---|
131 | # In case of returning school fee payment the |
---|
132 | # payment session and level contain the values of |
---|
133 | # the session the student has paid for. Payment |
---|
134 | # session is always next session. |
---|
135 | p_session, p_level = self.getReturningData(student) |
---|
136 | academic_session = self._getSessionConfiguration(p_session) |
---|
137 | if academic_session == None: |
---|
138 | return _( |
---|
139 | u'Session configuration object is not available.' |
---|
140 | ), None |
---|
141 | amount = getattr(certificate, 'school_fee_2', 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 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
153 | elif category == 'clearance': |
---|
154 | try: |
---|
155 | p_item = student['studycourse'].certificate.code |
---|
156 | except (AttributeError, TypeError): |
---|
157 | return _('Study course data are incomplete.'), None |
---|
158 | amount = academic_session.clearance_fee |
---|
159 | elif category == 'bed_allocation': |
---|
160 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
161 | amount = academic_session.booking_fee |
---|
162 | elif category == 'hostel_maintenance': |
---|
163 | amount = 0.0 |
---|
164 | bedticket = student['accommodation'].get( |
---|
165 | str(student.current_session), None) |
---|
166 | if bedticket is not None and bedticket.bed is not None: |
---|
167 | p_item = bedticket.bed_coordinates |
---|
168 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
169 | amount = bedticket.bed.__parent__.maint_fee |
---|
170 | else: |
---|
171 | # fallback |
---|
172 | amount = academic_session.maint_fee |
---|
173 | else: |
---|
174 | return _(u'No bed allocated.'), None |
---|
175 | elif category == 'logbook_combo': |
---|
176 | amount = academic_session.logbook_combo_fee |
---|
177 | elif category == 'ict_entre': |
---|
178 | amount = academic_session.ict_entre_fee |
---|
179 | elif category == 'siwess_combo': |
---|
180 | amount = academic_session.siwess_combo_fee |
---|
181 | if amount in (0.0, None): |
---|
182 | return _('Amount could not be determined.'), None |
---|
183 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
184 | return _('This type of payment has already been made.'), None |
---|
185 | if self._isPaymentDisabled(p_session, category, student): |
---|
186 | return _('This category of payments has been disabled.'), None |
---|
187 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
188 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
189 | payment.p_id = "p%s" % timestamp |
---|
190 | payment.p_category = category |
---|
191 | payment.p_item = p_item |
---|
192 | payment.p_session = p_session |
---|
193 | payment.p_level = p_level |
---|
194 | payment.p_current = p_current |
---|
195 | payment.amount_auth = amount |
---|
196 | return None, payment |
---|