source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/utils.py @ 15314

Last change on this file since 15314 was 15301, checked in by Henrik Bettermann, 6 years ago

Remove SIWESS fee payment requirement.

  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
1## $Id: utils.py 15301 2019-01-18 08:51:24Z 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##
18from time import time
19import grok
20from zope.component import createObject, getUtility
21from waeup.kofa.interfaces import (IKofaUtils,
22    CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from kofacustom.edopoly.interfaces import MessageFactory as _
25
26class CustomStudentsUtils(NigeriaStudentsUtils):
27    """A collection of customized methods.
28
29    """
30
31    # prefix
32    STUDENT_ID_PREFIX = u'U'
33
34    def warnCreditsOOR(self, studylevel, course=None):
35        """No maximum credits.
36        """
37        return
38
39    def GPABoundaries(self, faccode=None, depcode=None,
40                            certcode=None, student=None):
41        if student and student.current_mode.startswith('dp'):
42                return ((1, 'IRNS / NER / NYV'),
43                        (2, 'Pass'),
44                        (2.5, 'Lower Credit'),
45                        (3, 'Upper Credit'),
46                        (3.5, 'Distinction'))
47        elif student:
48            return ((1, 'FRNS / NER / NYV'),
49                    (1.5, 'Pass'),
50                    (2.4, '3rd Class Honours'),
51                    (3.5, '2nd Class Honours Lower Division'),
52                    (4.5, '2nd Class Honours Upper Division'),
53                    (5, '1st Class Honours'))
54        # Session Results Presentations depend on certificate
55        results = None
56        if certcode:
57            cat = queryUtility(ICatalog, name='certificates_catalog')
58            results = list(
59                cat.searchResults(code=(certcode, certcode)))
60        if results and results[0].study_mode.startswith('dp'):
61            return ((1, 'IRNS / NER / NYV'),
62                    (2, 'Pass'),
63                    (2.5, 'Lower Credit'),
64                    (3, 'Upper Credit'),
65                    (3.5, 'Distinction'))
66        else:
67            return ((1, 'FRNS / NER / NYV'),
68                    (1.5, 'Pass'),
69                    (2.4, '3rd Class Honours'),
70                    (3.5, '2nd Class Honours Lower Division'),
71                    (4.5, '2nd Class Honours Upper Division'),
72                    (5, '1st Class Honours'))
73
74    def getClassFromCGPA(self, gpa, student):
75        gpa_boundaries = self.GPABoundaries(student=student)
76        if gpa < gpa_boundaries[0][0]:
77            return 0, gpa_boundaries[0][1]
78        if gpa < gpa_boundaries[1][0]:
79            return 1, gpa_boundaries[1][1]
80        if gpa < gpa_boundaries[2][0]:
81            return 2, gpa_boundaries[2][1]
82        if gpa < gpa_boundaries[3][0]:
83            return 3, gpa_boundaries[3][1]
84        if gpa < gpa_boundaries[4][0]:
85            return 4, gpa_boundaries[4][1]
86        if gpa <= gpa_boundaries[5][0]:
87            return 5, gpa_boundaries[5][1]
88        return 'N/A'
89
90    def _requiredPaymentsMade(self, student, session):
91        # SIWESS fee requirement removed on 18/01/2019
92        req_payments = ('ict_entre', 'logbook_combo')
93        req_payments_titles = 'ICT and Logbook'
94        if len(student['payments']):
95            # All ND and HND part time do not pay LOGBOOK
96            if student.current_mode.endswith('_pt'):
97                req_payments = ('ict_entre',)
98                req_payments_titles = 'ICT'
99            # HND2 full time do not pay for SIWES
100            #elif student.current_mode == 'hnd_ft' and student.state == RETURNING:
101            #    req_payments = ('ict_entre', 'logbook_combo')
102            #    req_payments_titles = 'ICT and Logbook'
103            # HND1 full time do not pay both LOGBOOK
104            elif student.current_mode == 'hnd_ft' and student.state == CLEARED:
105                req_payments = ('ict_entre',)
106                req_payments_titles = 'ICT'
107            # ND2 FULL TIME Do not pay LOGBOOK
108            elif student.current_mode == 'nd_ft' and student.state == RETURNING:
109                req_payments = ('ict_entre',)
110                req_payments_titles = 'ICT'
111            # ND1 full time do not pay SIWES
112            #elif student.current_mode == 'nd_ft' and student.state == CLEARED:
113            #    req_payments = ('ict_entre', 'logbook_combo')
114            #    req_payments_titles = 'ICT and Logbook'
115            num = 0
116            for ticket in student['payments'].values():
117                if ticket.p_state == 'paid' and \
118                    ticket.p_category in req_payments and \
119                    ticket.p_session == session:
120                    num += 1
121            if num == len(req_payments):
122                return True, None
123        return False, req_payments_titles
124
125    def setPaymentDetails(self, category, student,
126            previous_session, previous_level):
127        """Create a payment ticket and set the payment data of a
128        student for the payment category specified.
129        """
130        p_item = u''
131        amount = 0.0
132        if previous_session:
133            if previous_session < student['studycourse'].entry_session:
134                return _('The previous session must not fall below '
135                         'your entry session.'), None
136            if category == 'schoolfee':
137                # School fee is always paid for the following session
138                if previous_session > student['studycourse'].current_session:
139                    return _('This is not a previous session.'), None
140            else:
141                if previous_session > student['studycourse'].current_session - 1:
142                    return _('This is not a previous session.'), None
143            p_session = previous_session
144            p_level = previous_level
145            p_current = False
146        else:
147            p_session = student['studycourse'].current_session
148            p_level = student['studycourse'].current_level
149            p_current = True
150        academic_session = self._getSessionConfiguration(p_session)
151        if academic_session == None:
152            return _(u'Session configuration object is not available.'), None
153        # Determine fee.
154        # The following three fees are part of the school fee which must be
155        # paid before tuition fee.
156        if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \
157            student.state == RETURNING and not previous_session:
158            p_session, p_level = self.getReturningData(student)
159        if category == 'schoolfee':
160            try:
161                certificate = student['studycourse'].certificate
162                p_item = certificate.code
163            except (AttributeError, TypeError):
164                return _('Study course data are incomplete.'), None
165            if previous_session:
166                amount = getattr(certificate, 'school_fee_1', 0.0)
167            else:
168                amount = getattr(certificate, 'school_fee_1', 0.0)
169                if student.state == RETURNING:
170                    # In case of returning school fee payment the
171                    # payment session and level contain the values of
172                    # the session the student has paid for. Payment
173                    # session is always next session.
174                    p_session, p_level = self.getReturningData(student)
175                    academic_session = self._getSessionConfiguration(p_session)
176                    if academic_session == None:
177                        return _(
178                            u'Session configuration object is not available.'
179                            ), None
180                   
181                elif student.is_postgrad and student.state == PAID:
182                    # Returning postgraduate students also pay for the
183                    # next session but their level always remains the
184                    # same.
185                    p_session += 1
186                    academic_session = self._getSessionConfiguration(p_session)
187                    if academic_session == None:
188                        return _(
189                            u'Session configuration object is not available.'
190                            ), None
191            rpm, rpt = self._requiredPaymentsMade(student, p_session)
192            if not rpm:
193                return 'Pay %s fee(s) first.' % rpt, None
194        elif category == 'clearance':
195            try:
196                p_item = student['studycourse'].certificate.code
197            except (AttributeError, TypeError):
198                return _('Study course data are incomplete.'), None
199            amount = academic_session.clearance_fee
200        elif category == 'bed_allocation':
201            p_item = self.getAccommodationDetails(student)['bt']
202            amount = academic_session.booking_fee
203        elif category == 'hostel_maintenance':
204            amount = 0.0
205            bedticket = student['accommodation'].get(
206                str(student.current_session), None)
207            if bedticket is not None and bedticket.bed is not None:
208                p_item = bedticket.bed_coordinates
209                if bedticket.bed.__parent__.maint_fee > 0:
210                    amount = bedticket.bed.__parent__.maint_fee
211                else:
212                    # fallback
213                    amount = academic_session.maint_fee
214            else:
215                return _(u'No bed allocated.'), None
216        else:
217            fee_name = category + '_fee'
218            amount = getattr(academic_session, fee_name, 0.0)
219        if amount in (0.0, None):
220            return _('Amount could not be determined.'), None
221        if self.samePaymentMade(student, category, p_item, p_session):
222            return _('This type of payment has already been made.'), None
223        if self._isPaymentDisabled(p_session, category, student):
224            return _('This category of payments has been disabled.'), None
225        payment = createObject(u'waeup.StudentOnlinePayment')
226        timestamp = ("%d" % int(time()*10000))[1:]
227        payment.p_id = "p%s" % timestamp
228        payment.p_category = category
229        payment.p_item = p_item
230        payment.p_session = p_session
231        payment.p_level = p_level
232        payment.p_current = p_current
233        payment.amount_auth = amount
234        return None, payment
235
236    def constructMatricNumber(self, student):
237        faccode = student.faccode
238        #depcode = student.depcode
239        #certcode = student.certcode
240        year = unicode(student.entry_session)[2:]
241        if not student.state in (PAID, ) or not student.is_fresh:
242            return _('Matriculation number cannot be set.'), None
243
244        # SASND1809001
245        if student.current_mode == 'nd_ft':
246            next_integer = grok.getSite()['configuration'].next_matric_integer
247            if next_integer == 0:
248                return _('Matriculation number cannot be set.'), None
249            return None, "%s/ND/%s/%05d" % (faccode, year, next_integer)
250
251        # SASNH1809001
252        if student.current_mode == 'hnd_ft':
253            next_integer = grok.getSite()['configuration'].next_matric_integer_2
254            if next_integer == 0:
255                return _('Matriculation number cannot be set.'), None
256            return None, "%s/HD/%s/%05d" % (faccode, year, next_integer)
257
258        # SASPT1809001
259        if student.current_mode in ('nd_pt', 'hnd_pt'):
260            next_integer = grok.getSite()['configuration'].next_matric_integer_3
261            if next_integer == 0:
262                return _('Matriculation number cannot be set.'), None
263            return None, "%s/PT/%s/%05d" % (faccode, year, next_integer)
264
265        return _('Matriculation number cannot be set.'), None
266
267    def getAccommodationDetails(self, student):
268        """Determine the accommodation data of a student.
269        """
270        d = {}
271        d['error'] = u''
272        hostels = grok.getSite()['hostels']
273        d['booking_session'] = hostels.accommodation_session
274        d['allowed_states'] = hostels.accommodation_states
275        d['startdate'] = hostels.startdate
276        d['enddate'] = hostels.enddate
277        d['expired'] = hostels.expired
278        # Determine bed type
279        studycourse = student['studycourse']
280        certificate = getattr(studycourse,'certificate',None)
281        entry_session = studycourse.entry_session
282        current_level = studycourse.current_level
283        if None in (entry_session, current_level, certificate):
284            return d
285        bt = 'all'
286        if student.sex == 'f':
287            sex = 'female'
288        else:
289            sex = 'male'
290        special_handling = 'regular'
291        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
292        return d
Note: See TracBrowser for help on using the repository browser.