source: main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py @ 12704

Last change on this file since 12704 was 12566, checked in by Henrik Bettermann, 10 years ago

Add new application category and type (ticket #966).

Implement hostel application fee payment (ticket #959). Uniben is still waiting for an agrrement with Interwsicth.

  • Property svn:keywords set to Id
File size: 11.8 KB
Line 
1## $Id: utils.py 12566 2015-02-07 10:25:56Z 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##
18import grok
19from time import time
20from zope.component import createObject, getUtility
21from waeup.kofa.interfaces import (IKofaUtils,
22    CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from waeup.uniben.interfaces import MessageFactory as _
25
26class CustomStudentsUtils(NigeriaStudentsUtils):
27    """A collection of customized methods.
28
29    """
30
31    def getReturningData(self, student):
32        """ This method defines what happens after school fee payment
33        of returning students depending on the student's senate verdict.
34        """
35        prev_level = student['studycourse'].current_level
36        cur_verdict = student['studycourse'].current_verdict
37        if cur_verdict in ('A','B','L','M','N','Z',):
38            # Successful student
39            new_level = divmod(int(prev_level),100)[0]*100 + 100
40        elif cur_verdict == 'C':
41            # Student on probation
42            new_level = int(prev_level) + 10
43        else:
44            # Student is somehow in an undefined state.
45            # Level has to be set manually.
46            new_level = prev_level
47        new_session = student['studycourse'].current_session + 1
48        return new_session, new_level
49
50    def _paymentMade(self, student, session):
51        if len(student['payments']):
52            for ticket in student['payments'].values():
53                if ticket.p_state == 'paid' and \
54                    ticket.p_category == 'schoolfee' and \
55                    ticket.p_session == session:
56                    return True
57        return False
58
59    def _hostelApplicationPaymentMade(self, student, session):
60        if len(student['payments']):
61            for ticket in student['payments'].values():
62                if ticket.p_state == 'paid' and \
63                    ticket.p_category == 'hostel_application' and \
64                    ticket.p_session == session:
65                    return True
66        return False
67
68    def setPaymentDetails(self, category, student,
69            previous_session, previous_level):
70        """Create Payment object and set the payment data of a student for
71        the payment category specified.
72
73        """
74        p_item = u''
75        amount = 0.0
76        if previous_session:
77            if previous_session < student['studycourse'].entry_session:
78                return _('The previous session must not fall below '
79                         'your entry session.'), None
80            if category == 'schoolfee':
81                # School fee is always paid for the following session
82                if previous_session > student['studycourse'].current_session:
83                    return _('This is not a previous session.'), None
84            else:
85                if previous_session > student['studycourse'].current_session - 1:
86                    return _('This is not a previous session.'), None
87            p_session = previous_session
88            p_level = previous_level
89            p_current = False
90        else:
91            p_session = student['studycourse'].current_session
92            p_level = student['studycourse'].current_level
93            p_current = True
94        academic_session = self._getSessionConfiguration(p_session)
95        if academic_session == None:
96            return _(u'Session configuration object is not available.'), None
97        # Determine fee.
98        if category == 'transfer':
99            amount = academic_session.transfer_fee
100        elif category == 'transcript':
101            amount = academic_session.transcript_fee
102        elif category == 'gown':
103            amount = academic_session.gown_fee
104        #elif category == 'bed_allocation':
105        #    amount = academic_session.booking_fee
106        #elif category == 'hostel_maintenance':
107        #    amount = academic_session.maint_fee
108        elif category == 'hostel_application':
109            amount = 1000.0
110        elif category.startswith('tempmaint'):
111            if not self._hostelApplicationPaymentMade(
112                student, student.current_session):
113                return _(
114                    'You have not yet paid the hostel application fee.'), None
115            if category == 'tempmaint_1':
116                amount = 8150.0
117            elif category == 'tempmaint_2':
118                amount = 12650.0
119            elif category == 'tempmaint_3':
120                amount = 9650.0
121        elif category == 'clearance':
122            p_item = student.certcode
123            if p_item is None:
124                return _('Study course data are incomplete.'), None
125            if student.faccode == 'FCETA':
126                amount = 22500.0
127            elif p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS',
128                'MBBSMED', 'MBBSNDU'):
129                amount = 65000.0
130            elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
131                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
132                amount = 22500.0
133            else:
134                amount = 45000.0
135        elif category == 'schoolfee':
136            try:
137                certificate = student['studycourse'].certificate
138                p_item = certificate.code
139            except (AttributeError, TypeError):
140                return _('Study course data are incomplete.'), None
141            if previous_session:
142                # Students can pay for previous sessions in all workflow states.
143                # Fresh students are excluded by the update method of the
144                # PreviousPaymentAddFormPage.
145                if previous_session == student['studycourse'].entry_session:
146                    if student.is_foreigner:
147                        amount = getattr(certificate, 'school_fee_3', 0.0)
148                    else:
149                        amount = getattr(certificate, 'school_fee_1', 0.0)
150                else:
151                    if student.is_foreigner:
152                        amount = getattr(certificate, 'school_fee_4', 0.0)
153                    else:
154                        amount = getattr(certificate, 'school_fee_2', 0.0)
155            else:
156                if student.state == CLEARED:
157                    if student.is_foreigner:
158                        amount = getattr(certificate, 'school_fee_3', 0.0)
159                    else:
160                        amount = getattr(certificate, 'school_fee_1', 0.0)
161                elif student.state in (PAID, REGISTERED, VALIDATED):
162                    p_session += 1
163                    # We don't know which level the student is paying for.
164                    p_level = None
165                    academic_session = self._getSessionConfiguration(p_session)
166                    if academic_session == None:
167                        return _(u'Session configuration object is not available.'), None
168
169                    # Students are only allowed to pay for the next session
170                    # if current session payment
171                    # has really been made, i.e. payment object exists.
172                    #if not self._paymentMade(
173                    #    student, student.current_session):
174                    #    return _('You have not yet paid your current/active' +
175                    #             ' session. Please use the previous session' +
176                    #             ' payment form first.'), None
177
178                    if student.is_foreigner:
179                        amount = getattr(certificate, 'school_fee_4', 0.0)
180                    else:
181                        amount = getattr(certificate, 'school_fee_2', 0.0)
182                elif student.state == RETURNING:
183                    # In case of returning school fee payment the payment session
184                    # and level contain the values of the session the student
185                    # has paid for.
186                    p_session, p_level = self.getReturningData(student)
187                    academic_session = self._getSessionConfiguration(p_session)
188                    if academic_session == None:
189                        return _(u'Session configuration object is not available.'), None
190
191                    # Students are only allowed to pay for the next session
192                    # if current session payment has really been made,
193                    # i.e. payment object exists and is paid.
194                    #if not self._paymentMade(
195                    #    student, student.current_session):
196                    #    return _('You have not yet paid your current/active' +
197                    #             ' session. Please use the previous session' +
198                    #             ' payment form first.'), None
199
200                    if student.is_foreigner:
201                        amount = getattr(certificate, 'school_fee_4', 0.0)
202                    else:
203                        amount = getattr(certificate, 'school_fee_2', 0.0)
204            # Give 50% school fee discount to staff members.
205            if student.is_staff:
206                amount /= 2
207        if amount in (0.0, None):
208            return _('Amount could not be determined.'), None
209        # Add session specific penalty fee.
210        if category == 'schoolfee' and student.is_postgrad:
211            amount += academic_session.penalty_pg
212        elif category == 'schoolfee':
213            amount += academic_session.penalty_ug
214        if category.startswith('tempmaint'):
215            p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category]
216            p_item = unicode(p_item)
217            # Now we change the category because tempmaint payments
218            # will be obsolete when Uniben returns to Kofa bed allocation.
219            category = 'hostel_maintenance'
220        # Create ticket.
221        if self.samePaymentMade(student, category, p_item, p_session):
222            return _('This type of payment has already been made.'), None
223        if self._isPaymentDisabled(p_session, category, student):
224            return _('Payment temporarily disabled.'), None
225        payment = createObject(u'waeup.StudentOnlinePayment')
226        timestamp = ("%d" % int(time()*10000))[1:]
227        payment.p_id = "p%s" % timestamp
228        payment.p_category = category
229        payment.p_item = p_item
230        payment.p_session = p_session
231        payment.p_level = p_level
232        payment.p_current = p_current
233        payment.amount_auth = amount
234        return None, payment
235
236    def maxCredits(self, studylevel):
237        """Return maximum credits.
238
239        """
240        studycourse = studylevel.__parent__
241        certificate = getattr(studycourse,'certificate', None)
242        current_level = studycourse.current_level
243        if None in (current_level, certificate):
244            return 0
245        end_level = certificate.end_level
246        if current_level >= end_level:
247            return 51
248        return 50
249
250    def clearance_disabled_message(self, student):
251        if student.is_postgrad:
252            return None
253        try:
254            session_config = grok.getSite()[
255                'configuration'][str(student.current_session)]
256        except KeyError:
257            return _('Session configuration object is not available.')
258        if not session_config.clearance_enabled:
259            return _('Clearance is disabled for this session.')
260        return None
261
262    # Uniben prefix
263    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.