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

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

pyflakes

  • Property svn:keywords set to Id
File size: 10.6 KB
RevLine 
[7419]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##
[8598]18from time import time
[9459]19from zope.component import createObject, getUtility
[9513]20from waeup.kofa.interfaces import (IKofaUtils,
21    CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
[8821]22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8020]23from waeup.uniben.interfaces import MessageFactory as _
[6902]24
[8821]25class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]26    """A collection of customized methods.
27
28    """
29
[8270]30    def getReturningData(self, student):
31        """ This method defines what happens after school fee payment
[8319]32        of returning students depending on the student's senate verdict.
[8270]33        """
[8319]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
[8270]46        new_session = student['studycourse'].current_session + 1
47        return new_session, new_level
48
[9520]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
[9152]58    def setPaymentDetails(self, category, student,
59            previous_session, previous_level):
[8598]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
[9152]66        if previous_session:
[9520]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
[9152]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
[9520]84        academic_session = self._getSessionConfiguration(p_session)
85        if academic_session == None:
[8598]86            return _(u'Session configuration object is not available.'), None
[8676]87        # Determine fee.
[7151]88        if category == 'transfer':
[8598]89            amount = academic_session.transfer_fee
[7151]90        elif category == 'gown':
[8598]91            amount = academic_session.gown_fee
[7151]92        elif category == 'bed_allocation':
[8598]93            amount = academic_session.booking_fee
[7151]94        elif category == 'hostel_maintenance':
[8598]95            amount = academic_session.maint_fee
[9727]96        elif category == 'tempmaint_1':
[9728]97            amount = 8150.0
[9727]98        elif category == 'tempmaint_2':
[9728]99            amount = 12650.0
[9727]100        elif category == 'tempmaint_3':
[9728]101            amount = 9650.0
[7151]102        elif category == 'clearance':
[9796]103            p_item = student.certcode
104            if p_item is None:
[8598]105                return _('Study course data are incomplete.'), None
[9796]106            if student.faccode == 'FCETA':
107                amount = 22500.0
108            elif p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS',
[9346]109                'MBBSMED', 'MBBSNDU'):
110                amount = 65000.0
111            elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
[8294]112                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
[9346]113                amount = 22500.0
[8294]114            else:
[9346]115                amount = 45000.0
[7151]116        elif category == 'schoolfee':
[8598]117            try:
118                certificate = student['studycourse'].certificate
119                p_item = certificate.code
120            except (AttributeError, TypeError):
121                return _('Study course data are incomplete.'), None
[9152]122            if previous_session:
[9520]123                # Students can pay for previous sessions in all workflow states.
124                # Fresh students are excluded by the update method of the
125                # PreviousPaymentAddFormPage.
[9157]126                if previous_session == student['studycourse'].entry_session:
[9152]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)
[9006]131                else:
[9152]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)
[9513]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
[9520]146                    academic_session = self._getSessionConfiguration(p_session)
147                    if academic_session == None:
[9513]148                        return _(u'Session configuration object is not available.'), None
[9570]149
[9520]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.
[9570]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
[9513]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)
[9152]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)
[9520]168                    academic_session = self._getSessionConfiguration(p_session)
169                    if academic_session == None:
[9152]170                        return _(u'Session configuration object is not available.'), None
[9570]171
[9520]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.
[9570]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
[9152]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)
[9006]185            # Give 50% school fee discount to staff members.
186            if student.is_staff:
187                amount /= 2
[8598]188        if amount in (0.0, None):
[9520]189            return _('Amount could not be determined.'), None
[8676]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
[9727]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'
[8676]202        # Create ticket.
[8598]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:
[9520]209                  return _('This type of payment has already been made.'), None
[8715]210        payment = createObject(u'waeup.StudentOnlinePayment')
[8950]211        timestamp = ("%d" % int(time()*10000))[1:]
[8598]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
[9152]217        payment.p_current = p_current
[8598]218        payment.amount_auth = amount
219        return None, payment
[7621]220
[9831]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
[8441]235    # Uniben prefix
[8413]236    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.