source: main/waeup.aaue/branches/0.1/src/waeup/aaue/students/utils.py @ 14292

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

Add late registration payment category.

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