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

Last change on this file since 15061 was 15056, checked in by Henrik Bettermann, 7 years ago

Break up school fee into 4 items. 'ict_entre', 'logbook_combo' and 'siwess_combo' fees must be paid before 'schoolfee'.

  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1## $Id: utils.py 15056 2018-06-18 08:05:20Z 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
23from kofacustom.edopoly.interfaces import MessageFactory as _
24
25class CustomStudentsUtils(NigeriaStudentsUtils):
26    """A collection of customized methods.
27
28    """
29
30    # prefix
31    STUDENT_ID_PREFIX = u'U'
32
33    def warnCreditsOOR(self, studylevel, course=None):
34        """No maximum credits.
35        """
36        return
37
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'))
72
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
89    def _requiredPaymentsMade(self, student, session):
90        if len(student['payments']):
91            num = 0
92            for ticket in student['payments'].values():
93                if ticket.p_state == 'paid' and \
94                    ticket.p_category in (
95                        'ict_entre', 'logbook_combo', 'siwess_combo') and \
96                    ticket.p_session == session:
97                    num += 1
98            if num == 3:
99                return True
100        return False
101
102    def setPaymentDetails(self, category, student,
103            previous_session, previous_level):
104        """Create a payment ticket and set the payment data of a
105        student for the payment category specified.
106        """
107        p_item = u''
108        amount = 0.0
109        if previous_session:
110            if previous_session < student['studycourse'].entry_session:
111                return _('The previous session must not fall below '
112                         'your entry session.'), None
113            if category == 'schoolfee':
114                # School fee is always paid for the following session
115                if previous_session > student['studycourse'].current_session:
116                    return _('This is not a previous session.'), None
117            else:
118                if previous_session > student['studycourse'].current_session - 1:
119                    return _('This is not a previous session.'), None
120            p_session = previous_session
121            p_level = previous_level
122            p_current = False
123        else:
124            p_session = student['studycourse'].current_session
125            p_level = student['studycourse'].current_level
126            p_current = True
127        academic_session = self._getSessionConfiguration(p_session)
128        if academic_session == None:
129            return _(u'Session configuration object is not available.'), None
130        # Determine fee.
131        # The following three fees are part of the school fee which must be
132        # paid before tuition fee.
133        if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \
134            student.state == RETURNING:
135            p_session, p_level = self.getReturningData(student)
136        if category == 'schoolfee':
137            if not self._requiredPaymentsMade(student, p_session):
138                return _('Pay SIWES, Logbook and ICT fees first.'), None
139            try:
140                certificate = student['studycourse'].certificate
141                p_item = certificate.code
142            except (AttributeError, TypeError):
143                return _('Study course data are incomplete.'), None
144            if previous_session:
145                amount = getattr(certificate, 'school_fee_1', 0.0)
146            else:
147                amount = getattr(certificate, 'school_fee_1', 0.0)
148                if student.state == RETURNING:
149                    # In case of returning school fee payment the
150                    # payment session and level contain the values of
151                    # the session the student has paid for. Payment
152                    # session is always next session.
153                    p_session, p_level = self.getReturningData(student)
154                    academic_session = self._getSessionConfiguration(p_session)
155                    if academic_session == None:
156                        return _(
157                            u'Session configuration object is not available.'
158                            ), None
159                   
160                elif student.is_postgrad and student.state == PAID:
161                    # Returning postgraduate students also pay for the
162                    # next session but their level always remains the
163                    # same.
164                    p_session += 1
165                    academic_session = self._getSessionConfiguration(p_session)
166                    if academic_session == None:
167                        return _(
168                            u'Session configuration object is not available.'
169                            ), None
170        elif category == 'clearance':
171            try:
172                p_item = student['studycourse'].certificate.code
173            except (AttributeError, TypeError):
174                return _('Study course data are incomplete.'), None
175            amount = academic_session.clearance_fee
176        elif category == 'bed_allocation':
177            p_item = self.getAccommodationDetails(student)['bt']
178            amount = academic_session.booking_fee
179        elif category == 'hostel_maintenance':
180            amount = 0.0
181            bedticket = student['accommodation'].get(
182                str(student.current_session), None)
183            if bedticket is not None and bedticket.bed is not None:
184                p_item = bedticket.bed_coordinates
185                if bedticket.bed.__parent__.maint_fee > 0:
186                    amount = bedticket.bed.__parent__.maint_fee
187                else:
188                    # fallback
189                    amount = academic_session.maint_fee
190            else:
191                return _(u'No bed allocated.'), None
192        elif category == 'logbook_combo':
193            amount = academic_session.logbook_combo_fee
194        elif category == 'ict_entre':
195            amount = academic_session.ict_entre_fee
196        elif category == 'siwess_combo':
197            amount = academic_session.siwess_combo_fee
198        elif category == 'transcript':
199            amount = academic_session.transcript_fee
200        elif category == 'certificate':
201            amount = academic_session.certificate_fee
202        if amount in (0.0, None):
203            return _('Amount could not be determined.'), None
204        if self.samePaymentMade(student, category, p_item, p_session):
205            return _('This type of payment has already been made.'), None
206        if self._isPaymentDisabled(p_session, category, student):
207            return _('This category of payments has been disabled.'), None
208        payment = createObject(u'waeup.StudentOnlinePayment')
209        timestamp = ("%d" % int(time()*10000))[1:]
210        payment.p_id = "p%s" % timestamp
211        payment.p_category = category
212        payment.p_item = p_item
213        payment.p_session = p_session
214        payment.p_level = p_level
215        payment.p_current = p_current
216        payment.amount_auth = amount
217        return None, payment
Note: See TracBrowser for help on using the repository browser.