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

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

Add new application category and type (ticket #966).

Implement hostel application fee payment (ticket #959). Uniben is still waiting for an agrrement with Interwsicth.

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