source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/students/utils.py @ 14878

Last change on this file since 14878 was 14878, checked in by Henrik Bettermann, 7 years ago

HNDFT are paying acceptance fees too, so HNDFT Deltan 15,000, Non-Deltan 20,000

  • Property svn:keywords set to Id
File size: 8.2 KB
Line 
1## $Id: utils.py 14878 2017-10-24 13:37:42Z 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.dspg.interfaces import MessageFactory as _
24
25
26def local(student):
27    lga = getattr(student, 'lga')
28    if lga and lga.startswith('delta'):
29        return True
30    return False
31
32class CustomStudentsUtils(NigeriaStudentsUtils):
33    """A collection of customized methods.
34    """
35
36    # prefix
37    STUDENT_ID_PREFIX = u'P'
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                    if local(student):
80                        amount = getattr(certificate, 'school_fee_1', 0.0)
81                    else:
82                        amount = getattr(certificate, 'school_fee_3', 0.0)
83                else:
84                    if local(student):
85                        amount = getattr(certificate, 'school_fee_2', 0.0)
86                    else:
87                        amount = getattr(certificate, 'school_fee_4', 0.0)
88            else:
89                if student.state == CLEARED:
90                    if local(student):
91                        amount = getattr(certificate, 'school_fee_1', 0.0)
92                    else:
93                        amount = getattr(certificate, 'school_fee_3', 0.0)
94                elif student.state == RETURNING:
95                    # In case of returning school fee payment the
96                    # payment session and level contain the values of
97                    # the session the student has paid for. Payment
98                    # session is always next session.
99                    p_session, p_level = self.getReturningData(student)
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                    if local(student):
106                        amount = getattr(certificate, 'school_fee_2', 0.0)
107                    else:
108                        amount = getattr(certificate, 'school_fee_4', 0.0)
109                elif student.is_postgrad and student.state == PAID:
110                    # Returning postgraduate students also pay for the
111                    # next session but their level always remains the
112                    # same.
113                    p_session += 1
114                    academic_session = self._getSessionConfiguration(p_session)
115                    if academic_session == None:
116                        return _(
117                            u'Session configuration object is not available.'
118                            ), None
119                    if local(student):
120                        amount = getattr(certificate, 'school_fee_2', 0.0)
121                    else:
122                        amount = getattr(certificate, 'school_fee_4', 0.0)
123        elif category == 'clearance':
124            try:
125                p_item = student['studycourse'].certificate.code
126            except (AttributeError, TypeError):
127                return _('Study course data are incomplete.'), None
128            amount = academic_session.clearance_fee
129            if student.current_mode == 'nd_ft' and local(student):
130                amount *= 0.5
131            if student.current_mode == 'hnd_ft' and local(student):
132                amount *= 0.75
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        elif category == 'transcript':
150            amount = academic_session.transcript_fee
151        elif category == 'transfer':
152            amount = academic_session.transfer_fee
153        elif category == 'late_registration':
154            amount = academic_session.late_registration_fee
155        elif category == 'carryover1':
156            amount = 10000.0
157        elif category == 'carryover2':
158            amount = 10000.0
159        elif category == 'carryover3':
160            amount = 10000.0
161        elif category == 'carryover4':
162            amount = 13000.0
163        else:
164            fee_name = category + '_fee'
165            amount = getattr(academic_session, fee_name, 0.0)
166        if amount in (0.0, None):
167            return _('Amount could not be determined.'), None
168        if self.samePaymentMade(student, category, p_item, p_session):
169            return _('This type of payment has already been made.'), None
170        if self._isPaymentDisabled(p_session, category, student):
171            return _('This category of payments has been disabled.'), None
172        payment = createObject(u'waeup.StudentOnlinePayment')
173        timestamp = ("%d" % int(time()*10000))[1:]
174        payment.p_id = "p%s" % timestamp
175        payment.p_category = category
176        payment.p_item = p_item
177        payment.p_session = p_session
178        payment.p_level = p_level
179        payment.p_current = p_current
180        payment.amount_auth = amount
181        return None, payment
Note: See TracBrowser for help on using the repository browser.