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

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

Let's use bed allocation payment tickets for pre-reservation.

  • Property svn:keywords set to Id
File size: 7.4 KB
RevLine 
[16717]1## $Id: utils.py 16882 2022-03-15 08:51:02Z henrik $
[15614]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
[16721]23from kofacustom.unidel.interfaces import MessageFactory as _
[15614]24
[16790]25def local(student):
26    lga = getattr(student, 'lga')
27    if lga and lga.startswith('delta'):
28        return True
29    return False
30
[15614]31class CustomStudentsUtils(NigeriaStudentsUtils):
32    """A collection of customized methods.
33
34    """
35
36    # refix
[16789]37    STUDENT_ID_PREFIX = u'D'
[16788]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)
[16835]108            if amount and not local(student):
109                amount += 40000
[16788]110        elif category == 'clearance':
111            try:
112                p_item = student['studycourse'].certificate.code
113            except (AttributeError, TypeError):
114                return _('Study course data are incomplete.'), None
115            amount = academic_session.clearance_fee
[16802]116            if not local(student):
[16790]117                amount += 10000
[16788]118        elif category == 'bed_allocation':
119            p_item = self.getAccommodationDetails(student)['bt']
[16882]120            amount = 0.0
[16788]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        elif category == 'combi' and combi:
135            categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES
136            for cat in combi:
137                fee_name = cat + '_fee'
138                cat_amount = getattr(academic_session, fee_name, 0.0)
139                if not cat_amount:
140                    return _('%s undefined.' % categories[cat]), None
141                amount += cat_amount
142                p_item += u'%s + ' % categories[cat]
143            p_item = p_item.strip(' + ')
144        else:
145            fee_name = category + '_fee'
146            amount = getattr(academic_session, fee_name, 0.0)
[16882]147        if category != 'bed_allocation' and amount in (0.0, None):
[16788]148            return _('Amount could not be determined.'), None
149        if self.samePaymentMade(student, category, p_item, p_session):
150            return _('This type of payment has already been made.'), None
151        if self._isPaymentDisabled(p_session, category, student):
152            return _('This category of payments has been disabled.'), None
153        payment = createObject(u'waeup.StudentOnlinePayment')
154        timestamp = ("%d" % int(time()*10000))[1:]
155        payment.p_id = "p%s" % timestamp
156        payment.p_category = category
157        payment.p_item = p_item
158        payment.p_session = p_session
159        payment.p_level = p_level
160        payment.p_current = p_current
161        payment.amount_auth = amount
162        payment.p_combi = combi
163        return None, payment
Note: See TracBrowser for help on using the repository browser.