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

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

Customize verdicts.

  • Property svn:keywords set to Id
File size: 7.4 KB
RevLine 
[7419]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##
[7151]18import grok
[8600]19from time import time
20from zope.component import createObject
[8474]21from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
[8823]22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]23from waeup.kofa.accesscodes import create_accesscode
[8444]24from waeup.aaue.interfaces import MessageFactory as _
[6902]25
[8823]26class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]27    """A collection of customized methods.
28
29    """
30
[10656]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
[10641]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
[8270]71    def getReturningData(self, student):
72        """ This method defines what happens after school fee payment
[8319]73        of returning students depending on the student's senate verdict.
[8270]74        """
[8319]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
[8270]87        new_session = student['studycourse'].current_session + 1
88        return new_session, new_level
89
[9154]90    def setPaymentDetails(self, category, student,
91            previous_session=None, previous_level=None):
[8600]92        """Create Payment object and set the payment data of a student for
93        the payment category specified.
94
95        """
[8306]96        details = {}
[8600]97        p_item = u''
98        amount = 0.0
99        error = u''
[9154]100        if previous_session:
101            return _('Previous session payment not yet implemented.'), None
[8600]102        p_session = student['studycourse'].current_session
103        p_level = student['studycourse'].current_level
[9154]104        p_current = True
[9527]105        academic_session = self._getSessionConfiguration(p_session)
106        if academic_session == None:
[8600]107            return _(u'Session configuration object is not available.'), None
[8677]108        # Determine fee.
[7151]109        if category == 'transfer':
[8600]110            amount = academic_session.transfer_fee
[10467]111        elif category == 'transcript':
112            amount = academic_session.transcript_fee
[7151]113        elif category == 'gown':
[8600]114            amount = academic_session.gown_fee
[7151]115        elif category == 'bed_allocation':
[8600]116            amount = academic_session.booking_fee
[7151]117        elif category == 'hostel_maintenance':
[8600]118            amount = academic_session.maint_fee
[7151]119        elif category == 'clearance':
[8753]120            amount = academic_session.clearance_fee
121            p_item = student['studycourse'].certificate.code
[9905]122        elif category == 'schoolfee':
[8600]123            try:
[8753]124                certificate = student['studycourse'].certificate
125                p_item = certificate.code
[8600]126            except (AttributeError, TypeError):
127                return _('Study course data are incomplete.'), None
[8753]128            if student.state == CLEARED:
[9905]129                amount = academic_session.school_fee
[8961]130            elif student.state == RETURNING or\
131                (student.is_postgrad and student.state == PAID):
[9527]132                academic_session = self._getSessionConfiguration(p_session)
133                if academic_session == None:
134                    return _(u'Session configuration object is not available.'), None
[8961]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
[9905]146                amount = academic_session.school_fee
[8600]147            else:
[8753]148                return _('Wrong state.'), None
[8600]149        if amount in (0.0, None):
150            return _(u'Amount could not be determined.'), None
[8677]151        # Add session specific penalty fee.
[9905]152        if category == 'schoolfee' and student.is_postgrad:
[8677]153            amount += academic_session.penalty_pg
[9905]154        elif category == 'schoolfee':
[8677]155            amount += academic_session.penalty_ug
156        # Create ticket.
[8600]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
[8712]164        payment = createObject(u'waeup.StudentOnlinePayment')
[8954]165        timestamp = ("%d" % int(time()*10000))[1:]
[8600]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
[9154]171        payment.p_current = p_current
[8600]172        payment.amount_auth = amount
173        return None, payment
[7621]174
[10051]175    def maxCredits(self, studylevel):
176        """Return maximum credits.
177
178        """
179        return 48
180
[8444]181    # AAUE prefix
182    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.