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

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

Further customize payment components.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1## $Id: utils.py 15015 2018-05-23 05:45:13Z 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 GPABoundaries(self, faccode=None, depcode=None,
34                            certcode=None, student=None):
35        if student and student.current_mode.startswith('dp'):
36                return ((1, 'IRNS / NER / NYV'),
37                        (2, 'Pass'),
38                        (2.5, 'Lower Credit'),
39                        (3, 'Upper Credit'),
40                        (3.5, 'Distinction'))
41        elif student:
42            return ((1, 'FRNS / NER / NYV'),
43                    (1.5, 'Pass'),
44                    (2.4, '3rd Class Honours'),
45                    (3.5, '2nd Class Honours Lower Division'),
46                    (4.5, '2nd Class Honours Upper Division'),
47                    (5, '1st Class Honours'))
48        # Session Results Presentations depend on certificate
49        results = None
50        if certcode:
51            cat = queryUtility(ICatalog, name='certificates_catalog')
52            results = list(
53                cat.searchResults(code=(certcode, certcode)))
54        if results and results[0].study_mode.startswith('dp'):
55            return ((1, 'IRNS / NER / NYV'),
56                    (2, 'Pass'),
57                    (2.5, 'Lower Credit'),
58                    (3, 'Upper Credit'),
59                    (3.5, 'Distinction'))
60        else:
61            return ((1, 'FRNS / NER / NYV'),
62                    (1.5, 'Pass'),
63                    (2.4, '3rd Class Honours'),
64                    (3.5, '2nd Class Honours Lower Division'),
65                    (4.5, '2nd Class Honours Upper Division'),
66                    (5, '1st Class Honours'))
67
68    def getClassFromCGPA(self, gpa, student):
69        gpa_boundaries = self.GPABoundaries(student=student)
70        if gpa < gpa_boundaries[0][0]:
71            return 0, gpa_boundaries[0][1]
72        if gpa < gpa_boundaries[1][0]:
73            return 1, gpa_boundaries[1][1]
74        if gpa < gpa_boundaries[2][0]:
75            return 2, gpa_boundaries[2][1]
76        if gpa < gpa_boundaries[3][0]:
77            return 3, gpa_boundaries[3][1]
78        if gpa < gpa_boundaries[4][0]:
79            return 4, gpa_boundaries[4][1]
80        if gpa <= gpa_boundaries[5][0]:
81            return 5, gpa_boundaries[5][1]
82        return 'N/A'
83
84    def setPaymentDetails(self, category, student,
85            previous_session, previous_level):
86        """Create a payment ticket and set the payment data of a
87        student for the payment category specified.
88        """
89        p_item = u''
90        amount = 0.0
91        if previous_session:
92            if previous_session < student['studycourse'].entry_session:
93                return _('The previous session must not fall below '
94                         'your entry session.'), None
95            if category == 'schoolfee':
96                # School fee is always paid for the following session
97                if previous_session > student['studycourse'].current_session:
98                    return _('This is not a previous session.'), None
99            else:
100                if previous_session > student['studycourse'].current_session - 1:
101                    return _('This is not a previous session.'), None
102            p_session = previous_session
103            p_level = previous_level
104            p_current = False
105        else:
106            p_session = student['studycourse'].current_session
107            p_level = student['studycourse'].current_level
108            p_current = True
109        academic_session = self._getSessionConfiguration(p_session)
110        if academic_session == None:
111            return _(u'Session configuration object is not available.'), None
112        # Determine fee.
113        if category == 'schoolfee':
114            try:
115                certificate = student['studycourse'].certificate
116                p_item = certificate.code
117            except (AttributeError, TypeError):
118                return _('Study course data are incomplete.'), None
119            if previous_session:
120                amount = getattr(certificate, 'school_fee_1', 0.0)
121            else:
122                amount = getattr(certificate, 'school_fee_1', 0.0)
123                if student.state == RETURNING:
124                    # In case of returning school fee payment the
125                    # payment session and level contain the values of
126                    # the session the student has paid for. Payment
127                    # session is always next session.
128                    p_session, p_level = self.getReturningData(student)
129                    academic_session = self._getSessionConfiguration(p_session)
130                    if academic_session == None:
131                        return _(
132                            u'Session configuration object is not available.'
133                            ), None
134                   
135                elif student.is_postgrad and student.state == PAID:
136                    # Returning postgraduate students also pay for the
137                    # next session but their level always remains the
138                    # same.
139                    p_session += 1
140                    academic_session = self._getSessionConfiguration(p_session)
141                    if academic_session == None:
142                        return _(
143                            u'Session configuration object is not available.'
144                            ), None
145        elif category == 'clearance':
146            try:
147                p_item = student['studycourse'].certificate.code
148            except (AttributeError, TypeError):
149                return _('Study course data are incomplete.'), None
150            amount = academic_session.clearance_fee
151        elif category == 'bed_allocation':
152            p_item = self.getAccommodationDetails(student)['bt']
153            amount = academic_session.booking_fee
154        elif category == 'hostel_maintenance':
155            amount = 0.0
156            bedticket = student['accommodation'].get(
157                str(student.current_session), None)
158            if bedticket is not None and bedticket.bed is not None:
159                p_item = bedticket.bed_coordinates
160                if bedticket.bed.__parent__.maint_fee > 0:
161                    amount = bedticket.bed.__parent__.maint_fee
162                else:
163                    # fallback
164                    amount = academic_session.maint_fee
165            else:
166                return _(u'No bed allocated.'), None
167        elif category == 'logbook_combo':
168            amount = academic_session.logbook_combo_fee
169        elif category == 'ict_entre':
170            amount = academic_session.ict_entre_fee
171        elif category == 'siwess_combo':
172            amount = academic_session.siwess_combo_fee
173        elif category == 'transcript':
174            amount = academic_session.transcript_fee
175        elif category == 'certificate':
176            amount = academic_session.certificate_fee
177        if amount in (0.0, None):
178            return _('Amount could not be determined.'), None
179        if self.samePaymentMade(student, category, p_item, p_session):
180            return _('This type of payment has already been made.'), None
181        if self._isPaymentDisabled(p_session, category, student):
182            return _('This category of payments has been disabled.'), None
183        payment = createObject(u'waeup.StudentOnlinePayment')
184        timestamp = ("%d" % int(time()*10000))[1:]
185        payment.p_id = "p%s" % timestamp
186        payment.p_category = category
187        payment.p_item = p_item
188        payment.p_session = p_session
189        payment.p_level = p_level
190        payment.p_current = p_current
191        payment.amount_auth = amount
192        return None, payment
Note: See TracBrowser for help on using the repository browser.