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

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

Add missing import.

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: utils.py 15658 2019-10-10 12:24:02Z 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 setPaymentDetails(self, category, student,
44            previous_session, previous_level):
45        """Create a payment ticket and set the payment data of a
46        student for the payment category specified.
47        """
48        p_item = u''
49        amount = 0.0
50        if previous_session:
51            if previous_session < student['studycourse'].entry_session:
52                return _('The previous session must not fall below '
53                         'your entry session.'), None
54            if category == 'schoolfee':
55                # School fee is always paid for the following session
56                if previous_session > student['studycourse'].current_session:
57                    return _('This is not a previous session.'), None
58            else:
59                if previous_session > student['studycourse'].current_session - 1:
60                    return _('This is not a previous session.'), None
61            p_session = previous_session
62            p_level = previous_level
63            p_current = False
64        else:
65            p_session = student['studycourse'].current_session
66            p_level = student['studycourse'].current_level
67            p_current = True
68        academic_session = self._getSessionConfiguration(p_session)
69        if academic_session == None:
70            return _(u'Session configuration object is not available.'), None
71        # Determine fee.
72        if category == 'schoolfee':
73            try:
74                certificate = student['studycourse'].certificate
75                p_item = certificate.code
76            except (AttributeError, TypeError):
77                return _('Study course data are incomplete.'), None
78            if previous_session:
79                # Students can pay for previous sessions in all
80                # workflow states.  Fresh students are excluded by the
81                # update method of the PreviousPaymentAddFormPage.
82                if previous_level == 100:
83                    amount = getattr(certificate, 'school_fee_1', 0.0)
84                else:
85                    amount = getattr(certificate, 'school_fee_2', 0.0)
86            else:
87                if student.state == CLEARED:
88                    amount = getattr(certificate, 'school_fee_1', 0.0)
89                elif student.state == RETURNING:
90                    # In case of returning school fee payment the
91                    # payment session and level contain the values of
92                    # the session the student has paid for. Payment
93                    # session is always next session.
94                    p_session, p_level = self.getReturningData(student)
95                    academic_session = self._getSessionConfiguration(p_session)
96                    if academic_session == None:
97                        return _(
98                            u'Session configuration object is not available.'
99                            ), None
100                    amount = getattr(certificate, 'school_fee_2', 0.0)
101                elif student.is_postgrad and student.state == PAID:
102                    # Returning postgraduate students also pay for the
103                    # next session but their level always remains the
104                    # same.
105                    p_session += 1
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 category == 'clearance':
113            try:
114                p_item = student['studycourse'].certificate.code
115            except (AttributeError, TypeError):
116                return _('Study course data are incomplete.'), None
117            amount = academic_session.clearance_fee
118        elif category == 'bed_allocation':
119            p_item = self.getAccommodationDetails(student)['bt']
120            amount = academic_session.booking_fee
121        elif category == 'hostel_maintenance':
122            amount = 0.0
123            bedticket = student['accommodation'].get(
124                str(student.current_session), None)
125            if bedticket is not None and bedticket.bed is not None:
126                p_item = bedticket.bed_coordinates
127                if bedticket.bed.__parent__.maint_fee > 0:
128                    amount = bedticket.bed.__parent__.maint_fee
129                else:
130                    # fallback
131                    amount = academic_session.maint_fee
132            else:
133                return _(u'No bed allocated.'), None
134        else:
135            fee_name = category + '_fee'
136            amount = getattr(academic_session, fee_name, 0.0)
137        if amount in (0.0, None):
138            return _('Amount could not be determined.'), None
139        if self.samePaymentMade(student, category, p_item, p_session):
140            return _('This type of payment has already been made.'), None
141        if self._isPaymentDisabled(p_session, category, student):
142            return _('This category of payments has been disabled.'), None
143        payment = createObject(u'waeup.StudentOnlinePayment')
144        timestamp = ("%d" % int(time()*10000))[1:]
145        payment.p_id = "p%s" % timestamp
146        payment.p_category = category
147        payment.p_item = p_item
148        payment.p_session = p_session
149        payment.p_level = p_level
150        payment.p_current = p_current
151        payment.amount_auth = amount
152        return None, payment
Note: See TracBrowser for help on using the repository browser.