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

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

Adjust to changes in base package.

  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1## $Id: utils.py 15672 2019-10-13 21:01:01Z 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 > 120:
48            return _('Maximum credits exceeded.')
49        elif studylevel.total_credits > 120:
50            return _('Maximum credits exceeded.')
51        return
52
53    def setPaymentDetails(self, category, student,
54            previous_session, previous_level, p_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            else:
98                if student.state == CLEARED:
99                    amount = getattr(certificate, 'school_fee_1', 0.0)
100                elif student.state == RETURNING:
101                    # In case of returning school fee payment the
102                    # payment session and level contain the values of
103                    # the session the student has paid for. Payment
104                    # session is always next session.
105                    p_session, p_level = self.getReturningData(student)
106                    academic_session = self._getSessionConfiguration(p_session)
107                    if academic_session == None:
108                        return _(
109                            u'Session configuration object is not available.'
110                            ), None
111                    amount = getattr(certificate, 'school_fee_2', 0.0)
112                elif student.is_postgrad and student.state == PAID:
113                    # Returning postgraduate students also pay for the
114                    # next session but their level always remains the
115                    # same.
116                    p_session += 1
117                    academic_session = self._getSessionConfiguration(p_session)
118                    if academic_session == None:
119                        return _(
120                            u'Session configuration object is not available.'
121                            ), None
122                    amount = getattr(certificate, 'school_fee_2', 0.0)
123            if category == 'schoolfee40':
124                amount *= 0.4
125            elif category == 'secondinstal':
126                amount *= 0.6
127        elif category == 'clearance':
128            try:
129                p_item = student['studycourse'].certificate.code
130            except (AttributeError, TypeError):
131                return _('Study course data are incomplete.'), None
132            amount = academic_session.clearance_fee
133        #elif category == 'bed_allocation':
134        #    p_item = self.getAccommodationDetails(student)['bt']
135        #    amount = academic_session.booking_fee
136        #elif category == 'hostel_maintenance':
137        #    amount = 0.0
138        #    bedticket = student['accommodation'].get(
139        #        str(student.current_session), None)
140        #    if bedticket is not None and bedticket.bed is not None:
141        #        p_item = bedticket.bed_coordinates
142        #        if bedticket.bed.__parent__.maint_fee > 0:
143        #            amount = bedticket.bed.__parent__.maint_fee
144        #        else:
145        #            # fallback
146        #            amount = academic_session.maint_fee
147        #    else:
148        #        return _(u'No bed allocated.'), None
149        else:
150            fee_name = category + '_fee'
151            amount = getattr(academic_session, fee_name, 0.0)
152        if amount in (0.0, None):
153            return _('Amount could not be determined.'), None
154        if self.samePaymentMade(student, category, p_item, p_session):
155            return _('This type of payment has already been made.'), None
156        if self._isPaymentDisabled(p_session, category, student):
157            return _('This category of payments has been disabled.'), None
158        payment = createObject(u'waeup.StudentOnlinePayment')
159        timestamp = ("%d" % int(time()*10000))[1:]
160        payment.p_id = "p%s" % timestamp
161        payment.p_category = category
162        payment.p_item = p_item
163        payment.p_session = p_session
164        payment.p_level = p_level
165        payment.p_current = p_current
166        payment.amount_auth = amount
167        return None, payment
Note: See TracBrowser for help on using the repository browser.