source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/utils.py @ 9386

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

Set payment ticket attributes properly.

Mrrr, even the test was expecting the wrong p_session and p_level.

  • Property svn:keywords set to Id
File size: 10.4 KB
RevLine 
[7419]1## $Id: utils.py 9297 2012-10-05 11:24:30Z 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
[9190]19import random
[8599]20from time import time
21from zope.component import createObject
[8475]22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
[8834]23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]24from waeup.kofa.accesscodes import create_accesscode
[9143]25from waeup.kofa.interfaces import CLEARED, RETURNING
[8460]26from waeup.fceokene.interfaces import MessageFactory as _
[6902]27
[8834]28class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]29    """A collection of customized methods.
30
31    """
32
[9190]33    def selectBed(self, available_beds):
34        """Randomly select a bed from a list of available beds.
35
36        """
37        return random.choice(available_beds)
38
[8270]39    def getReturningData(self, student):
40        """ This method defines what happens after school fee payment
[8319]41        of returning students depending on the student's senate verdict.
[8270]42        """
[8319]43        prev_level = student['studycourse'].current_level
44        cur_verdict = student['studycourse'].current_verdict
45        if cur_verdict in ('A','B','L','M','N','Z',):
46            # Successful student
47            new_level = divmod(int(prev_level),100)[0]*100 + 100
48        elif cur_verdict == 'C':
49            # Student on probation
50            new_level = int(prev_level) + 10
51        else:
52            # Student is somehow in an undefined state.
53            # Level has to be set manually.
54            new_level = prev_level
[8270]55        new_session = student['studycourse'].current_session + 1
56        return new_session, new_level
57
[9153]58    def setPaymentDetails(self, category, student,
59            previous_session=None, previous_level=None):
[8599]60        """Create Payment object and set the payment data of a student for
61        the payment category specified.
62
63        """
[8306]64        details = {}
[8599]65        p_item = u''
66        amount = 0.0
67        error = u''
[9153]68        if previous_session:
69            return _('Previous session payment not yet implemented.'), None
[8599]70        p_session = student['studycourse'].current_session
71        p_level = student['studycourse'].current_level
[9153]72        p_current = True
[8599]73        session = str(p_session)
[7151]74        try:
75            academic_session = grok.getSite()['configuration'][session]
76        except KeyError:
[8599]77            return _(u'Session configuration object is not available.'), None
[7151]78        if category == 'transfer':
[8599]79            amount = academic_session.transfer_fee
[7151]80        elif category == 'gown':
[8599]81            amount = academic_session.gown_fee
[7151]82        elif category == 'bed_allocation':
[8599]83            amount = academic_session.booking_fee
[7151]84        elif category == 'hostel_maintenance':
[8599]85            amount = academic_session.maint_fee
[7151]86        elif category == 'clearance':
[9143]87            amount = academic_session.clearance_fee
[8599]88            try:
89                p_item = student['studycourse'].certificate.code
90            except (AttributeError, TypeError):
91                return _('Study course data are incomplete.'), None
[7151]92        elif category == 'schoolfee':
[8599]93            try:
94                certificate = student['studycourse'].certificate
95                p_item = certificate.code
96            except (AttributeError, TypeError):
97                return _('Study course data are incomplete.'), None
[9143]98
99            # Very special school fee configuration, should be moved to
100            # a seperate file.
101
102            ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
103                    'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
104                    'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
105                    'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
106                    'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
107
108            #PDE Students
109            if student.current_mode == 'pd_ft':
110                amount = 35000
111            elif not student.current_mode.endswith('_sw'):
112                # PRENCE
113                if student.current_level == 10 and student.state == CLEARED:
114                    if student.depcode in ARTS:
115                        amount = 14900
116                    else:
117                        amount = 15400
118                # NCE I fresh
119                elif student.current_level == 100 and student.state == CLEARED:
120                    if student.depcode in ARTS:
121                        amount = 12020
122                    else:
123                        amount = 12495
124                # NCE II
125                elif student.current_level in (100, 110, 120) and \
126                    student.state == RETURNING:
127                    if student.depcode in ARTS:
128                        amount = 11070
129                    else:
130                        amount = 11545
131                # NCE III
132                elif student.current_level in (200, 210, 220):
133                    if student.depcode in ARTS:
134                        amount = 11070
135                    else:
136                        amount = 11545
137                # NCE III repeater
138                elif student.current_level in (300, 310, 320) and \
139                    student.current_verdict == 'O':
140                    if student.depcode in ARTS:
141                        amount = 6535
142                    else:
143                        amount = 6773
144                # NCE III spillover
145                elif student.current_level in (300, 310, 320) and \
146                    student.current_verdict == 'B':
147                    if student.depcode in ARTS:
148                        amount = 9170
149                    else:
150                        amount = 9645
151                # NCE III second spillover
152                elif student.current_level in (400, 410, 420) and \
153                    student.current_verdict == 'B':
154                    if student.depcode in ARTS:
155                        amount = 9170
156                    else:
157                        amount = 9645
158            else:
159                if student.current_level == 100 and student.state == CLEARED:
160                    if student.depcode in ARTS:
161                        amount = 21900
162                    else:
163                        amount = 22400
164                # NCE II
165                elif student.current_level in (100, 110, 120) and \
166                    student.state == RETURNING:
167                    if student.depcode in ARTS:
168                        amount = 18400
169                    else:
170                        amount = 18900
171                # NCE III
172                elif student.current_level in (200, 210, 220):
173                    if student.depcode in ARTS:
174                        amount = 20400
175                    else:
176                        amount = 20900
177                # NCE IV
178                elif student.current_level in (300, 310, 320):
179                    if student.depcode in ARTS:
180                        amount = 18400
181                    else:
182                        amount = 18900
183                # NCE V
184                elif student.current_level in (400, 410, 420):
185                    if student.depcode in ARTS:
186                        amount = 18400
187                    else:
188                        amount = 18900
189                # NCE V spillover
190                elif student.current_level in (500, 510, 520) and \
191                    student.current_verdict == 'B':
192                    if student.depcode in ARTS:
193                        amount = 16900
194                    else:
195                        amount = 17400
196                # NCE V second spillover
197                elif student.current_level in (600, 610, 620) and \
198                    student.current_verdict == 'B':
199                    if student.depcode in ARTS:
200                        amount = 16900
201                    else:
202                        amount = 17400
[9297]203            if student.state == RETURNING:
204                p_session, p_level = self.getReturningData(student)
[9143]205
[8599]206        if amount in (0.0, None):
207            return _(u'Amount could not be determined.'), None
208        for key in student['payments'].keys():
209            ticket = student['payments'][key]
210            if ticket.p_state == 'paid' and\
211               ticket.p_category == category and \
212               ticket.p_item == p_item and \
213               ticket.p_session == p_session:
214                  return _('This type of payment has already been made.'), None
[8713]215        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]216        timestamp = ("%d" % int(time()*10000))[1:]
[8599]217        payment.p_id = "p%s" % timestamp
218        payment.p_category = category
219        payment.p_item = p_item
220        payment.p_session = p_session
221        payment.p_level = p_level
[9153]222        payment.p_current = p_current
[9143]223        payment.amount_auth = float(amount)
[8599]224        return None, payment
[7621]225
[9207]226    def getAccommodationDetails(self, student):
227        """Determine the accommodation data of a student.
228        """
229        d = {}
230        d['error'] = u''
231        hostels = grok.getSite()['hostels']
232        d['booking_session'] = hostels.accommodation_session
233        d['allowed_states'] = hostels.accommodation_states
234        d['startdate'] = hostels.startdate
235        d['enddate'] = hostels.enddate
236        d['expired'] = hostels.expired
237        # Determine bed type
238        studycourse = student['studycourse']
239        certificate = getattr(studycourse,'certificate',None)
240        current_level = studycourse.current_level
241        if None in (current_level, certificate):
242            return d
243        end_level = certificate.end_level
244        if current_level == 10:
245            bt = 'pr'
246        elif current_level == 100:
247            bt = 'fr'
248        elif current_level >= 300:
249            bt = 'fi'
250        else:
251            bt = 're'
252        if student.sex == 'f':
253            sex = 'female'
254        else:
255            sex = 'male'
256        special_handling = 'regular'
257        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
258        return d
259
[8460]260    # FCEOkene prefix
[8528]261    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.