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

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

Customize clearance_disabled_message.

  • Property svn:keywords set to Id
File size: 11.1 KB
Line 
1## $Id: utils.py 11773 2014-07-31 05:14:19Z 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 setPaymentDetails(self, category, student,
60            previous_session, previous_level):
61        """Create Payment object and set the payment data of a student for
62        the payment category specified.
63
64        """
65        p_item = u''
66        amount = 0.0
67        if previous_session:
68            if previous_session < student['studycourse'].entry_session:
69                return _('The previous session must not fall below '
70                         'your entry session.'), None
71            if category == 'schoolfee':
72                # School fee is always paid for the following session
73                if previous_session > student['studycourse'].current_session:
74                    return _('This is not a previous session.'), None
75            else:
76                if previous_session > student['studycourse'].current_session - 1:
77                    return _('This is not a previous session.'), None
78            p_session = previous_session
79            p_level = previous_level
80            p_current = False
81        else:
82            p_session = student['studycourse'].current_session
83            p_level = student['studycourse'].current_level
84            p_current = True
85        academic_session = self._getSessionConfiguration(p_session)
86        if academic_session == None:
87            return _(u'Session configuration object is not available.'), None
88        # Determine fee.
89        if category == 'transfer':
90            amount = academic_session.transfer_fee
91        elif category == 'transcript':
92            amount = academic_session.transcript_fee
93        elif category == 'gown':
94            amount = academic_session.gown_fee
95        elif category == 'bed_allocation':
96            amount = academic_session.booking_fee
97        elif category == 'hostel_maintenance':
98            amount = academic_session.maint_fee
99        elif category == 'tempmaint_1':
100            amount = 8150.0
101        elif category == 'tempmaint_2':
102            amount = 12650.0
103        elif category == 'tempmaint_3':
104            amount = 9650.0
105        elif category == 'clearance':
106            p_item = student.certcode
107            if p_item is None:
108                return _('Study course data are incomplete.'), None
109            if student.faccode == 'FCETA':
110                amount = 22500.0
111            elif p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS',
112                'MBBSMED', 'MBBSNDU'):
113                amount = 65000.0
114            elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
115                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
116                amount = 22500.0
117            else:
118                amount = 45000.0
119        elif category == 'schoolfee':
120            try:
121                certificate = student['studycourse'].certificate
122                p_item = certificate.code
123            except (AttributeError, TypeError):
124                return _('Study course data are incomplete.'), None
125            if previous_session:
126                # Students can pay for previous sessions in all workflow states.
127                # Fresh students are excluded by the update method of the
128                # PreviousPaymentAddFormPage.
129                if previous_session == student['studycourse'].entry_session:
130                    if student.is_foreigner:
131                        amount = getattr(certificate, 'school_fee_3', 0.0)
132                    else:
133                        amount = getattr(certificate, 'school_fee_1', 0.0)
134                else:
135                    if student.is_foreigner:
136                        amount = getattr(certificate, 'school_fee_4', 0.0)
137                    else:
138                        amount = getattr(certificate, 'school_fee_2', 0.0)
139            else:
140                if student.state == CLEARED:
141                    if student.is_foreigner:
142                        amount = getattr(certificate, 'school_fee_3', 0.0)
143                    else:
144                        amount = getattr(certificate, 'school_fee_1', 0.0)
145                elif student.state in (PAID, REGISTERED, VALIDATED):
146                    p_session += 1
147                    # We don't know which level the student is paying for.
148                    p_level = None
149                    academic_session = self._getSessionConfiguration(p_session)
150                    if academic_session == None:
151                        return _(u'Session configuration object is not available.'), None
152
153                    # Students are only allowed to pay for the next session
154                    # if current session payment
155                    # has really been made, i.e. payment object exists.
156                    #if not self._paymentMade(
157                    #    student, student.current_session):
158                    #    return _('You have not yet paid your current/active' +
159                    #             ' session. Please use the previous session' +
160                    #             ' payment form first.'), None
161
162                    if student.is_foreigner:
163                        amount = getattr(certificate, 'school_fee_4', 0.0)
164                    else:
165                        amount = getattr(certificate, 'school_fee_2', 0.0)
166                elif student.state == RETURNING:
167                    # In case of returning school fee payment the payment session
168                    # and level contain the values of the session the student
169                    # has paid for.
170                    p_session, p_level = self.getReturningData(student)
171                    academic_session = self._getSessionConfiguration(p_session)
172                    if academic_session == None:
173                        return _(u'Session configuration object is not available.'), None
174
175                    # Students are only allowed to pay for the next session
176                    # if current session payment has really been made,
177                    # i.e. payment object exists and is paid.
178                    #if not self._paymentMade(
179                    #    student, student.current_session):
180                    #    return _('You have not yet paid your current/active' +
181                    #             ' session. Please use the previous session' +
182                    #             ' payment form first.'), None
183
184                    if student.is_foreigner:
185                        amount = getattr(certificate, 'school_fee_4', 0.0)
186                    else:
187                        amount = getattr(certificate, 'school_fee_2', 0.0)
188            # Give 50% school fee discount to staff members.
189            if student.is_staff:
190                amount /= 2
191        if amount in (0.0, None):
192            return _('Amount could not be determined.'), None
193        # Add session specific penalty fee.
194        if category == 'schoolfee' and student.is_postgrad:
195            amount += academic_session.penalty_pg
196        elif category == 'schoolfee':
197            amount += academic_session.penalty_ug
198        # XXX: Obsolete in 2013
199        if category.startswith('tempmaint'):
200            p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category]
201            p_item = unicode(p_item)
202            # Now we change the category because tempmaint payments
203            # will be obsolete in 2013
204            category = 'hostel_maintenance'
205        # Create ticket.
206        if self.samePaymentMade(student, category, p_item, p_session):
207            return _('This type of payment has already been made.'), None
208        if self._isPaymentDisabled(p_session, category, student):
209            return _('Payment temporarily disabled.'), None
210        payment = createObject(u'waeup.StudentOnlinePayment')
211        timestamp = ("%d" % int(time()*10000))[1:]
212        payment.p_id = "p%s" % timestamp
213        payment.p_category = category
214        payment.p_item = p_item
215        payment.p_session = p_session
216        payment.p_level = p_level
217        payment.p_current = p_current
218        payment.amount_auth = amount
219        return None, payment
220
221    def maxCredits(self, studylevel):
222        """Return maximum credits.
223
224        """
225        studycourse = studylevel.__parent__
226        certificate = getattr(studycourse,'certificate', None)
227        current_level = studycourse.current_level
228        if None in (current_level, certificate):
229            return 0
230        end_level = certificate.end_level
231        if current_level >= end_level:
232            return 51
233        return 50
234
235    def clearance_disabled_message(self, student):
236        if student.is_postgrad:
237            return None
238        try:
239            session_config = grok.getSite()[
240                'configuration'][str(student.current_session)]
241        except KeyError:
242            return _('Session configuration object is not available.')
243        if not session_config.clearance_enabled:
244            return _('Clearance is disabled for this session.')
245        return None
246
247    # Uniben prefix
248    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.