source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/students/utils.py @ 14961

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

Customize warnCreditsOOR.

  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1## $Id: utils.py 14956 2018-02-28 17:47:23Z 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    ADMITTED, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
23from kofacustom.dspg.interfaces import MessageFactory as _
24
25
26def local(student):
27    lga = getattr(student, 'lga')
28    if lga and lga.startswith('delta'):
29        return True
30    return False
31
32class CustomStudentsUtils(NigeriaStudentsUtils):
33    """A collection of customized methods.
34    """
35
36    # prefix
37    STUDENT_ID_PREFIX = u'P'
38
39    def _dep_sug_paymentMade(self, student, session):
40        if len(student['payments']):
41            for ticket in student['payments'].values():
42                if ticket.p_state == 'paid' and \
43                    ticket.p_category == 'dep_sug' and \
44                    ticket.p_session == session:
45                    return True
46        return False
47
48    def setPaymentDetails(self, category, student,
49            previous_session, previous_level):
50        """Create a payment ticket and set the payment data of a
51        student for the payment category specified.
52        """
53        p_item = u''
54        amount = 0.0
55        if previous_session:
56            if previous_session < student['studycourse'].entry_session:
57                return _('The previous session must not fall below '
58                         'your entry session.'), None
59            if category == 'schoolfee':
60                # School fee is always paid for the following session
61                if previous_session > student['studycourse'].current_session:
62                    return _('This is not a previous session.'), None
63            else:
64                if previous_session > student['studycourse'].current_session - 1:
65                    return _('This is not a previous session.'), None
66            p_session = previous_session
67            p_level = previous_level
68            p_current = False
69        else:
70            p_session = student['studycourse'].current_session
71            p_level = student['studycourse'].current_level
72            p_current = True
73        academic_session = self._getSessionConfiguration(p_session)
74        if academic_session == None:
75            return _(u'Session configuration object is not available.'), None
76        # Determine fee.
77        if category == 'schoolfee':
78            try:
79                certificate = student['studycourse'].certificate
80                p_item = certificate.code
81            except (AttributeError, TypeError):
82                return _('Study course data are incomplete.'), None
83            if previous_session:
84                # Students can pay for previous sessions in all
85                # workflow states.  Fresh students are excluded by the
86                # update method of the PreviousPaymentAddFormPage.
87                if previous_level == 100:
88                    if local(student):
89                        amount = getattr(certificate, 'school_fee_1', 0.0)
90                    else:
91                        amount = getattr(certificate, 'school_fee_3', 0.0)
92                else:
93                    if local(student):
94                        amount = getattr(certificate, 'school_fee_2', 0.0)
95                    else:
96                        amount = getattr(certificate, 'school_fee_4', 0.0)
97            else:
98                # Students are only allowed to pay school fee
99                # if current session dep_sug payment has been made.
100                if student.faccode != 'SPAT' and not self._dep_sug_paymentMade(
101                    student, student.current_session):
102                    return _('You have to pay NADESU/SA/SUG Dues first.'), None
103                if student.state == CLEARED:
104                    if local(student):
105                        amount = getattr(certificate, 'school_fee_1', 0.0)
106                    else:
107                        amount = getattr(certificate, 'school_fee_3', 0.0)
108                elif student.state == RETURNING:
109                    # In case of returning school fee payment the
110                    # payment session and level contain the values of
111                    # the session the student has paid for. Payment
112                    # session is always next session.
113                    p_session, p_level = self.getReturningData(student)
114                    academic_session = self._getSessionConfiguration(p_session)
115                    if academic_session == None:
116                        return _(
117                            u'Session configuration object is not available.'
118                            ), None
119                    if local(student):
120                        amount = getattr(certificate, 'school_fee_2', 0.0)
121                    else:
122                        amount = getattr(certificate, 'school_fee_4', 0.0)
123                elif student.is_postgrad and student.state == PAID:
124                    # Returning postgraduate students also pay for the
125                    # next session but their level always remains the
126                    # same.
127                    p_session += 1
128                    academic_session = self._getSessionConfiguration(p_session)
129                    if academic_session == None:
130                        return _(
131                            u'Session configuration object is not available.'
132                            ), None
133                    if local(student):
134                        amount = getattr(certificate, 'school_fee_2', 0.0)
135                    else:
136                        amount = getattr(certificate, 'school_fee_4', 0.0)
137        elif category == 'clearance':
138            try:
139                p_item = student['studycourse'].certificate.code
140            except (AttributeError, TypeError):
141                return _('Study course data are incomplete.'), None
142            amount = academic_session.clearance_fee
143            # Local ND and HND students are given a rebate which has
144            # to be adjusted if the basic acceptance fee changes.
145            if student.current_mode == 'nd_ft' and local(student):
146                amount -= 10000.0
147            if student.current_mode == 'hnd_ft' and local(student):
148                amount -= 5000.0
149        elif category == 'bed_allocation':
150            p_item = self.getAccommodationDetails(student)['bt']
151            amount = academic_session.booking_fee
152        elif category == 'hostel_maintenance':
153            amount = 0.0
154            bedticket = student['accommodation'].get(
155                str(student.current_session), None)
156            if bedticket is not None and bedticket.bed is not None:
157                p_item = bedticket.bed_coordinates
158                if bedticket.bed.__parent__.maint_fee > 0:
159                    amount = bedticket.bed.__parent__.maint_fee
160                else:
161                    # fallback
162                    amount = academic_session.maint_fee
163            else:
164                return _(u'No bed allocated.'), None
165        elif category == 'gown':
166            amount = academic_session.gown_fee
167        elif category == 'transcript':
168            amount = academic_session.transcript_fee
169        elif category == 'transfer':
170            amount = academic_session.transfer_fee
171        elif category == 'late_registration':
172            amount = academic_session.late_registration_fee
173        elif category == 'carryover1':
174            amount = 10000.0
175        elif category == 'carryover2':
176            amount = 10000.0
177        elif category == 'carryover3':
178            amount = 10000.0
179        elif category == 'carryover4':
180            amount = 13000.0
181        elif category == 'dep_sug':
182            amount = 3150.0 # includes GATEWAY_AMT
183            if student.faccode == 'SPAT':
184            #    amount = 1650.0 # includes GATEWAY_AMT
185                amount = 0.0
186        else:
187            fee_name = category + '_fee'
188            amount = getattr(academic_session, fee_name, 0.0)
189        if amount in (0.0, None):
190            return _('Amount could not be determined.'), None
191        if self.samePaymentMade(student, category, p_item, p_session):
192            return _('This type of payment has already been made.'), None
193        if self._isPaymentDisabled(p_session, category, student):
194            return _('This category of payments has been disabled.'), None
195        payment = createObject(u'waeup.StudentOnlinePayment')
196        timestamp = ("%d" % int(time()*10000))[1:]
197        payment.p_id = "p%s" % timestamp
198        payment.p_category = category
199        payment.p_item = p_item
200        payment.p_session = p_session
201        payment.p_level = p_level
202        payment.p_current = p_current
203        payment.amount_auth = amount
204        return None, payment
205
206    def warnCreditsOOR(self, studylevel, course=None):
207        """Return message if credits are out of range. In the base
208        package only maximum credits is set.
209        """
210        if course and studylevel.total_credits + course.credits > 80:
211            return _('Maximum credits exceeded.')
212        elif studylevel.total_credits > 80:
213            return _('Maximum credits exceeded.')
214        return
215
216    #: A tuple containing names of file upload viewlets which are not shown
217    #: on the `StudentClearanceManageFormPage`. Nothing is being skipped
218    #: in the base package. This attribute makes only sense, if intermediate
219    #: custom packages are being used, like we do for all Nigerian portals.
220    SKIP_UPLOAD_VIEWLETS = ('acceptanceletterupload',
221                            'higherqualificationresultupload',
222                            'advancedlevelresultupload',
223                            'evidencenameupload',
224                            'refereeletterupload',
225                            'statutorydeclarationupload',
226                            'firstsittingresultupload',
227                            'secondsittingresultupload',
228                            'certificateupload',
229                            'resultstatementupload',
230                            )
231
232    #: A tuple containing the names of registration states in which changing of
233    #: passport pictures is allowed.
234    PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING,)
Note: See TracBrowser for help on using the repository browser.