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

Last change on this file since 17662 was 17662, checked in by Henrik Bettermann, 10 months ago

Customize warnCreditsOOR.

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