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

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

Double max files size.

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