source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/utils.py @ 17644

Last change on this file since 17644 was 17644, checked in by Henrik Bettermann, 12 months ago

Change configuration

  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1## $Id: utils.py 17644 2023-11-16 07:21:45Z 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##
18import grok
19from time import time
20from zope.component import createObject, getUtility
21from waeup.kofa.interfaces import (IKofaUtils,
22    CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from kofacustom.unidel.interfaces import MessageFactory as _
25
26def local(student):
27    lga = getattr(student, 'lga')
28    if lga and lga.startswith('delta'):
29        return True
30    return False
31
32class CustomStudentsUtils(NigeriaStudentsUtils):
33    """A collection of customized methods.
34
35    """
36
37    # refix
38    STUDENT_ID_PREFIX = u'D'
39
40    def _clearancePaymentMade(self, student):
41        if len(student['payments']):
42            for ticket in student['payments'].values():
43                if ticket.p_state == 'paid' and \
44                    ticket.p_category == 'clearance':
45                    return True
46        return False
47
48    def _isPaymentDisabled(self, p_session, category, student):
49        academic_session = self._getSessionConfiguration(p_session)
50        if category == 'schoolfee':
51            if 'sf_all' in academic_session.payment_disabled:
52                return True
53            if student.current_mode == 'ug_ft' and \
54                'sf_ugft' in academic_session.payment_disabled:
55                return True
56        return False
57
58    def setPaymentDetails(self, category, student,
59            previous_session=None, previous_level=None, combi=[]):
60        """Create a payment ticket and set the payment data of a
61        student for the payment category specified.
62        """
63        p_item = u''
64        amount = 0.0
65        if previous_session:
66            if previous_session < student['studycourse'].entry_session:
67                return _('The previous session must not fall below '
68                         'your entry session.'), None
69            if category == 'schoolfee':
70                # School fee is always paid for the following session
71                if previous_session > student['studycourse'].current_session:
72                    return _('This is not a previous session.'), None
73            else:
74                if previous_session > student['studycourse'].current_session - 1:
75                    return _('This is not a previous session.'), None
76            p_session = previous_session
77            p_level = previous_level
78            p_current = False
79        else:
80            p_session = student['studycourse'].current_session
81            p_level = student['studycourse'].current_level
82            p_current = True
83        academic_session = self._getSessionConfiguration(p_session)
84        if academic_session == None:
85            return _(u'Session configuration object is not available.'), None
86        # Determine fee.
87        if category == 'schoolfee':
88            try:
89                certificate = student['studycourse'].certificate
90                p_item = certificate.code
91            except (AttributeError, TypeError):
92                return _('Study course data are incomplete.'), None
93            if previous_session:
94                # Students can pay for previous sessions in all
95                # workflow states.  Fresh students are excluded by the
96                # update method of the PreviousPaymentAddFormPage.
97                if previous_level == 100:
98                    amount = getattr(certificate, 'school_fee_1', 0.0)
99                else:
100                    amount = getattr(certificate, 'school_fee_2', 0.0)
101            else:
102                if student.faccode == 'JUPEB':
103                    if not self._clearancePaymentMade(student):
104                        return _(u'Acceptance fee must be paid first.'), None
105                if student.state == CLEARED:
106                    amount = getattr(certificate, 'school_fee_1', 0.0)
107                elif student.state == RETURNING:
108                    # In case of returning school fee payment the
109                    # payment session and level contain the values of
110                    # the session the student has paid for. Payment
111                    # session is always next session.
112                    p_session, p_level = self.getReturningData(student)
113                    academic_session = self._getSessionConfiguration(p_session)
114                    if academic_session == None:
115                        return _(
116                            u'Session configuration object is not available.'
117                            ), None
118                    amount = getattr(certificate, 'school_fee_2', 0.0)
119                elif student.is_postgrad and student.state == PAID:
120                    # Returning postgraduate students also pay for the
121                    # next session but their level always remains the
122                    # same.
123                    p_session += 1
124                    academic_session = self._getSessionConfiguration(p_session)
125                    if academic_session == None:
126                        return _(
127                            u'Session configuration object is not available.'
128                            ), None
129                    amount = getattr(certificate, 'school_fee_2', 0.0)
130            if amount and not local(student):
131                if student.faccode == 'NCE':
132                    amount += 14600
133                elif student.faccode not in ('PRE', 'JUPEB', 'DELSU'):
134                    amount += 40000
135        elif category == 'clearance':
136            try:
137                p_item = student['studycourse'].certificate.code
138            except (AttributeError, TypeError):
139                return _('Study course data are incomplete.'), None
140            amount = academic_session.clearance_fee
141            if student.current_mode in ('ug_ft', 'de_ft'):
142                if local(student):
143                    amount = academic_session.ugftlocal_clearance_fee
144                else:
145                    amount = academic_session.ugft_clearance_fee
146            elif student.faccode == 'PRE':
147                amount = 20000.0
148            elif student.faccode == 'JUPEB':
149                amount = 25000.0
150            elif student.current_mode.startswith('dp'):
151                amount = 20000.0
152        elif category == 'bed_allocation':
153            acco_details = self.getAccommodationDetails(student)
154            p_session = acco_details['booking_session']
155            p_item = acco_details['bt']
156            amount = academic_session.booking_fee
157        elif category == 'hostel_maintenance':
158            amount = 0.0
159            booking_session = grok.getSite()['hostels'].accommodation_session
160            bedticket = student['accommodation'].get(str(booking_session), None)
161            if bedticket is not None and bedticket.bed is not None:
162                p_session = booking_session
163                p_item = bedticket.bed_coordinates
164                if bedticket.bed.__parent__.maint_fee > 0:
165                    amount = bedticket.bed.__parent__.maint_fee
166                else:
167                    # fallback
168                    amount = academic_session.maint_fee
169            else:
170                return _(u'No bed allocated.'), None
171        elif category == 'combi' and combi:
172            categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES
173            for cat in combi:
174                fee_name = cat + '_fee'
175                cat_amount = getattr(academic_session, fee_name, 0.0)
176                if not cat_amount:
177                    return _('%s undefined.' % categories[cat]), None
178                amount += cat_amount
179                p_item += u'%s + ' % categories[cat]
180            p_item = p_item.strip(' + ')
181        else:
182            fee_name = category + '_fee'
183            amount = getattr(academic_session, fee_name, 0.0)
184        if category != 'bed_allocation' and amount in (0.0, None):
185            return _('Amount could not be determined.'), None
186        if self.samePaymentMade(student, category, p_item, p_session):
187            return _('This type of payment has already been made.'), None
188        if self._isPaymentDisabled(p_session, category, student):
189            return _('This category of payments has been disabled.'), None
190        payment = createObject(u'waeup.StudentOnlinePayment')
191        timestamp = ("%d" % int(time()*10000))[1:]
192        payment.p_id = "p%s" % timestamp
193        payment.p_category = category
194        payment.p_item = p_item
195        payment.p_session = p_session
196        payment.p_level = p_level
197        payment.p_current = p_current
198        payment.amount_auth = amount
199        payment.p_combi = combi
200        return None, payment
201
202    def getAccommodationDetails(self, student):
203        """Determine the accommodation data of a student.
204        """
205        d = {}
206        d['error'] = u''
207        hostels = grok.getSite()['hostels']
208        d['booking_session'] = hostels.accommodation_session
209        d['allowed_states'] = hostels.accommodation_states
210        d['startdate'] = hostels.startdate
211        d['enddate'] = hostels.enddate
212        d['expired'] = hostels.expired
213        # Determine bed type
214        if entry_session == grok.getSite()['hostels'].accommodation_session:
215            bt = 'fr'
216        elif current_level >= end_level:
217            bt = 'fi'
218        else:
219            bt = 're'
220        #if student.current_level >= 300:
221        #    bt = 'na'
222        if student.sex == 'f':
223            sex = 'female'
224        else:
225            sex = 'male'
226        special_handling = 'regular'
227        #if student.faccode in ('FLW', 'FMS'):
228        #    special_handling = 'oyibu'
229        #if student.faccode in ('FET', 'FES'):
230        #    special_handling = 'alero'
231        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
232        return d
233
Note: See TracBrowser for help on using the repository browser.