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

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

Configure dep_sug payments which are required for schoolfee payments.

  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1## $Id: utils.py 14938 2018-01-16 15:06:52Z 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 not self._dep_sug_paymentMade(student,
101                    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 == 'transcript':
166            amount = academic_session.transcript_fee
167        elif category == 'transfer':
168            amount = academic_session.transfer_fee
169        elif category == 'late_registration':
170            amount = academic_session.late_registration_fee
171        elif category == 'carryover1':
172            amount = 10000.0
173        elif category == 'carryover2':
174            amount = 10000.0
175        elif category == 'carryover3':
176            amount = 10000.0
177        elif category == 'carryover4':
178            amount = 13000.0
179        elif category == 'dep_sug':
180            amount = 3150.0 # includes GATEWAY_AMT
181            if student.faccode == 'SPAT':
182                amount = 1650.0 # includes GATEWAY_AMT
183        else:
184            fee_name = category + '_fee'
185            amount = getattr(academic_session, fee_name, 0.0)
186        if amount in (0.0, None):
187            return _('Amount could not be determined.'), None
188        if self.samePaymentMade(student, category, p_item, p_session):
189            return _('This type of payment has already been made.'), None
190        if self._isPaymentDisabled(p_session, category, student):
191            return _('This category of payments has been disabled.'), None
192        payment = createObject(u'waeup.StudentOnlinePayment')
193        timestamp = ("%d" % int(time()*10000))[1:]
194        payment.p_id = "p%s" % timestamp
195        payment.p_category = category
196        payment.p_item = p_item
197        payment.p_session = p_session
198        payment.p_level = p_level
199        payment.p_current = p_current
200        payment.amount_auth = amount
201        return None, payment
202
203    #: A tuple containing names of file upload viewlets which are not shown
204    #: on the `StudentClearanceManageFormPage`. Nothing is being skipped
205    #: in the base package. This attribute makes only sense, if intermediate
206    #: custom packages are being used, like we do for all Nigerian portals.
207    SKIP_UPLOAD_VIEWLETS = ('acceptanceletterupload',
208                            'higherqualificationresultupload',
209                            'advancedlevelresultupload',
210                            'evidencenameupload',
211                            'refereeletterupload',
212                            'statutorydeclarationupload',
213                            'firstsittingresultupload',
214                            'secondsittingresultupload',
215                            'certificateupload',
216                            'resultstatementupload',
217                            )
218
219    #: A tuple containing the names of registration states in which changing of
220    #: passport pictures is allowed.
221    PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING,)
Note: See TracBrowser for help on using the repository browser.