source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/utils.py @ 15800

Last change on this file since 15800 was 15780, checked in by Henrik Bettermann, 5 years ago

Second instalments can be paid in all registration states.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1## $Id: utils.py 15780 2019-11-08 06:58:44Z 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##
18from time import time
19from zope.component import createObject, getUtility
20from waeup.kofa.interfaces import (IKofaUtils,
21    ADMITTED, CLEARANCE, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
23from kofacustom.iuokada.interfaces import MessageFactory as _
24
25class CustomStudentsUtils(NigeriaStudentsUtils):
26    """A collection of customized methods.
27
28    """
29
30    # refix
31    STUDENT_ID_PREFIX = u'I'
32
33    SKIP_UPLOAD_VIEWLETS = (
34        'acceptanceletterupload', 'certificateupload'
35        )
36    # Maximum size of upload files in kB
37    MAX_KB = 500
38
39    #: A tuple containing the names of registration states in which changing of
40    #: passport pictures is allowed.
41    PORTRAIT_CHANGE_STATES = (ADMITTED, CLEARANCE,)
42
43    def warnCreditsOOR(self, studylevel, course=None):
44        """Return message if credits are out of range. In the base
45        package only maximum credits is set.
46        """
47        if course and studylevel.total_credits + course.credits > 54:
48            return _('Maximum credits exceeded.')
49        elif studylevel.total_credits > 54:
50            return _('Maximum credits exceeded.')
51        return
52
53    def setPaymentDetails(self, category, student,
54            previous_session, previous_level, combi=[]):
55        """Create a payment ticket and set the payment data of a
56        student for the payment category specified.
57        """
58        p_item = u''
59        amount = 0.0
60        if previous_session:
61            if previous_session < student['studycourse'].entry_session:
62                return _('The previous session must not fall below '
63                         'your entry session.'), None
64            if category == 'schoolfee':
65                # School fee is always paid for the following session
66                if previous_session > student['studycourse'].current_session:
67                    return _('This is not a previous session.'), None
68            else:
69                if previous_session > student['studycourse'].current_session - 1:
70                    return _('This is not a previous session.'), None
71            p_session = previous_session
72            p_level = previous_level
73            p_current = False
74        else:
75            p_session = student['studycourse'].current_session
76            p_level = student['studycourse'].current_level
77            p_current = True
78        academic_session = self._getSessionConfiguration(p_session)
79        if academic_session == None:
80            return _(u'Session configuration object is not available.'), None
81        # Determine fee.
82        if category in ('schoolfee', 'schoolfee40',
83                        'secondinstal'):
84            try:
85                certificate = student['studycourse'].certificate
86                p_item = certificate.code
87            except (AttributeError, TypeError):
88                return _('Study course data are incomplete.'), None
89            if previous_session:
90                # Students can pay for previous sessions in all
91                # workflow states.  Fresh students are excluded by the
92                # update method of the PreviousPaymentAddFormPage.
93                if previous_level == 100:
94                    amount = getattr(certificate, 'school_fee_1', 0.0)
95                else:
96                    amount = getattr(certificate, 'school_fee_2', 0.0)
97                if category == 'schoolfee40':
98                    amount = 0.4*amount
99                elif category == 'secondinstal':
100                    amount = 0.6*amount
101            else:
102                if category == 'secondinstal':
103                    if student.is_fresh:
104                        amount = 0.6 * getattr(certificate, 'school_fee_1', 0.0)
105                    else:
106                        amount = 0.6 * getattr(certificate, 'school_fee_2', 0.0)
107                else:
108                    if student.state == CLEARED:
109                        amount = getattr(certificate, 'school_fee_1', 0.0)
110                    elif student.state == RETURNING:
111                        # In case of returning school fee payment the
112                        # payment session and level contain the values of
113                        # the session the student has paid for. Payment
114                        # session is always next session.
115                        p_session, p_level = self.getReturningData(student)
116                        academic_session = self._getSessionConfiguration(p_session)
117                        if academic_session == None:
118                            return _(
119                                u'Session configuration object is not available.'
120                                ), None
121                        amount = getattr(certificate, 'school_fee_2', 0.0)
122                    elif student.is_postgrad and student.state == PAID:
123                        # Returning postgraduate students also pay for the
124                        # next session but their level always remains the
125                        # same.
126                        p_session += 1
127                        academic_session = self._getSessionConfiguration(p_session)
128                        if academic_session == None:
129                            return _(
130                                u'Session configuration object is not available.'
131                                ), None
132                        amount = getattr(certificate, 'school_fee_2', 0.0)
133                    if amount and category == 'schoolfee40':
134                        amount = 0.4*amount
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        #elif category == 'bed_allocation':
142        #    p_item = self.getAccommodationDetails(student)['bt']
143        #    amount = academic_session.booking_fee
144        #elif category == 'hostel_maintenance':
145        #    amount = 0.0
146        #    bedticket = student['accommodation'].get(
147        #        str(student.current_session), None)
148        #    if bedticket is not None and bedticket.bed is not None:
149        #        p_item = bedticket.bed_coordinates
150        #        if bedticket.bed.__parent__.maint_fee > 0:
151        #            amount = bedticket.bed.__parent__.maint_fee
152        #        else:
153        #            # fallback
154        #            amount = academic_session.maint_fee
155        #    else:
156        #        return _(u'No bed allocated.'), None
157        elif category == 'combi' and combi:
158            categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES
159            for cat in combi:
160                fee_name = cat + '_fee'
161                cat_amount = getattr(academic_session, fee_name, 0.0)
162                if not cat_amount:
163                    return _('%s undefined.' % categories[cat]), None
164                amount += cat_amount
165                p_item += u'%s + ' % categories[cat]
166            p_item = p_item.strip(' + ')
167        else:
168            fee_name = category + '_fee'
169            amount = getattr(academic_session, fee_name, 0.0)
170        if amount in (0.0, None):
171            return _('Amount could not be determined.'), None
172        if self.samePaymentMade(student, category, p_item, p_session):
173            return _('This type of payment has already been made.'), None
174        if self._isPaymentDisabled(p_session, category, student):
175            return _('This category of payments has been disabled.'), None
176        payment = createObject(u'waeup.StudentOnlinePayment')
177        timestamp = ("%d" % int(time()*10000))[1:]
178        payment.p_id = "p%s" % timestamp
179        payment.p_category = category
180        payment.p_item = p_item
181        payment.p_session = p_session
182        payment.p_level = p_level
183        payment.p_current = p_current
184        payment.amount_auth = amount
185        payment.p_combi = combi
186        return None, payment
Note: See TracBrowser for help on using the repository browser.