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

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

Customize verdicts.

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1## $Id: utils.py 10656 2013-09-27 09:52:51Z 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    VERDICTS_DICT = {
32        '0': 'not yet',
33        'A': 'Successful student',
34        'B': 'Student with carryover courses',
35        'C': 'Student on probation',
36        #'D': 'Withdrawn from the faculty',
37        #'E': 'Student who were previously on probation',
38        #'F': 'Medical case',
39        #'G': 'Absent from examination',
40        #'H': 'Withheld results',
41        #'I': 'Expelled/rusticated/suspended student',
42        #'J': 'Temporary withdrawn from the university',
43        #'K': 'Unregistered student',
44        #'L': 'Referred student',
45        #'M': 'Reinstatement',
46        #'N': 'Student on transfer',
47        #'O': 'NCE-III repeater',
48        #'Y': 'No previous verdict',
49        #'X': 'New 300 level student',
50        'Z': 'Successful student (provisional)',
51        #'A1': 'First Class',
52        #'A2': 'Second Class Upper',
53        #'A3': 'Second Class Lower',
54        #'A4': 'Third Class',
55        #'A5': 'Pass',
56        #'A6': 'Distinction',
57        #'A7': 'Credit',
58        #'A8': 'Merit',
59        'NEOR': 'No evidence of registration',
60        'NEOV': 'No evidence of verification',
61        'FRNS': 'Faculty requirements not satisfied',
62        }
63
64    gpa_boundaries = ((1, 'FRNS'),
65                      (1.5, 'Pass'),
66                      (2.4, '3rd Class Honours'),
67                      (3.5, '2nd Class Honours Lower Division'),
68                      (4.5, '2nd Class Honours Upper Division'),
69                      (5, '1st Class Honours'))
70
71    def getReturningData(self, student):
72        """ This method defines what happens after school fee payment
73        of returning students depending on the student's senate verdict.
74        """
75        prev_level = student['studycourse'].current_level
76        cur_verdict = student['studycourse'].current_verdict
77        if cur_verdict in ('A','B','L','M','N','Z',):
78            # Successful student
79            new_level = divmod(int(prev_level),100)[0]*100 + 100
80        elif cur_verdict == 'C':
81            # Student on probation
82            new_level = int(prev_level) + 10
83        else:
84            # Student is somehow in an undefined state.
85            # Level has to be set manually.
86            new_level = prev_level
87        new_session = student['studycourse'].current_session + 1
88        return new_session, new_level
89
90    def setPaymentDetails(self, category, student,
91            previous_session=None, previous_level=None):
92        """Create Payment object and set the payment data of a student for
93        the payment category specified.
94
95        """
96        details = {}
97        p_item = u''
98        amount = 0.0
99        error = u''
100        if previous_session:
101            return _('Previous session payment not yet implemented.'), None
102        p_session = student['studycourse'].current_session
103        p_level = student['studycourse'].current_level
104        p_current = True
105        academic_session = self._getSessionConfiguration(p_session)
106        if academic_session == None:
107            return _(u'Session configuration object is not available.'), None
108        # Determine fee.
109        if category == 'transfer':
110            amount = academic_session.transfer_fee
111        elif category == 'transcript':
112            amount = academic_session.transcript_fee
113        elif category == 'gown':
114            amount = academic_session.gown_fee
115        elif category == 'bed_allocation':
116            amount = academic_session.booking_fee
117        elif category == 'hostel_maintenance':
118            amount = academic_session.maint_fee
119        elif category == 'clearance':
120            amount = academic_session.clearance_fee
121            p_item = student['studycourse'].certificate.code
122        elif category == 'schoolfee':
123            try:
124                certificate = student['studycourse'].certificate
125                p_item = certificate.code
126            except (AttributeError, TypeError):
127                return _('Study course data are incomplete.'), None
128            if student.state == CLEARED:
129                amount = academic_session.school_fee
130            elif student.state == RETURNING or\
131                (student.is_postgrad and student.state == PAID):
132                academic_session = self._getSessionConfiguration(p_session)
133                if academic_session == None:
134                    return _(u'Session configuration object is not available.'), None
135                if student.state == RETURNING:
136                    p_session, p_level = self.getReturningData(student)
137                else:
138                    # Returning postgraduate students also pay for the
139                    # next session but their level always remains the same.
140                    p_session += 1
141                try:
142                    academic_session = grok.getSite()[
143                        'configuration'][str(p_session)]
144                except KeyError:
145                    return _(u'Session configuration object is not available.'), None
146                amount = academic_session.school_fee
147            else:
148                return _('Wrong state.'), None
149        if amount in (0.0, None):
150            return _(u'Amount could not be determined.'), None
151        # Add session specific penalty fee.
152        if category == 'schoolfee' and student.is_postgrad:
153            amount += academic_session.penalty_pg
154        elif category == 'schoolfee':
155            amount += academic_session.penalty_ug
156        # Create ticket.
157        for key in student['payments'].keys():
158            ticket = student['payments'][key]
159            if ticket.p_state == 'paid' and\
160               ticket.p_category == category and \
161               ticket.p_item == p_item and \
162               ticket.p_session == p_session:
163                  return _('This type of payment has already been made.'), None
164        payment = createObject(u'waeup.StudentOnlinePayment')
165        timestamp = ("%d" % int(time()*10000))[1:]
166        payment.p_id = "p%s" % timestamp
167        payment.p_category = category
168        payment.p_item = p_item
169        payment.p_session = p_session
170        payment.p_level = p_level
171        payment.p_current = p_current
172        payment.amount_auth = amount
173        return None, payment
174
175    def maxCredits(self, studylevel):
176        """Return maximum credits.
177
178        """
179        return 48
180
181    # AAUE prefix
182    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.