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

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

Prepare for previous session payments.

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