source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/utils.py @ 16827

Last change on this file since 16827 was 16802, checked in by Henrik Bettermann, 3 years ago

Uups, non-local students pay more not local.

  • Property svn:keywords set to Id
File size: 7.3 KB
Line 
1## $Id: utils.py 16802 2022-02-13 15:21:18Z 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.unidel.interfaces import MessageFactory as _
24
25def local(student):
26    lga = getattr(student, 'lga')
27    if lga and lga.startswith('delta'):
28        return True
29    return False
30
31class CustomStudentsUtils(NigeriaStudentsUtils):
32    """A collection of customized methods.
33
34    """
35
36    # refix
37    STUDENT_ID_PREFIX = u'D'
38
39    def setPaymentDetails(self, category, student,
40            previous_session=None, previous_level=None, combi=[]):
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            if not local(student):
115                amount += 10000
116        elif category == 'bed_allocation':
117            p_item = self.getAccommodationDetails(student)['bt']
118            amount = academic_session.booking_fee
119        elif category == 'hostel_maintenance':
120            amount = 0.0
121            bedticket = student['accommodation'].get(
122                str(student.current_session), None)
123            if bedticket is not None and bedticket.bed is not None:
124                p_item = bedticket.bed_coordinates
125                if bedticket.bed.__parent__.maint_fee > 0:
126                    amount = bedticket.bed.__parent__.maint_fee
127                else:
128                    # fallback
129                    amount = academic_session.maint_fee
130            else:
131                return _(u'No bed allocated.'), None
132        elif category == 'combi' and combi:
133            categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES
134            for cat in combi:
135                fee_name = cat + '_fee'
136                cat_amount = getattr(academic_session, fee_name, 0.0)
137                if not cat_amount:
138                    return _('%s undefined.' % categories[cat]), None
139                amount += cat_amount
140                p_item += u'%s + ' % categories[cat]
141            p_item = p_item.strip(' + ')
142        else:
143            fee_name = category + '_fee'
144            amount = getattr(academic_session, fee_name, 0.0)
145        if amount in (0.0, None):
146            return _('Amount could not be determined.'), None
147        if self.samePaymentMade(student, category, p_item, p_session):
148            return _('This type of payment has already been made.'), None
149        if self._isPaymentDisabled(p_session, category, student):
150            return _('This category of payments has been disabled.'), None
151        payment = createObject(u'waeup.StudentOnlinePayment')
152        timestamp = ("%d" % int(time()*10000))[1:]
153        payment.p_id = "p%s" % timestamp
154        payment.p_category = category
155        payment.p_item = p_item
156        payment.p_session = p_session
157        payment.p_level = p_level
158        payment.p_current = p_current
159        payment.amount_auth = amount
160        payment.p_combi = combi
161        return None, payment
Note: See TracBrowser for help on using the repository browser.