source: main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py @ 8746

Last change on this file since 8746 was 8715, checked in by Henrik Bettermann, 13 years ago

See previous revision in waeup.aaue.

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: utils.py 8715 2012-06-14 05:38: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 CLEARED, RETURNING, PAID
22from waeup.kofa.students.utils import StudentsUtils
23from waeup.kofa.students.interfaces import IStudentsUtils
24from waeup.kofa.accesscodes import create_accesscode
25from waeup.uniben.interfaces import MessageFactory as _
26
27class CustomStudentsUtils(StudentsUtils):
28    """A collection of customized methods.
29
30    """
31    grok.implements(IStudentsUtils)
32
33    def getReturningData(self, student):
34        """ This method defines what happens after school fee payment
35        of returning students depending on the student's senate verdict.
36        """
37        prev_level = student['studycourse'].current_level
38        cur_verdict = student['studycourse'].current_verdict
39        if cur_verdict in ('A','B','L','M','N','Z',):
40            # Successful student
41            new_level = divmod(int(prev_level),100)[0]*100 + 100
42        elif cur_verdict == 'C':
43            # Student on probation
44            new_level = int(prev_level) + 10
45        else:
46            # Student is somehow in an undefined state.
47            # Level has to be set manually.
48            new_level = prev_level
49        new_session = student['studycourse'].current_session + 1
50        return new_session, new_level
51
52    def setPaymentDetails(self, category, student):
53        """Create Payment object and set the payment data of a student for
54        the payment category specified.
55
56        """
57        details = {}
58        p_item = u''
59        amount = 0.0
60        error = u''
61        p_session = student['studycourse'].current_session
62        p_level = student['studycourse'].current_level
63        session = str(p_session)
64        try:
65            academic_session = grok.getSite()['configuration'][session]
66        except KeyError:
67            return _(u'Session configuration object is not available.'), None
68        # Determine fee.
69        if category == 'transfer':
70            amount = academic_session.transfer_fee
71        elif category == 'gown':
72            amount = academic_session.gown_fee
73        elif category == 'bed_allocation':
74            amount = academic_session.booking_fee
75        elif category == 'hostel_maintenance':
76            amount = academic_session.maint_fee
77        elif category == 'clearance':
78            try:
79                p_item = student['studycourse'].certificate.code
80            except (AttributeError, TypeError):
81                return _('Study course data are incomplete.'), None
82            if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
83                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
84                amount = 17250.0
85            else:
86                amount = 34250.0
87        elif category == 'schoolfee':
88            try:
89                certificate = student['studycourse'].certificate
90                p_item = certificate.code
91            except (AttributeError, TypeError):
92                return _('Study course data are incomplete.'), None
93            if student.state == CLEARED:
94                amount = getattr(certificate, 'school_fee_1', 0.0)
95            elif student.state == RETURNING:
96                # In case of returning school fee payment the payment session
97                # and level contain the values of the session the student
98                # has paid for.
99                p_session, p_level = self.getReturningData(student)
100                amount = getattr(certificate, 'school_fee_2', 0.0)
101            elif student.is_postgrad and student.state == PAID:
102                # Returning postgraduate students also pay for the next session
103                # but their level always remains the same.
104                p_session += 1
105                amount = getattr(certificate, 'school_fee_2', 0.0)
106        if amount in (0.0, None):
107            return _(u'Amount could not be determined.'), None
108        # Add session specific penalty fee.
109        if category == 'schoolfee' and student.is_postgrad:
110            amount += academic_session.penalty_pg
111        elif category == 'schoolfee':
112            amount += academic_session.penalty_ug
113        # Create ticket.
114        for key in student['payments'].keys():
115            ticket = student['payments'][key]
116            if ticket.p_state == 'paid' and\
117               ticket.p_category == category and \
118               ticket.p_item == p_item and \
119               ticket.p_session == p_session:
120                  return _('This type of payment has already been made.'), None
121        payment = createObject(u'waeup.StudentOnlinePayment')
122        timestamp = "%d" % int(time()*1000)
123        payment.p_id = "p%s" % timestamp
124        payment.p_category = category
125        payment.p_item = p_item
126        payment.p_session = p_session
127        payment.p_level = p_level
128        payment.amount_auth = amount
129        return None, payment
130
131    VERDICTS_DICT = {
132        'NY': 'not yet',
133        'A': 'Successful student',
134        'B': 'Student with carryover courses',
135        'C': 'Student on probation',
136        'D': 'Withdrawn from the faculty',
137        'E': 'Student who were previously on probation',
138        'F': 'Medical case',
139        'G': 'Absent from examination',
140        'H': 'Withheld results',
141        'I': 'Expelled/rusticated/suspended student',
142        'J': 'Temporary withdrawn from the university',
143        'K': 'Unregistered student',
144        'L': 'Referred student',
145        'M': 'Reinstatement',
146        'N': 'Student on transfer',
147        'O': 'NCE-III repeater',
148        'Y': 'No previous verdict',
149        'X': 'New 300 level student',
150        'Z': 'Successful student (provisional)',
151        'A1': 'First Class',
152        'A2': 'Second Class Upper',
153        'A3': 'Second Class Lower',
154        'A4': 'Third Class',
155        'A5': 'Pass',
156        'A6': 'Distinction',
157        'A7': 'Credit',
158        'A8': 'Merit',
159        }
160
161    # Uniben separators
162    SEPARATORS_DICT = {
163        'form.fst_sit_fname': _(u'First Sitting Record'),
164        'form.scd_sit_fname': _(u'Second Sitting Record'),
165        'form.alr_fname': _(u'Advanced Level Record'),
166        'form.hq_type': _(u'Higher Education Record'),
167        'form.hq2_type': _(u'Second Higher Education Record'),
168        'form.nysc_year': _(u'NYSC Information'),
169        'form.employer': _(u'Employment History'),
170        'form.former_matric': _(u'Former Uniben Student'),
171        }
172
173    # Uniben prefix
174    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.