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

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

No maximum credits.

  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
1## $Id: utils.py 15035 2018-05-30 16:45:29Z 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 setPaymentDetails(self, category, student,
90            previous_session, previous_level):
91        """Create a payment ticket and set the payment data of a
92        student for the payment category specified.
93        """
94        p_item = u''
95        amount = 0.0
96        if previous_session:
97            if previous_session < student['studycourse'].entry_session:
98                return _('The previous session must not fall below '
99                         'your entry session.'), None
100            if category == 'schoolfee':
101                # School fee is always paid for the following session
102                if previous_session > student['studycourse'].current_session:
103                    return _('This is not a previous session.'), None
104            else:
105                if previous_session > student['studycourse'].current_session - 1:
106                    return _('This is not a previous session.'), None
107            p_session = previous_session
108            p_level = previous_level
109            p_current = False
110        else:
111            p_session = student['studycourse'].current_session
112            p_level = student['studycourse'].current_level
113            p_current = True
114        academic_session = self._getSessionConfiguration(p_session)
115        if academic_session == None:
116            return _(u'Session configuration object is not available.'), None
117        # Determine fee.
118        if category == 'schoolfee':
119            try:
120                certificate = student['studycourse'].certificate
121                p_item = certificate.code
122            except (AttributeError, TypeError):
123                return _('Study course data are incomplete.'), None
124            if previous_session:
125                amount = getattr(certificate, 'school_fee_1', 0.0)
126            else:
127                amount = getattr(certificate, 'school_fee_1', 0.0)
128                if student.state == RETURNING:
129                    # In case of returning school fee payment the
130                    # payment session and level contain the values of
131                    # the session the student has paid for. Payment
132                    # session is always next session.
133                    p_session, p_level = self.getReturningData(student)
134                    academic_session = self._getSessionConfiguration(p_session)
135                    if academic_session == None:
136                        return _(
137                            u'Session configuration object is not available.'
138                            ), None
139                   
140                elif student.is_postgrad and student.state == PAID:
141                    # Returning postgraduate students also pay for the
142                    # next session but their level always remains the
143                    # same.
144                    p_session += 1
145                    academic_session = self._getSessionConfiguration(p_session)
146                    if academic_session == None:
147                        return _(
148                            u'Session configuration object is not available.'
149                            ), None
150        elif category == 'clearance':
151            try:
152                p_item = student['studycourse'].certificate.code
153            except (AttributeError, TypeError):
154                return _('Study course data are incomplete.'), None
155            amount = academic_session.clearance_fee
156        elif category == 'bed_allocation':
157            p_item = self.getAccommodationDetails(student)['bt']
158            amount = academic_session.booking_fee
159        elif category == 'hostel_maintenance':
160            amount = 0.0
161            bedticket = student['accommodation'].get(
162                str(student.current_session), None)
163            if bedticket is not None and bedticket.bed is not None:
164                p_item = bedticket.bed_coordinates
165                if bedticket.bed.__parent__.maint_fee > 0:
166                    amount = bedticket.bed.__parent__.maint_fee
167                else:
168                    # fallback
169                    amount = academic_session.maint_fee
170            else:
171                return _(u'No bed allocated.'), None
172        elif category == 'logbook_combo':
173            amount = academic_session.logbook_combo_fee
174        elif category == 'ict_entre':
175            amount = academic_session.ict_entre_fee
176        elif category == 'siwess_combo':
177            amount = academic_session.siwess_combo_fee
178        elif category == 'transcript':
179            amount = academic_session.transcript_fee
180        elif category == 'certificate':
181            amount = academic_session.certificate_fee
182        if amount in (0.0, None):
183            return _('Amount could not be determined.'), None
184        if self.samePaymentMade(student, category, p_item, p_session):
185            return _('This type of payment has already been made.'), None
186        if self._isPaymentDisabled(p_session, category, student):
187            return _('This category of payments has been disabled.'), None
188        payment = createObject(u'waeup.StudentOnlinePayment')
189        timestamp = ("%d" % int(time()*10000))[1:]
190        payment.p_id = "p%s" % timestamp
191        payment.p_category = category
192        payment.p_item = p_item
193        payment.p_session = p_session
194        payment.p_level = p_level
195        payment.p_current = p_current
196        payment.amount_auth = amount
197        return None, payment
Note: See TracBrowser for help on using the repository browser.