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

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

The rebate is not relative, it has to be deducted.

  • Property svn:keywords set to Id
File size: 9.2 KB
Line 
1## $Id: utils.py 14884 2017-10-26 09:11:38Z 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.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 setPaymentDetails(self, category, student,
40            previous_session, previous_level):
41        """Create a payment ticket and set the payment data of a
42        student for the payment category specified.
43        """
44        p_item = u''
45        amount = 0.0
46        if previous_session:
47            if previous_session < student['studycourse'].entry_session:
48                return _('The previous session must not fall below '
49                         'your entry session.'), None
50            if category == 'schoolfee':
51                # School fee is always paid for the following session
52                if previous_session > student['studycourse'].current_session:
53                    return _('This is not a previous session.'), None
54            else:
55                if previous_session > student['studycourse'].current_session - 1:
56                    return _('This is not a previous session.'), None
57            p_session = previous_session
58            p_level = previous_level
59            p_current = False
60        else:
61            p_session = student['studycourse'].current_session
62            p_level = student['studycourse'].current_level
63            p_current = True
64        academic_session = self._getSessionConfiguration(p_session)
65        if academic_session == None:
66            return _(u'Session configuration object is not available.'), None
67        # Determine fee.
68        if category == 'schoolfee':
69            try:
70                certificate = student['studycourse'].certificate
71                p_item = certificate.code
72            except (AttributeError, TypeError):
73                return _('Study course data are incomplete.'), None
74            if previous_session:
75                # Students can pay for previous sessions in all
76                # workflow states.  Fresh students are excluded by the
77                # update method of the PreviousPaymentAddFormPage.
78                if previous_level == 100:
79                    if local(student):
80                        amount = getattr(certificate, 'school_fee_1', 0.0)
81                    else:
82                        amount = getattr(certificate, 'school_fee_3', 0.0)
83                else:
84                    if local(student):
85                        amount = getattr(certificate, 'school_fee_2', 0.0)
86                    else:
87                        amount = getattr(certificate, 'school_fee_4', 0.0)
88            else:
89                if student.state == CLEARED:
90                    if local(student):
91                        amount = getattr(certificate, 'school_fee_1', 0.0)
92                    else:
93                        amount = getattr(certificate, 'school_fee_3', 0.0)
94                elif student.state == RETURNING:
95                    # In case of returning school fee payment the
96                    # payment session and level contain the values of
97                    # the session the student has paid for. Payment
98                    # session is always next session.
99                    p_session, p_level = self.getReturningData(student)
100                    academic_session = self._getSessionConfiguration(p_session)
101                    if academic_session == None:
102                        return _(
103                            u'Session configuration object is not available.'
104                            ), None
105                    if local(student):
106                        amount = getattr(certificate, 'school_fee_2', 0.0)
107                    else:
108                        amount = getattr(certificate, 'school_fee_4', 0.0)
109                elif student.is_postgrad and student.state == PAID:
110                    # Returning postgraduate students also pay for the
111                    # next session but their level always remains the
112                    # same.
113                    p_session += 1
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 category == 'clearance':
124            try:
125                p_item = student['studycourse'].certificate.code
126            except (AttributeError, TypeError):
127                return _('Study course data are incomplete.'), None
128            amount = academic_session.clearance_fee
129            # Local ND and HND students are given a rebate which has
130            # to be adjusted if the basic acceptance fee changes.
131            if student.current_mode == 'nd_ft' and local(student):
132                amount -= 10000.0
133            if student.current_mode == 'hnd_ft' and local(student):
134                amount -= 5000.0
135        elif category == 'bed_allocation':
136            p_item = self.getAccommodationDetails(student)['bt']
137            amount = academic_session.booking_fee
138        elif category == 'hostel_maintenance':
139            amount = 0.0
140            bedticket = student['accommodation'].get(
141                str(student.current_session), None)
142            if bedticket is not None and bedticket.bed is not None:
143                p_item = bedticket.bed_coordinates
144                if bedticket.bed.__parent__.maint_fee > 0:
145                    amount = bedticket.bed.__parent__.maint_fee
146                else:
147                    # fallback
148                    amount = academic_session.maint_fee
149            else:
150                return _(u'No bed allocated.'), None
151        elif category == 'transcript':
152            amount = academic_session.transcript_fee
153        elif category == 'transfer':
154            amount = academic_session.transfer_fee
155        elif category == 'late_registration':
156            amount = academic_session.late_registration_fee
157        elif category == 'carryover1':
158            amount = 10000.0
159        elif category == 'carryover2':
160            amount = 10000.0
161        elif category == 'carryover3':
162            amount = 10000.0
163        elif category == 'carryover4':
164            amount = 13000.0
165        else:
166            fee_name = category + '_fee'
167            amount = getattr(academic_session, fee_name, 0.0)
168        if amount in (0.0, None):
169            return _('Amount could not be determined.'), None
170        if self.samePaymentMade(student, category, p_item, p_session):
171            return _('This type of payment has already been made.'), None
172        if self._isPaymentDisabled(p_session, category, student):
173            return _('This category of payments has been disabled.'), None
174        payment = createObject(u'waeup.StudentOnlinePayment')
175        timestamp = ("%d" % int(time()*10000))[1:]
176        payment.p_id = "p%s" % timestamp
177        payment.p_category = category
178        payment.p_item = p_item
179        payment.p_session = p_session
180        payment.p_level = p_level
181        payment.p_current = p_current
182        payment.amount_auth = amount
183        return None, payment
184
185    #: A tuple containing names of file upload viewlets which are not shown
186    #: on the `StudentClearanceManageFormPage`. Nothing is being skipped
187    #: in the base package. This attribute makes only sense, if intermediate
188    #: custom packages are being used, like we do for all Nigerian portals.
189    SKIP_UPLOAD_VIEWLETS = ('acceptanceletterupload',
190                            'higherqualificationresultupload',
191                            'advancedlevelresultupload',
192                            'evidencenameupload',
193                            'refereeletterupload',
194                            'statutorydeclarationupload',
195                            'firstsittingresultupload',
196                            'secondsittingresultupload',
197                            'certificateupload',
198                            'resultstatementupload',
199                            )
Note: See TracBrowser for help on using the repository browser.