1 | ## $Id: utils.py 9152 2012-09-04 07:06:20Z 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 ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
88 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
89 | amount = 17250.0 |
---|
90 | else: |
---|
91 | amount = 34250.0 |
---|
92 | elif category == 'schoolfee': |
---|
93 | try: |
---|
94 | certificate = student['studycourse'].certificate |
---|
95 | p_item = certificate.code |
---|
96 | except (AttributeError, TypeError): |
---|
97 | return _('Study course data are incomplete.'), None |
---|
98 | if previous_session: |
---|
99 | if student.current_session == student['studycourse'].entry_session: |
---|
100 | if student.is_foreigner: |
---|
101 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
102 | else: |
---|
103 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
104 | else: |
---|
105 | if student.is_foreigner: |
---|
106 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
107 | else: |
---|
108 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
109 | else: |
---|
110 | if student.state == CLEARED: |
---|
111 | if student.is_foreigner: |
---|
112 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
113 | else: |
---|
114 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
115 | elif student.state == RETURNING: |
---|
116 | # In case of returning school fee payment the payment session |
---|
117 | # and level contain the values of the session the student |
---|
118 | # has paid for. |
---|
119 | p_session, p_level = self.getReturningData(student) |
---|
120 | if student.is_foreigner: |
---|
121 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
122 | else: |
---|
123 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
124 | try: |
---|
125 | academic_session = grok.getSite()[ |
---|
126 | 'configuration'][str(p_session)] |
---|
127 | except KeyError: |
---|
128 | return _(u'Session configuration object is not available.'), None |
---|
129 | elif student.is_postgrad and student.state == PAID: |
---|
130 | # Returning postgraduate students also pay for the next session |
---|
131 | # but their level always remains the same. |
---|
132 | p_session += 1 |
---|
133 | if student.is_foreigner: |
---|
134 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
135 | else: |
---|
136 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
137 | try: |
---|
138 | academic_session = grok.getSite()[ |
---|
139 | 'configuration'][str(p_session)] |
---|
140 | except KeyError: |
---|
141 | return _(u'Session configuration object is not available.'), None |
---|
142 | # Give 50% school fee discount to staff members. |
---|
143 | if student.is_staff: |
---|
144 | amount /= 2 |
---|
145 | if amount in (0.0, None): |
---|
146 | return _('Amount could not be determined.' + |
---|
147 | ' Would you like to pay for a previous session?'), None |
---|
148 | # Add session specific penalty fee. |
---|
149 | if category == 'schoolfee' and student.is_postgrad: |
---|
150 | amount += academic_session.penalty_pg |
---|
151 | elif category == 'schoolfee': |
---|
152 | amount += academic_session.penalty_ug |
---|
153 | # Create ticket. |
---|
154 | for key in student['payments'].keys(): |
---|
155 | ticket = student['payments'][key] |
---|
156 | if ticket.p_state == 'paid' and\ |
---|
157 | ticket.p_category == category and \ |
---|
158 | ticket.p_item == p_item and \ |
---|
159 | ticket.p_session == p_session: |
---|
160 | return _('This type of payment has already been made.' + |
---|
161 | ' Would you like to pay for a previous session?'), None |
---|
162 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
163 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
164 | payment.p_id = "p%s" % timestamp |
---|
165 | payment.p_category = category |
---|
166 | payment.p_item = p_item |
---|
167 | payment.p_session = p_session |
---|
168 | payment.p_level = p_level |
---|
169 | payment.p_current = p_current |
---|
170 | payment.amount_auth = amount |
---|
171 | return None, payment |
---|
172 | |
---|
173 | # Uniben prefix |
---|
174 | STUDENT_ID_PREFIX = u'B' |
---|