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

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

Previous session must be valid.

  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1## $Id: utils.py 9206 2012-09-19 14:24:46Z 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            previous_session, previous_level):
52        """Create Payment object and set the payment data of a student for
53        the payment category specified.
54
55        """
56        details = {}
57        p_item = u''
58        amount = 0.0
59        error = u''
60        if previous_session:
61            p_session = previous_session
62            p_level = previous_level
63            p_current = False
64        else:
65            p_session = student['studycourse'].current_session
66            p_level = student['studycourse'].current_level
67            p_current = True
68        session = str(p_session)
69        try:
70            academic_session = grok.getSite()['configuration'][session]
71        except KeyError:
72            return _(u'Session configuration object is not available.'), None
73        # Determine fee.
74        if category == 'transfer':
75            amount = academic_session.transfer_fee
76        elif category == 'gown':
77            amount = academic_session.gown_fee
78        elif category == 'bed_allocation':
79            amount = academic_session.booking_fee
80        elif category == 'hostel_maintenance':
81            amount = academic_session.maint_fee
82        elif category == 'clearance':
83            try:
84                p_item = student['studycourse'].certificate.code
85            except (AttributeError, TypeError):
86                return _('Study course data are incomplete.'), None
87            if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
88                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
89                amount = 17250.0
90            else:
91                amount = 34250.0
92        elif category == 'schoolfee':
93            try:
94                certificate = student['studycourse'].certificate
95                p_item = certificate.code
96            except (AttributeError, TypeError):
97                return _('Study course data are incomplete.'), None
98            if previous_session:
99                if previous_session < student['studycourse'].entry_session:
100                    return _('The previous session must not fall below '
101                             'your entry session.'), None
102                if previous_session > student['studycourse'].current_session - 1:
103                    return _('This is not a previous session.'), None
104                if previous_session == student['studycourse'].entry_session:
105                    if student.is_foreigner:
106                        amount = getattr(certificate, 'school_fee_3', 0.0)
107                    else:
108                        amount = getattr(certificate, 'school_fee_1', 0.0)
109                else:
110                    if student.is_foreigner:
111                        amount = getattr(certificate, 'school_fee_4', 0.0)
112                    else:
113                        amount = getattr(certificate, 'school_fee_2', 0.0)
114            else:
115                if student.state == CLEARED:
116                    if student.is_foreigner:
117                        amount = getattr(certificate, 'school_fee_3', 0.0)
118                    else:
119                        amount = getattr(certificate, 'school_fee_1', 0.0)
120                elif student.state == RETURNING:
121                    # In case of returning school fee payment the payment session
122                    # and level contain the values of the session the student
123                    # has paid for.
124                    p_session, p_level = self.getReturningData(student)
125                    if student.is_foreigner:
126                        amount = getattr(certificate, 'school_fee_4', 0.0)
127                    else:
128                        amount = getattr(certificate, 'school_fee_2', 0.0)
129                    try:
130                        academic_session = grok.getSite()[
131                            'configuration'][str(p_session)]
132                    except KeyError:
133                        return _(u'Session configuration object is not available.'), None
134                elif student.is_postgrad and student.state == PAID:
135                    # Returning postgraduate students also pay for the next session
136                    # but their level always remains the same.
137                    p_session += 1
138                    if student.is_foreigner:
139                        amount = getattr(certificate, 'school_fee_4', 0.0)
140                    else:
141                        amount = getattr(certificate, 'school_fee_2', 0.0)
142                    try:
143                        academic_session = grok.getSite()[
144                            'configuration'][str(p_session)]
145                    except KeyError:
146                        return _(u'Session configuration object is not available.'), None
147            # Give 50% school fee discount to staff members.
148            if student.is_staff:
149                amount /= 2
150        if amount in (0.0, None):
151            return _('Amount could not be determined.' +
152                     ' Would you like to pay for a previous session?'), None
153        # Add session specific penalty fee.
154        if category == 'schoolfee' and student.is_postgrad:
155            amount += academic_session.penalty_pg
156        elif category == 'schoolfee':
157            amount += academic_session.penalty_ug
158        # Create ticket.
159        for key in student['payments'].keys():
160            ticket = student['payments'][key]
161            if ticket.p_state == 'paid' and\
162               ticket.p_category == category and \
163               ticket.p_item == p_item and \
164               ticket.p_session == p_session:
165                  return _('This type of payment has already been made.' +
166                           ' Would you like to pay for a previous session?'), None
167        payment = createObject(u'waeup.StudentOnlinePayment')
168        timestamp = ("%d" % int(time()*10000))[1:]
169        payment.p_id = "p%s" % timestamp
170        payment.p_category = category
171        payment.p_item = p_item
172        payment.p_session = p_session
173        payment.p_level = p_level
174        payment.p_current = p_current
175        payment.amount_auth = amount
176        return None, payment
177
178    # Uniben prefix
179    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.