source: main/waeup.futminna/trunk/src/waeup/futminna/students/utils.py @ 14395

Last change on this file since 14395 was 11458, checked in by Henrik Bettermann, 11 years ago
  • Property svn:keywords set to Id
File size: 9.4 KB
RevLine 
[7419]1## $Id: utils.py 11458 2014-02-27 11:02:09Z 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##
[7151]18import grok
[9403]19import random
[8598]20from time import time
21from zope.component import createObject
[8473]22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
[8833]23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]24from waeup.kofa.accesscodes import create_accesscode
[8619]25from waeup.futminna.interfaces import MessageFactory as _
[6902]26
[8833]27class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]28    """A collection of customized methods.
29
30    """
31
[9403]32    def selectBed(self, available_beds):
33        """Randomly select a bed from a list of available beds.
34
35        """
36        return random.choice(available_beds)
37
[8270]38    def getReturningData(self, student):
39        """ This method defines what happens after school fee payment
[8319]40        of returning students depending on the student's senate verdict.
[8270]41        """
[8319]42        prev_level = student['studycourse'].current_level
43        cur_verdict = student['studycourse'].current_verdict
44        if cur_verdict in ('A','B','L','M','N','Z',):
45            # Successful student
46            new_level = divmod(int(prev_level),100)[0]*100 + 100
47        elif cur_verdict == 'C':
48            # Student on probation
49            new_level = int(prev_level) + 10
50        else:
51            # Student is somehow in an undefined state.
52            # Level has to be set manually.
53            new_level = prev_level
[8270]54        new_session = student['studycourse'].current_session + 1
55        return new_session, new_level
56
[9155]57    def setPaymentDetails(self, category, student,
58            previous_session=None, previous_level=None):
[8598]59        """Create Payment object and set the payment data of a student for
60        the payment category specified.
61
62        """
[9244]63        p_item = u''
64        amount = 0.0
65        if previous_session:
66            return _('Previous session payment not yet implemented.'), None
67        p_session = student['studycourse'].current_session
68        p_level = student['studycourse'].current_level
69        p_current = True
[9523]70        academic_session = self._getSessionConfiguration(p_session)
71        if academic_session == None:
[9244]72            return _(u'Session configuration object is not available.'), None
[9523]73        # Determine fee.
[9244]74        if category == 'schoolfee':
75            try:
76                certificate = student['studycourse'].certificate
77                p_item = certificate.code
78            except (AttributeError, TypeError):
79                return _('Study course data are incomplete.'), None
[9888]80            if student.is_postgrad:
81                if student.state == CLEARED:
82                    if student.is_foreigner:
83                        amount = getattr(certificate, 'school_fee_3', 0.0)
84                    else:
85                        amount = getattr(certificate, 'school_fee_1', 0.0)
86                elif student.state == RETURNING:
87                    if student.is_foreigner:
88                        amount = getattr(certificate, 'school_fee_4', 0.0)
89                    else:
90                        amount = getattr(certificate, 'school_fee_2', 0.0)
91            elif student.current_mode.endswith('_ft'):
[9244]92                # fresh remedial
93                if student.current_level == 10 and student.state == CLEARED:
94                    if student['studycourse'].entry_mode == 'rmd_ft':
95                        amount = 80200.0
96                    else:
97                        amount = 74200.0
98                # fresh
99                elif student.state == CLEARED:
100                    if student.current_mode == 'jm_ft':
101                        amount = 72700.0
102                    elif student.is_foreigner:
103                        amount = 131500.0
104                    else:
105                        amount = 37000.0 # School Fee reduced by 8000
106                # returning
107                elif student.state == RETURNING:
108                    if student.current_mode == 'jm_ft':
109                        amount = 37000.0
110                    elif student.is_foreigner:
111                        amount = 109500.0
112                    else:
113                        amount = 20000.0
114                else:
115                    amount = 0.0
[9298]116            if student.state == RETURNING:
[9523]117                # Override p_session and p_level
[9298]118                p_session, p_level = self.getReturningData(student)
[9523]119                academic_session = self._getSessionConfiguration(p_session)
120                if academic_session == None:
121                    return _(u'Session configuration object is not available.'), None
[9244]122        elif category == 'clearance':
123            try:
124                p_item = student['studycourse'].certificate.code
125            except (AttributeError, TypeError):
126                return _('Study course data are incomplete.'), None
[9714]127            amount = academic_session.clearance_fee
128            if amount and (student.faccode in [
129                'EET','ICT'] or student.depcode in ['ARC']):
130                amount += 5000.0
[9404]131        elif category == 'hostel_maintenance':
[9431]132            current_session = student['studycourse'].current_session
133            bedticket = student['accommodation'].get(str(current_session), None)
[9575]134            if bedticket is not None and bedticket.bed is not None:
[9431]135                p_item = bedticket.bed_coordinates
136            else:
137                return _(u'You have not yet booked accommodation.'), None
[9404]138            acc_details = self.getAccommodationDetails(student)
[9431]139            if current_session != acc_details['booking_session']:
[9404]140                return _(u'Current session does not match accommodation session.'), None
[9431]141            if bedticket.bed.bed_id.startswith('block-h'):
142                amount = 15000.0
143            elif student.current_level  in (100,200,300,400,500) and \
[9404]144                student.faccode in ('EET','SET','AAT','ICT','EMT'):
145                amount = 12000.0
146            else:
147                amount = 10000.0
[9244]148        elif category == 'bed_allocation':
149            p_item = self.getAccommodationDetails(student)['bt']
150            amount = academic_session.booking_fee
[9892]151        if category == 'schoolfee':
152            if (student.is_postgrad and
153                academic_session.penalty_pg == 9999.0) or \
154                (not student.is_postgrad and
155                academic_session.penalty_ug == 9999.0):
156                return _('School fee payment is disabled.'), None
[9244]157        if amount in (0.0, None):
158            return _('Amount could not be determined.'), None
159        for key in student['payments'].keys():
160            ticket = student['payments'][key]
161            if ticket.p_state == 'paid' and\
162               ticket.p_category == category and \
163               ticket.p_item == p_item and \
164               ticket.p_session == p_session:
165                  return _('This type of payment has already been made.'), None
[9732]166        # Add session specific penalty fee.
167        if category == 'schoolfee' and student.is_postgrad:
[9889]168            amount += academic_session.penalty_pg
[9732]169        elif category == 'schoolfee':
[9889]170            amount += academic_session.penalty_ug
[11458]171        if self._isPaymentDisabled(p_session, category, student):
172            return _('Payment temporarily disabled.'), None
[9244]173        payment = createObject(u'waeup.StudentOnlinePayment')
174        timestamp = ("%d" % int(time()*10000))[1:]
175        payment.p_id = "p%s" % timestamp
176        payment.p_category = category
177        payment.p_item = p_item
178        payment.p_session = p_session
179        payment.p_level = p_level
180        payment.p_current = p_current
181        payment.amount_auth = amount
182        return None, payment
[9155]183
[9402]184    def getAccommodationDetails(self, student):
185        """Determine the accommodation data of a student.
186        """
187        d = {}
188        d['error'] = u''
189        hostels = grok.getSite()['hostels']
190        d['booking_session'] = hostels.accommodation_session
191        d['allowed_states'] = hostels.accommodation_states
192        d['startdate'] = hostels.startdate
193        d['enddate'] = hostels.enddate
194        d['expired'] = hostels.expired
195        # Determine bed type
196        studycourse = student['studycourse']
197        certificate = getattr(studycourse,'certificate',None)
198        entry_session = studycourse.entry_session
199        current_level = studycourse.current_level
200        if None in (entry_session, current_level, certificate):
201            return d
202        end_level = certificate.end_level
203        if current_level == 10:
204            bt = 'pr'
205        elif entry_session == grok.getSite()['hostels'].accommodation_session:
206            bt = 'fr'
207        elif current_level >= end_level:
208            bt = 'fi'
209        else:
210            bt = 're'
211        sex = 'male'
212        if student.sex == 'f':
213            sex = 'female'
214        special_handling = 'regular'
215        if student.faccode == 'SSE':
216            special_handling = 'sse'
217        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
218        return d
[9244]219
[9402]220
[8619]221    # FUTMinna prefix
222    STUDENT_ID_PREFIX = u'M'
Note: See TracBrowser for help on using the repository browser.