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

Last change on this file since 11136 was 10901, checked in by Henrik Bettermann, 11 years ago

Temporarily disable all clearance payments except for postgraduate students. Completely untested!!

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