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

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

Reorganize tests.

Further adjust constructMatricNumber (see ticket).

  • Property svn:keywords set to Id
File size: 9.1 KB
Line 
1## $Id: utils.py 11596 2014-04-23 09:46:18Z 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 constructMatricNumber(self, student):
74        next_integer = grok.getSite()['configuration'].next_matric_integer
75        if next_integer == 0:
76            return None
77        faccode = student.faccode
78        depcode = student.depcode
79        year = unicode(student.entry_session)[2:]
80        if student.current_mode in ('ug_pt', 'de_pt'):
81            return "PTP/%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
82        #if student.current_mode in ('pg_ft', 'pg_pt'):
83        #    return "SPS/%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
84        #if student.current_mode in ('dp_ft', 'dp_pt'):
85        #    return "DIP/%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
86        #if student.current_mode == 'found':
87        #    return None
88        #return "%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
89        return None
90
91    def getReturningData(self, student):
92        """ This method defines what happens after school fee payment
93        of returning students depending on the student's senate verdict.
94        """
95        prev_level = student['studycourse'].current_level
96        cur_verdict = student['studycourse'].current_verdict
97        if cur_verdict in ('A','B','L','M','N','Z',):
98            # Successful student
99            new_level = divmod(int(prev_level),100)[0]*100 + 100
100        elif cur_verdict == 'C':
101            # Student on probation
102            new_level = int(prev_level) + 10
103        else:
104            # Student is somehow in an undefined state.
105            # Level has to be set manually.
106            new_level = prev_level
107        new_session = student['studycourse'].current_session + 1
108        return new_session, new_level
109
110    def setPaymentDetails(self, category, student,
111            previous_session=None, previous_level=None):
112        """Create Payment object and set the payment data of a student for
113        the payment category specified.
114
115        """
116        details = {}
117        p_item = u''
118        amount = 0.0
119        error = u''
120        if previous_session:
121            return _('Previous session payment not yet implemented.'), None
122        p_session = student['studycourse'].current_session
123        p_level = student['studycourse'].current_level
124        p_current = True
125        academic_session = self._getSessionConfiguration(p_session)
126        if academic_session == None:
127            return _(u'Session configuration object is not available.'), None
128        # Determine fee.
129        if category == 'transfer':
130            amount = academic_session.transfer_fee
131        elif category == 'transcript':
132            amount = academic_session.transcript_fee
133        elif category == 'gown':
134            amount = academic_session.gown_fee
135        elif category == 'bed_allocation':
136            amount = academic_session.booking_fee
137        elif category == 'hostel_maintenance':
138            amount = academic_session.maint_fee
139        elif category == 'clearance':
140            amount = academic_session.clearance_fee
141            p_item = student['studycourse'].certificate.code
142        elif category == 'late_registration':
143            amount = academic_session.late_fee
144        elif category == 'schoolfee':
145            try:
146                certificate = student['studycourse'].certificate
147                p_item = certificate.code
148            except (AttributeError, TypeError):
149                return _('Study course data are incomplete.'), None
150            if student.state == CLEARED:
151                if student.faccode == 'FP':
152                    amount = 84000.0
153                else:
154                    amount = academic_session.school_fee
155            elif student.state == RETURNING or\
156                (student.is_postgrad and student.state == PAID):
157                academic_session = self._getSessionConfiguration(p_session)
158                if academic_session == None:
159                    return _(u'Session configuration object is not available.'), None
160                if student.state == RETURNING:
161                    p_session, p_level = self.getReturningData(student)
162                else:
163                    # Returning postgraduate students also pay for the
164                    # next session but their level always remains the same.
165                    p_session += 1
166                try:
167                    academic_session = grok.getSite()[
168                        'configuration'][str(p_session)]
169                except KeyError:
170                    return _(u'Session configuration object is not available.'), None
171                amount = academic_session.school_fee
172            else:
173                return _('Wrong state.'), None
174        if amount in (0.0, None):
175            return _(u'Amount could not be determined.'), None
176        # Add session specific penalty fee.
177        if category == 'schoolfee' and student.is_postgrad:
178            amount += academic_session.penalty_pg
179        elif category == 'schoolfee':
180            amount += academic_session.penalty_ug
181        # Create ticket.
182        for key in student['payments'].keys():
183            ticket = student['payments'][key]
184            if ticket.p_state == 'paid' and\
185               ticket.p_category == category and \
186               ticket.p_item == p_item and \
187               ticket.p_session == p_session:
188                  return _('This type of payment has already been made.'), None
189        if self._isPaymentDisabled(p_session, category, student):
190            return _('Payment temporarily disabled.'), None
191        payment = createObject(u'waeup.StudentOnlinePayment')
192        timestamp = ("%d" % int(time()*10000))[1:]
193        payment.p_id = "p%s" % timestamp
194        payment.p_category = category
195        payment.p_item = p_item
196        payment.p_session = p_session
197        payment.p_level = p_level
198        payment.p_current = p_current
199        payment.amount_auth = amount
200        return None, payment
201
202    def _admissionText(self, student, portal_language):
203        inst_name = grok.getSite()['configuration'].name
204        entry_session = student['studycourse'].entry_session
205        entry_session = academic_sessions_vocab.getTerm(entry_session).title
206        text = trans(_(
207            'This is to inform you that you have been offered provisional'
208            ' admission into ${a} for the ${b} academic session as follows:',
209            mapping = {'a': inst_name, 'b': entry_session}),
210            portal_language)
211        return text
212
213    def maxCredits(self, studylevel):
214        """Return maximum credits.
215
216        """
217        return 48
218
219    # AAUE prefix
220    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.