1 | ## $Id: utils.py 16893 2022-03-17 08:05:57Z 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, getUtility |
---|
21 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
22 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
24 | from kofacustom.unidel.interfaces import MessageFactory as _ |
---|
25 | |
---|
26 | def local(student): |
---|
27 | lga = getattr(student, 'lga') |
---|
28 | if lga and lga.startswith('delta'): |
---|
29 | return True |
---|
30 | return False |
---|
31 | |
---|
32 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
33 | """A collection of customized methods. |
---|
34 | |
---|
35 | """ |
---|
36 | |
---|
37 | # refix |
---|
38 | STUDENT_ID_PREFIX = u'D' |
---|
39 | |
---|
40 | def setPaymentDetails(self, category, student, |
---|
41 | previous_session=None, previous_level=None, combi=[]): |
---|
42 | """Create a payment ticket and set the payment data of a |
---|
43 | student for the payment category specified. |
---|
44 | """ |
---|
45 | p_item = u'' |
---|
46 | amount = 0.0 |
---|
47 | if previous_session: |
---|
48 | if previous_session < student['studycourse'].entry_session: |
---|
49 | return _('The previous session must not fall below ' |
---|
50 | 'your entry session.'), None |
---|
51 | if category == 'schoolfee': |
---|
52 | # School fee is always paid for the following session |
---|
53 | if previous_session > student['studycourse'].current_session: |
---|
54 | return _('This is not a previous session.'), None |
---|
55 | else: |
---|
56 | if previous_session > student['studycourse'].current_session - 1: |
---|
57 | return _('This is not a previous session.'), None |
---|
58 | p_session = previous_session |
---|
59 | p_level = previous_level |
---|
60 | p_current = False |
---|
61 | else: |
---|
62 | p_session = student['studycourse'].current_session |
---|
63 | p_level = student['studycourse'].current_level |
---|
64 | p_current = True |
---|
65 | academic_session = self._getSessionConfiguration(p_session) |
---|
66 | if academic_session == None: |
---|
67 | return _(u'Session configuration object is not available.'), None |
---|
68 | # Determine fee. |
---|
69 | if category == 'schoolfee': |
---|
70 | try: |
---|
71 | certificate = student['studycourse'].certificate |
---|
72 | p_item = certificate.code |
---|
73 | except (AttributeError, TypeError): |
---|
74 | return _('Study course data are incomplete.'), None |
---|
75 | if previous_session: |
---|
76 | # Students can pay for previous sessions in all |
---|
77 | # workflow states. Fresh students are excluded by the |
---|
78 | # update method of the PreviousPaymentAddFormPage. |
---|
79 | if previous_level == 100: |
---|
80 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
81 | else: |
---|
82 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
83 | else: |
---|
84 | if student.state == CLEARED: |
---|
85 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
86 | elif student.state == RETURNING: |
---|
87 | # In case of returning school fee payment the |
---|
88 | # payment session and level contain the values of |
---|
89 | # the session the student has paid for. Payment |
---|
90 | # session is always next session. |
---|
91 | p_session, p_level = self.getReturningData(student) |
---|
92 | academic_session = self._getSessionConfiguration(p_session) |
---|
93 | if academic_session == None: |
---|
94 | return _( |
---|
95 | u'Session configuration object is not available.' |
---|
96 | ), None |
---|
97 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
98 | elif student.is_postgrad and student.state == PAID: |
---|
99 | # Returning postgraduate students also pay for the |
---|
100 | # next session but their level always remains the |
---|
101 | # same. |
---|
102 | p_session += 1 |
---|
103 | academic_session = self._getSessionConfiguration(p_session) |
---|
104 | if academic_session == None: |
---|
105 | return _( |
---|
106 | u'Session configuration object is not available.' |
---|
107 | ), None |
---|
108 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
109 | if amount and not local(student): |
---|
110 | amount += 40000 |
---|
111 | elif category == 'clearance': |
---|
112 | try: |
---|
113 | p_item = student['studycourse'].certificate.code |
---|
114 | except (AttributeError, TypeError): |
---|
115 | return _('Study course data are incomplete.'), None |
---|
116 | amount = academic_session.clearance_fee |
---|
117 | if not local(student): |
---|
118 | amount += 10000 |
---|
119 | elif category == 'bed_allocation': |
---|
120 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
121 | amount = 0.0 |
---|
122 | elif category == 'hostel_maintenance': |
---|
123 | amount = 0.0 |
---|
124 | bedticket = student['accommodation'].get( |
---|
125 | str(student.current_session), None) |
---|
126 | if bedticket is not None and bedticket.bed is not None: |
---|
127 | p_item = bedticket.bed_coordinates |
---|
128 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
129 | amount = bedticket.bed.__parent__.maint_fee |
---|
130 | else: |
---|
131 | # fallback |
---|
132 | amount = academic_session.maint_fee |
---|
133 | else: |
---|
134 | return _(u'No bed allocated.'), None |
---|
135 | elif category == 'combi' and combi: |
---|
136 | categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES |
---|
137 | for cat in combi: |
---|
138 | fee_name = cat + '_fee' |
---|
139 | cat_amount = getattr(academic_session, fee_name, 0.0) |
---|
140 | if not cat_amount: |
---|
141 | return _('%s undefined.' % categories[cat]), None |
---|
142 | amount += cat_amount |
---|
143 | p_item += u'%s + ' % categories[cat] |
---|
144 | p_item = p_item.strip(' + ') |
---|
145 | else: |
---|
146 | fee_name = category + '_fee' |
---|
147 | amount = getattr(academic_session, fee_name, 0.0) |
---|
148 | if category != 'bed_allocation' and amount in (0.0, None): |
---|
149 | return _('Amount could not be determined.'), None |
---|
150 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
151 | return _('This type of payment has already been made.'), None |
---|
152 | if self._isPaymentDisabled(p_session, category, student): |
---|
153 | return _('This category of payments has been disabled.'), None |
---|
154 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
155 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
156 | payment.p_id = "p%s" % timestamp |
---|
157 | payment.p_category = category |
---|
158 | payment.p_item = p_item |
---|
159 | payment.p_session = p_session |
---|
160 | payment.p_level = p_level |
---|
161 | payment.p_current = p_current |
---|
162 | payment.amount_auth = amount |
---|
163 | payment.p_combi = combi |
---|
164 | return None, payment |
---|
165 | |
---|
166 | def getAccommodationDetails(self, student): |
---|
167 | """Determine the accommodation data of a student. |
---|
168 | """ |
---|
169 | d = {} |
---|
170 | d['error'] = u'' |
---|
171 | hostels = grok.getSite()['hostels'] |
---|
172 | d['booking_session'] = hostels.accommodation_session |
---|
173 | d['allowed_states'] = hostels.accommodation_states |
---|
174 | d['startdate'] = hostels.startdate |
---|
175 | d['enddate'] = hostels.enddate |
---|
176 | d['expired'] = hostels.expired |
---|
177 | # Determine bed type |
---|
178 | bt = 'all' |
---|
179 | if student.sex == 'f': |
---|
180 | sex = 'female' |
---|
181 | else: |
---|
182 | sex = 'male' |
---|
183 | special_handling = 'regular' |
---|
184 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
185 | return d |
---|