source: main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py @ 9111

Last change on this file since 9111 was 9006, checked in by Henrik Bettermann, 12 years ago

Add special school fee regulations for staff members and foreign students.

  • Property svn:keywords set to Id
File size: 6.5 KB
Line 
1## $Id: utils.py 9006 2012-07-16 07:36:13Z 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##
18import grok
19from time import time
20from zope.component import createObject
21from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
23from waeup.kofa.accesscodes import create_accesscode
24from waeup.uniben.interfaces import MessageFactory as _
25
26class CustomStudentsUtils(NigeriaStudentsUtils):
27    """A collection of customized methods.
28
29    """
30
31    def getReturningData(self, student):
32        """ This method defines what happens after school fee payment
33        of returning students depending on the student's senate verdict.
34        """
35        prev_level = student['studycourse'].current_level
36        cur_verdict = student['studycourse'].current_verdict
37        if cur_verdict in ('A','B','L','M','N','Z',):
38            # Successful student
39            new_level = divmod(int(prev_level),100)[0]*100 + 100
40        elif cur_verdict == 'C':
41            # Student on probation
42            new_level = int(prev_level) + 10
43        else:
44            # Student is somehow in an undefined state.
45            # Level has to be set manually.
46            new_level = prev_level
47        new_session = student['studycourse'].current_session + 1
48        return new_session, new_level
49
50    def setPaymentDetails(self, category, student):
51        """Create Payment object and set the payment data of a student for
52        the payment category specified.
53
54        """
55        details = {}
56        p_item = u''
57        amount = 0.0
58        error = u''
59        p_session = student['studycourse'].current_session
60        p_level = student['studycourse'].current_level
61        session = str(p_session)
62        try:
63            academic_session = grok.getSite()['configuration'][session]
64        except KeyError:
65            return _(u'Session configuration object is not available.'), None
66        # Determine fee.
67        if category == 'transfer':
68            amount = academic_session.transfer_fee
69        elif category == 'gown':
70            amount = academic_session.gown_fee
71        elif category == 'bed_allocation':
72            amount = academic_session.booking_fee
73        elif category == 'hostel_maintenance':
74            amount = academic_session.maint_fee
75        elif category == 'clearance':
76            try:
77                p_item = student['studycourse'].certificate.code
78            except (AttributeError, TypeError):
79                return _('Study course data are incomplete.'), None
80            if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
81                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
82                amount = 17250.0
83            else:
84                amount = 34250.0
85        elif category == 'schoolfee':
86            try:
87                certificate = student['studycourse'].certificate
88                p_item = certificate.code
89            except (AttributeError, TypeError):
90                return _('Study course data are incomplete.'), None
91            if student.state == CLEARED:
92                if student.is_foreigner:
93                    amount = getattr(certificate, 'school_fee_3', 0.0)
94                else:
95                    amount = getattr(certificate, 'school_fee_1', 0.0)
96            elif student.state == RETURNING:
97                # In case of returning school fee payment the payment session
98                # and level contain the values of the session the student
99                # has paid for.
100                p_session, p_level = self.getReturningData(student)
101                if student.is_foreigner:
102                    amount = getattr(certificate, 'school_fee_4', 0.0)
103                else:
104                    amount = getattr(certificate, 'school_fee_2', 0.0)
105                try:
106                    academic_session = grok.getSite()[
107                        'configuration'][str(p_session)]
108                except KeyError:
109                    return _(u'Session configuration object is not available.'), None
110            elif student.is_postgrad and student.state == PAID:
111                # Returning postgraduate students also pay for the next session
112                # but their level always remains the same.
113                p_session += 1
114                if student.is_foreigner:
115                    amount = getattr(certificate, 'school_fee_4', 0.0)
116                else:
117                    amount = getattr(certificate, 'school_fee_2', 0.0)
118                try:
119                    academic_session = grok.getSite()[
120                        'configuration'][str(p_session)]
121                except KeyError:
122                    return _(u'Session configuration object is not available.'), None
123            # Give 50% school fee discount to staff members.
124            if student.is_staff:
125                amount /= 2
126        if amount in (0.0, None):
127            return _(u'Amount could not be determined.'), None
128        # Add session specific penalty fee.
129        if category == 'schoolfee' and student.is_postgrad:
130            amount += academic_session.penalty_pg
131        elif category == 'schoolfee':
132            amount += academic_session.penalty_ug
133        # Create ticket.
134        for key in student['payments'].keys():
135            ticket = student['payments'][key]
136            if ticket.p_state == 'paid' and\
137               ticket.p_category == category and \
138               ticket.p_item == p_item and \
139               ticket.p_session == p_session:
140                  return _('This type of payment has already been made.'), None
141        payment = createObject(u'waeup.StudentOnlinePayment')
142        timestamp = ("%d" % int(time()*10000))[1:]
143        payment.p_id = "p%s" % timestamp
144        payment.p_category = category
145        payment.p_item = p_item
146        payment.p_session = p_session
147        payment.p_level = p_level
148        payment.amount_auth = amount
149        return None, payment
150
151    # Uniben prefix
152    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.