1 | ## $Id: utils.py 8624 2012-06-04 10:28:28Z 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 waeup.kofa.students.utils import StudentsUtils |
---|
23 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
24 | from waeup.kofa.accesscodes import create_accesscode |
---|
25 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
26 | |
---|
27 | class CustomStudentsUtils(StudentsUtils): |
---|
28 | """A collection of customized methods. |
---|
29 | |
---|
30 | """ |
---|
31 | grok.implements(IStudentsUtils) |
---|
32 | |
---|
33 | paymentfactory = u'waeup.CustomStudentOnlinePayment' |
---|
34 | |
---|
35 | def getReturningData(self, student): |
---|
36 | """ This method defines what happens after school fee payment |
---|
37 | of returning students depending on the student's senate verdict. |
---|
38 | """ |
---|
39 | prev_level = student['studycourse'].current_level |
---|
40 | cur_verdict = student['studycourse'].current_verdict |
---|
41 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
42 | # Successful student |
---|
43 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
44 | elif cur_verdict == 'C': |
---|
45 | # Student on probation |
---|
46 | new_level = int(prev_level) + 10 |
---|
47 | else: |
---|
48 | # Student is somehow in an undefined state. |
---|
49 | # Level has to be set manually. |
---|
50 | new_level = prev_level |
---|
51 | new_session = student['studycourse'].current_session + 1 |
---|
52 | return new_session, new_level |
---|
53 | |
---|
54 | def setPaymentDetails(self, category, student): |
---|
55 | """Create Payment object and set the payment data of a student for |
---|
56 | the payment category specified. |
---|
57 | |
---|
58 | """ |
---|
59 | details = {} |
---|
60 | p_item = u'' |
---|
61 | amount = 0.0 |
---|
62 | error = u'' |
---|
63 | p_session = student['studycourse'].current_session |
---|
64 | p_level = student['studycourse'].current_level |
---|
65 | session = str(p_session) |
---|
66 | try: |
---|
67 | academic_session = grok.getSite()['configuration'][session] |
---|
68 | except KeyError: |
---|
69 | return _(u'Session configuration object is not available.'), None |
---|
70 | if category == 'transfer': |
---|
71 | amount = academic_session.transfer_fee |
---|
72 | elif category == 'gown': |
---|
73 | amount = academic_session.gown_fee |
---|
74 | elif category == 'bed_allocation': |
---|
75 | amount = academic_session.booking_fee |
---|
76 | elif category == 'hostel_maintenance': |
---|
77 | amount = academic_session.maint_fee |
---|
78 | elif category == 'clearance': |
---|
79 | try: |
---|
80 | p_item = student['studycourse'].certificate.code |
---|
81 | except (AttributeError, TypeError): |
---|
82 | return _('Study course data are incomplete.'), None |
---|
83 | if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
84 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
85 | amount = 17250.0 |
---|
86 | else: |
---|
87 | amount = 34250.0 |
---|
88 | elif category == 'schoolfee': |
---|
89 | try: |
---|
90 | certificate = student['studycourse'].certificate |
---|
91 | p_item = certificate.code |
---|
92 | except (AttributeError, TypeError): |
---|
93 | return _('Study course data are incomplete.'), None |
---|
94 | if student.state == CLEARED: |
---|
95 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
96 | elif student.state == RETURNING: |
---|
97 | # In case of returning school fee payment the payment session |
---|
98 | # and level contain the values of the session the student |
---|
99 | # has paid for. |
---|
100 | p_session, p_level = self.getReturningData(student) |
---|
101 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
102 | elif student.is_postgrad and student.state == PAID: |
---|
103 | # Returning postgraduate students also pay for the next session |
---|
104 | # but their level always remains the same. |
---|
105 | p_session += 1 |
---|
106 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
107 | if amount in (0.0, None): |
---|
108 | return _(u'Amount could not be determined.'), None |
---|
109 | for key in student['payments'].keys(): |
---|
110 | ticket = student['payments'][key] |
---|
111 | if ticket.p_state == 'paid' and\ |
---|
112 | ticket.p_category == category and \ |
---|
113 | ticket.p_item == p_item and \ |
---|
114 | ticket.p_session == p_session: |
---|
115 | return _('This type of payment has already been made.'), None |
---|
116 | payment = createObject(self.paymentfactory) |
---|
117 | timestamp = "%d" % int(time()*1000) |
---|
118 | payment.p_id = "p%s" % timestamp |
---|
119 | payment.p_category = category |
---|
120 | payment.p_item = p_item |
---|
121 | payment.p_session = p_session |
---|
122 | payment.p_level = p_level |
---|
123 | payment.amount_auth = amount |
---|
124 | return None, payment |
---|
125 | |
---|
126 | VERDICTS_DICT = { |
---|
127 | 'NY': 'not yet', |
---|
128 | 'A': 'Successful student', |
---|
129 | 'B': 'Student with carryover courses', |
---|
130 | 'C': 'Student on probation', |
---|
131 | 'D': 'Withdrawn from the faculty', |
---|
132 | 'E': 'Student who were previously on probation', |
---|
133 | 'F': 'Medical case', |
---|
134 | 'G': 'Absent from examination', |
---|
135 | 'H': 'Withheld results', |
---|
136 | 'I': 'Expelled/rusticated/suspended student', |
---|
137 | 'J': 'Temporary withdrawn from the university', |
---|
138 | 'K': 'Unregistered student', |
---|
139 | 'L': 'Referred student', |
---|
140 | 'M': 'Reinstatement', |
---|
141 | 'N': 'Student on transfer', |
---|
142 | 'O': 'NCE-III repeater', |
---|
143 | 'Y': 'No previous verdict', |
---|
144 | 'X': 'New 300 level student', |
---|
145 | 'Z': 'Successful student (provisional)', |
---|
146 | 'A1': 'First Class', |
---|
147 | 'A2': 'Second Class Upper', |
---|
148 | 'A3': 'Second Class Lower', |
---|
149 | 'A4': 'Third Class', |
---|
150 | 'A5': 'Pass', |
---|
151 | 'A6': 'Distinction', |
---|
152 | 'A7': 'Credit', |
---|
153 | 'A8': 'Merit', |
---|
154 | } |
---|
155 | |
---|
156 | # FCEOkene separators |
---|
157 | SEPARATORS_DICT = { |
---|
158 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
159 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
160 | 'form.alr_fname': _(u'Advanced Level Record'), |
---|
161 | 'form.hq_type': _(u'Higher Education Record'), |
---|
162 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
163 | 'form.nysc_year': _(u'NYSC Information'), |
---|
164 | 'form.employer': _(u'Employment History'), |
---|
165 | 'form.former_matric': _(u'Former FCEOkene Student'), |
---|
166 | } |
---|
167 | |
---|
168 | # FCEOkene prefix |
---|
169 | STUDENT_ID_PREFIX = u'K' |
---|