source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/utils.py @ 8794

Last change on this file since 8794 was 8713, checked in by Henrik Bettermann, 12 years ago

See previous revision in waeup.aaue.

  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1## $Id: utils.py 8713 2012-06-14 05:36:19Z 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.fceokene.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        if category == 'transfer':
69            amount = academic_session.transfer_fee
70        elif category == 'gown':
71            amount = academic_session.gown_fee
72        elif category == 'bed_allocation':
73            amount = academic_session.booking_fee
74        elif category == 'hostel_maintenance':
75            amount = academic_session.maint_fee
76        elif category == 'clearance':
77            try:
78                p_item = student['studycourse'].certificate.code
79            except (AttributeError, TypeError):
80                return _('Study course data are incomplete.'), None
81            if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
82                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
83                amount = 17250.0
84            else:
85                amount = 34250.0
86        elif category == 'schoolfee':
87            try:
88                certificate = student['studycourse'].certificate
89                p_item = certificate.code
90            except (AttributeError, TypeError):
91                return _('Study course data are incomplete.'), None
92            if student.state == CLEARED:
93                amount = getattr(certificate, 'school_fee_1', 0.0)
94            elif student.state == RETURNING:
95                # In case of returning school fee payment the payment session
96                # and level contain the values of the session the student
97                # has paid for.
98                p_session, p_level = self.getReturningData(student)
99                amount = getattr(certificate, 'school_fee_2', 0.0)
100            elif student.is_postgrad and student.state == PAID:
101                # Returning postgraduate students also pay for the next session
102                # but their level always remains the same.
103                p_session += 1
104                amount = getattr(certificate, 'school_fee_2', 0.0)
105        if amount in (0.0, None):
106            return _(u'Amount could not be determined.'), None
107        for key in student['payments'].keys():
108            ticket = student['payments'][key]
109            if ticket.p_state == 'paid' and\
110               ticket.p_category == category and \
111               ticket.p_item == p_item and \
112               ticket.p_session == p_session:
113                  return _('This type of payment has already been made.'), None
114        payment = createObject(u'waeup.StudentOnlinePayment')
115        timestamp = "%d" % int(time()*1000)
116        payment.p_id = "p%s" % timestamp
117        payment.p_category = category
118        payment.p_item = p_item
119        payment.p_session = p_session
120        payment.p_level = p_level
121        payment.amount_auth = amount
122        return None, payment
123
124    VERDICTS_DICT = {
125        'NY': 'not yet',
126        'A': 'Successful student',
127        'B': 'Student with carryover courses',
128        'C': 'Student on probation',
129        'D': 'Withdrawn from the faculty',
130        'E': 'Student who were previously on probation',
131        'F': 'Medical case',
132        'G': 'Absent from examination',
133        'H': 'Withheld results',
134        'I': 'Expelled/rusticated/suspended student',
135        'J': 'Temporary withdrawn from the university',
136        'K': 'Unregistered student',
137        'L': 'Referred student',
138        'M': 'Reinstatement',
139        'N': 'Student on transfer',
140        'O': 'NCE-III repeater',
141        'Y': 'No previous verdict',
142        'X': 'New 300 level student',
143        'Z': 'Successful student (provisional)',
144        'A1': 'First Class',
145        'A2': 'Second Class Upper',
146        'A3': 'Second Class Lower',
147        'A4': 'Third Class',
148        'A5': 'Pass',
149        'A6': 'Distinction',
150        'A7': 'Credit',
151        'A8': 'Merit',
152        }
153
154    # FCEOkene separators
155    SEPARATORS_DICT = {
156        'form.fst_sit_fname': _(u'First Sitting Record'),
157        'form.scd_sit_fname': _(u'Second Sitting Record'),
158        'form.alr_fname': _(u'Advanced Level Record'),
159        'form.hq_type': _(u'Higher Education Record'),
160        'form.hq2_type': _(u'Second Higher Education Record'),
161        'form.nysc_year': _(u'NYSC Information'),
162        'form.employer': _(u'Employment History'),
163        'form.former_matric': _(u'Former FCEOkene Student'),
164        }
165
166    # FCEOkene prefix
167    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.