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

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

Remove acceptanceletterupload viewlet.

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