source: main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py @ 10641

Last change on this file since 10641 was 10641, checked in by Henrik Bettermann, 11 years ago

Change gpa boundary names.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: utils.py 10641 2013-09-23 08:12:39Z 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.aaue.interfaces import MessageFactory as _
25
26class CustomStudentsUtils(NigeriaStudentsUtils):
27    """A collection of customized methods.
28
29    """
30
31    gpa_boundaries = ((1, 'FRNS'),
32                      (1.5, 'Pass'),
33                      (2.4, '3rd Class Honours'),
34                      (3.5, '2nd Class Honours Lower Division'),
35                      (4.5, '2nd Class Honours Upper Division'),
36                      (5, '1st Class Honours'))
37
38    def getReturningData(self, student):
39        """ This method defines what happens after school fee payment
40        of returning students depending on the student's senate verdict.
41        """
42        prev_level = student['studycourse'].current_level
43        cur_verdict = student['studycourse'].current_verdict
44        if cur_verdict in ('A','B','L','M','N','Z',):
45            # Successful student
46            new_level = divmod(int(prev_level),100)[0]*100 + 100
47        elif cur_verdict == 'C':
48            # Student on probation
49            new_level = int(prev_level) + 10
50        else:
51            # Student is somehow in an undefined state.
52            # Level has to be set manually.
53            new_level = prev_level
54        new_session = student['studycourse'].current_session + 1
55        return new_session, new_level
56
57    def setPaymentDetails(self, category, student,
58            previous_session=None, previous_level=None):
59        """Create Payment object and set the payment data of a student for
60        the payment category specified.
61
62        """
63        details = {}
64        p_item = u''
65        amount = 0.0
66        error = u''
67        if previous_session:
68            return _('Previous session payment not yet implemented.'), None
69        p_session = student['studycourse'].current_session
70        p_level = student['studycourse'].current_level
71        p_current = True
72        academic_session = self._getSessionConfiguration(p_session)
73        if academic_session == None:
74            return _(u'Session configuration object is not available.'), None
75        # Determine fee.
76        if category == 'transfer':
77            amount = academic_session.transfer_fee
78        elif category == 'transcript':
79            amount = academic_session.transcript_fee
80        elif category == 'gown':
81            amount = academic_session.gown_fee
82        elif category == 'bed_allocation':
83            amount = academic_session.booking_fee
84        elif category == 'hostel_maintenance':
85            amount = academic_session.maint_fee
86        elif category == 'clearance':
87            amount = academic_session.clearance_fee
88            p_item = student['studycourse'].certificate.code
89        elif category == 'schoolfee':
90            try:
91                certificate = student['studycourse'].certificate
92                p_item = certificate.code
93            except (AttributeError, TypeError):
94                return _('Study course data are incomplete.'), None
95            if student.state == CLEARED:
96                amount = academic_session.school_fee
97            elif student.state == RETURNING or\
98                (student.is_postgrad and student.state == PAID):
99                academic_session = self._getSessionConfiguration(p_session)
100                if academic_session == None:
101                    return _(u'Session configuration object is not available.'), None
102                if student.state == RETURNING:
103                    p_session, p_level = self.getReturningData(student)
104                else:
105                    # Returning postgraduate students also pay for the
106                    # next session but their level always remains the same.
107                    p_session += 1
108                try:
109                    academic_session = grok.getSite()[
110                        'configuration'][str(p_session)]
111                except KeyError:
112                    return _(u'Session configuration object is not available.'), None
113                amount = academic_session.school_fee
114            else:
115                return _('Wrong state.'), None
116        if amount in (0.0, None):
117            return _(u'Amount could not be determined.'), None
118        # Add session specific penalty fee.
119        if category == 'schoolfee' and student.is_postgrad:
120            amount += academic_session.penalty_pg
121        elif category == 'schoolfee':
122            amount += academic_session.penalty_ug
123        # Create ticket.
124        for key in student['payments'].keys():
125            ticket = student['payments'][key]
126            if ticket.p_state == 'paid' and\
127               ticket.p_category == category and \
128               ticket.p_item == p_item and \
129               ticket.p_session == p_session:
130                  return _('This type of payment has already been made.'), None
131        payment = createObject(u'waeup.StudentOnlinePayment')
132        timestamp = ("%d" % int(time()*10000))[1:]
133        payment.p_id = "p%s" % timestamp
134        payment.p_category = category
135        payment.p_item = p_item
136        payment.p_session = p_session
137        payment.p_level = p_level
138        payment.p_current = p_current
139        payment.amount_auth = amount
140        return None, payment
141
142    def maxCredits(self, studylevel):
143        """Return maximum credits.
144
145        """
146        return 48
147
148    # AAUE prefix
149    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.