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

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

Remove import of non-existing function.

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