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

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

Maryanne: make the student union dues a fee on its own

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