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