1 | ## $Id: utils.py 9346 2012-10-18 04:49:58Z 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 | ## |
---|
18 | import grok |
---|
19 | from time import time |
---|
20 | from zope.component import createObject |
---|
21 | from waeup.kofa.interfaces import CLEARED, RETURNING, PAID |
---|
22 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
23 | from waeup.kofa.accesscodes import create_accesscode |
---|
24 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
25 | |
---|
26 | class 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, previous_level): |
---|
52 | """Create Payment object and set the payment data of a student for |
---|
53 | the payment category specified. |
---|
54 | |
---|
55 | """ |
---|
56 | details = {} |
---|
57 | p_item = u'' |
---|
58 | amount = 0.0 |
---|
59 | error = u'' |
---|
60 | if previous_session: |
---|
61 | p_session = previous_session |
---|
62 | p_level = previous_level |
---|
63 | p_current = False |
---|
64 | else: |
---|
65 | p_session = student['studycourse'].current_session |
---|
66 | p_level = student['studycourse'].current_level |
---|
67 | p_current = True |
---|
68 | session = str(p_session) |
---|
69 | try: |
---|
70 | academic_session = grok.getSite()['configuration'][session] |
---|
71 | except KeyError: |
---|
72 | return _(u'Session configuration object is not available.'), None |
---|
73 | # Determine fee. |
---|
74 | if category == 'transfer': |
---|
75 | amount = academic_session.transfer_fee |
---|
76 | elif category == 'gown': |
---|
77 | amount = academic_session.gown_fee |
---|
78 | elif category == 'bed_allocation': |
---|
79 | amount = academic_session.booking_fee |
---|
80 | elif category == 'hostel_maintenance': |
---|
81 | amount = academic_session.maint_fee |
---|
82 | elif category == 'clearance': |
---|
83 | try: |
---|
84 | p_item = student['studycourse'].certificate.code |
---|
85 | except (AttributeError, TypeError): |
---|
86 | return _('Study course data are incomplete.'), None |
---|
87 | if p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS', |
---|
88 | 'MBBSMED', 'MBBSNDU'): |
---|
89 | amount = 65000.0 |
---|
90 | elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
91 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
92 | amount = 22500.0 |
---|
93 | else: |
---|
94 | amount = 45000.0 |
---|
95 | elif category == 'schoolfee': |
---|
96 | try: |
---|
97 | certificate = student['studycourse'].certificate |
---|
98 | p_item = certificate.code |
---|
99 | except (AttributeError, TypeError): |
---|
100 | return _('Study course data are incomplete.'), None |
---|
101 | if previous_session: |
---|
102 | if previous_session < student['studycourse'].entry_session: |
---|
103 | return _('The previous session must not fall below ' |
---|
104 | 'your entry session.'), None |
---|
105 | if previous_session > student['studycourse'].current_session - 1: |
---|
106 | return _('This is not a previous session.'), None |
---|
107 | if previous_session == student['studycourse'].entry_session: |
---|
108 | if student.is_foreigner: |
---|
109 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
110 | else: |
---|
111 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
112 | else: |
---|
113 | if student.is_foreigner: |
---|
114 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
115 | else: |
---|
116 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
117 | else: |
---|
118 | if student.state == CLEARED: |
---|
119 | if student.is_foreigner: |
---|
120 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
121 | else: |
---|
122 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
123 | elif student.state == RETURNING: |
---|
124 | # In case of returning school fee payment the payment session |
---|
125 | # and level contain the values of the session the student |
---|
126 | # has paid for. |
---|
127 | p_session, p_level = self.getReturningData(student) |
---|
128 | if student.is_foreigner: |
---|
129 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
130 | else: |
---|
131 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
132 | try: |
---|
133 | academic_session = grok.getSite()[ |
---|
134 | 'configuration'][str(p_session)] |
---|
135 | except KeyError: |
---|
136 | return _(u'Session configuration object is not available.'), None |
---|
137 | elif student.state == PAID and student.is_postgrad and \ |
---|
138 | not student.is_special_postgrad: |
---|
139 | # Regular returning postgraduate students also pay |
---|
140 | # for the next session but their level always remains the same. |
---|
141 | p_session += 1 |
---|
142 | if student.is_foreigner: |
---|
143 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
144 | else: |
---|
145 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
146 | try: |
---|
147 | academic_session = grok.getSite()[ |
---|
148 | 'configuration'][str(p_session)] |
---|
149 | except KeyError: |
---|
150 | return _(u'Session configuration object is not available.'), None |
---|
151 | # Give 50% school fee discount to staff members. |
---|
152 | if student.is_staff: |
---|
153 | amount /= 2 |
---|
154 | if amount in (0.0, None): |
---|
155 | return _('Amount could not be determined.' + |
---|
156 | ' Would you like to pay for a previous session?'), None |
---|
157 | # Add session specific penalty fee. |
---|
158 | if category == 'schoolfee' and student.is_postgrad: |
---|
159 | amount += academic_session.penalty_pg |
---|
160 | elif category == 'schoolfee': |
---|
161 | amount += academic_session.penalty_ug |
---|
162 | # Create ticket. |
---|
163 | for key in student['payments'].keys(): |
---|
164 | ticket = student['payments'][key] |
---|
165 | if ticket.p_state == 'paid' and\ |
---|
166 | ticket.p_category == category and \ |
---|
167 | ticket.p_item == p_item and \ |
---|
168 | ticket.p_session == p_session: |
---|
169 | return _('This type of payment has already been made.' + |
---|
170 | ' Would you like to pay for a previous session?'), None |
---|
171 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
172 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
173 | payment.p_id = "p%s" % timestamp |
---|
174 | payment.p_category = category |
---|
175 | payment.p_item = p_item |
---|
176 | payment.p_session = p_session |
---|
177 | payment.p_level = p_level |
---|
178 | payment.p_current = p_current |
---|
179 | payment.amount_auth = amount |
---|
180 | return None, payment |
---|
181 | |
---|
182 | # Uniben prefix |
---|
183 | STUDENT_ID_PREFIX = u'B' |
---|