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

Last change on this file since 10009 was 9971, checked in by Henrik Bettermann, 12 years ago

pyflakes

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