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

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

Customize SPECIAL_HANDLING_DICT and getAccommodationDetails.

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: utils.py 9402 2012-10-24 05:58:57Z 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
21from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
23from waeup.kofa.accesscodes import create_accesscode
24from waeup.futminna.interfaces import MessageFactory as _
25
26class CustomStudentsUtils(NigeriaStudentsUtils):
27    """A collection of customized methods.
28
29    """
30
31    def getReturningData(self, student):
32        """ This method defines what happens after school fee payment
33        of returning students depending on the student's senate verdict.
34        """
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
47        new_session = student['studycourse'].current_session + 1
48        return new_session, new_level
49
50    def setPaymentDetails(self, category, student,
51            previous_session=None, previous_level=None):
52        """Create Payment object and set the payment data of a student for
53        the payment category specified.
54
55        """
56        p_item = u''
57        amount = 0.0
58        if previous_session:
59            return _('Previous session payment not yet implemented.'), None
60        p_session = student['studycourse'].current_session
61        p_level = student['studycourse'].current_level
62        p_current = True
63        session = str(p_session)
64        try:
65            academic_session = grok.getSite()['configuration'][session]
66        except KeyError:
67            return _(u'Session configuration object is not available.'), None
68        if category == 'schoolfee':
69            try:
70                certificate = student['studycourse'].certificate
71                p_item = certificate.code
72            except (AttributeError, TypeError):
73                return _('Study course data are incomplete.'), None
74            if student.current_mode.endswith('_ft'):
75                # fresh remedial
76                if student.current_level == 10 and student.state == CLEARED:
77                    if student['studycourse'].entry_mode == 'rmd_ft':
78                        amount = 80200.0
79                    else:
80                        amount = 74200.0
81                # fresh
82                elif student.state == CLEARED:
83                    if student.current_mode == 'jm_ft':
84                        amount = 72700.0
85                    elif student.is_foreigner:
86                        amount = 131500.0
87                    else:
88                        amount = 37000.0 # School Fee reduced by 8000
89                # returning
90                elif student.state == RETURNING:
91                    if student.current_mode == 'jm_ft':
92                        amount = 37000.0
93                    elif student.is_foreigner:
94                        amount = 109500.0
95                    else:
96                        amount = 20000.0
97                else:
98                    amount = 0.0
99            if student.state == RETURNING:
100                p_session, p_level = self.getReturningData(student)
101        elif category == 'clearance':
102            try:
103                p_item = student['studycourse'].certificate.code
104            except (AttributeError, TypeError):
105                return _('Study course data are incomplete.'), None
106            if student.faccode in ['EET','ICT'] or student.depcode in ['ARC']:
107                amount = 25000.0
108            else:
109                amount = 20000.0
110        elif category == 'bed_allocation':
111            p_item = self.getAccommodationDetails(student)['bt']
112            amount = academic_session.booking_fee
113        if amount in (0.0, None):
114            return _('Amount could not be determined.'), None
115        for key in student['payments'].keys():
116            ticket = student['payments'][key]
117            if ticket.p_state == 'paid' and\
118               ticket.p_category == category and \
119               ticket.p_item == p_item and \
120               ticket.p_session == p_session:
121                  return _('This type of payment has already been made.'), None
122        payment = createObject(u'waeup.StudentOnlinePayment')
123        timestamp = ("%d" % int(time()*10000))[1:]
124        payment.p_id = "p%s" % timestamp
125        payment.p_category = category
126        payment.p_item = p_item
127        payment.p_session = p_session
128        payment.p_level = p_level
129        payment.p_current = p_current
130        payment.amount_auth = amount
131        return None, payment
132
133    def getAccommodationDetails(self, student):
134        """Determine the accommodation data of a student.
135        """
136        d = {}
137        d['error'] = u''
138        hostels = grok.getSite()['hostels']
139        d['booking_session'] = hostels.accommodation_session
140        d['allowed_states'] = hostels.accommodation_states
141        d['startdate'] = hostels.startdate
142        d['enddate'] = hostels.enddate
143        d['expired'] = hostels.expired
144        # Determine bed type
145        studycourse = student['studycourse']
146        certificate = getattr(studycourse,'certificate',None)
147        entry_session = studycourse.entry_session
148        current_level = studycourse.current_level
149        if None in (entry_session, current_level, certificate):
150            return d
151        end_level = certificate.end_level
152        if current_level == 10:
153            bt = 'pr'
154        elif entry_session == grok.getSite()['hostels'].accommodation_session:
155            bt = 'fr'
156        elif current_level >= end_level:
157            bt = 'fi'
158        else:
159            bt = 're'
160        sex = 'male'
161        if student.sex == 'f':
162            sex = 'female'
163        special_handling = 'regular'
164        if student.faccode == 'SSE':
165            special_handling = 'sse'
166        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
167        return d
168
169
170    # FUTMinna prefix
171    STUDENT_ID_PREFIX = u'M'
Note: See TracBrowser for help on using the repository browser.