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

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

Extend _requiredPaymentsMade.

  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1## $Id: utils.py 15072 2018-07-01 09:18:26Z 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        req_payments = ('ict_entre', 'logbook_combo', 'siwess_combo')
91        req_payments_titles = 'ICT, Logbook and SIWESS'
92        if len(student['payments']):
93            # All ND and HND of part time do not pay LOGBOOK
94            if student.current_mode.endswith('_pt'):
95                req_payments = ('ict_entre', 'siwess_combo')
96                req_payments_titles = 'ICT and SIWESS'
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'
113            num = 0
114            for ticket in student['payments'].values():
115                if ticket.p_state == 'paid' and \
116                    ticket.p_category in req_payments and \
117                    ticket.p_session == session:
118                    num += 1
119            if num == len(req_payments):
120                return True, None
121        return False, req_payments_titles
122
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.
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)
157        if category == 'schoolfee':
158            rpm, rpt = self._requiredPaymentsMade(student, p_session)
159            if not rpm:
160                return 'Pay %s fee(s) first.' % rpt, None
161            try:
162                certificate = student['studycourse'].certificate
163                p_item = certificate.code
164            except (AttributeError, TypeError):
165                return _('Study course data are incomplete.'), None
166            if previous_session:
167                amount = getattr(certificate, 'school_fee_1', 0.0)
168            else:
169                amount = getattr(certificate, 'school_fee_1', 0.0)
170                if student.state == RETURNING:
171                    # In case of returning school fee payment the
172                    # payment session and level contain the values of
173                    # the session the student has paid for. Payment
174                    # session is always next session.
175                    p_session, p_level = self.getReturningData(student)
176                    academic_session = self._getSessionConfiguration(p_session)
177                    if academic_session == None:
178                        return _(
179                            u'Session configuration object is not available.'
180                            ), None
181                   
182                elif student.is_postgrad and student.state == PAID:
183                    # Returning postgraduate students also pay for the
184                    # next session but their level always remains the
185                    # same.
186                    p_session += 1
187                    academic_session = self._getSessionConfiguration(p_session)
188                    if academic_session == None:
189                        return _(
190                            u'Session configuration object is not available.'
191                            ), None
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
214        elif category == 'logbook_combo':
215            amount = academic_session.logbook_combo_fee
216        elif category == 'ict_entre':
217            amount = academic_session.ict_entre_fee
218        elif category == 'siwess_combo':
219            amount = academic_session.siwess_combo_fee
220        elif category == 'transcript':
221            amount = academic_session.transcript_fee
222        elif category == 'certificate':
223            amount = academic_session.certificate_fee
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
230        if amount in (0.0, None):
231            return _('Amount could not be determined.'), None
232        if self.samePaymentMade(student, category, p_item, p_session):
233            return _('This type of payment has already been made.'), None
234        if self._isPaymentDisabled(p_session, category, student):
235            return _('This category of payments has been disabled.'), None
236        payment = createObject(u'waeup.StudentOnlinePayment')
237        timestamp = ("%d" % int(time()*10000))[1:]
238        payment.p_id = "p%s" % timestamp
239        payment.p_category = category
240        payment.p_item = p_item
241        payment.p_session = p_session
242        payment.p_level = p_level
243        payment.p_current = p_current
244        payment.amount_auth = amount
245        return None, payment
Note: See TracBrowser for help on using the repository browser.