source: main/waeup.futminna/trunk/src/waeup/futminna/students/utils.py @ 8705

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

See waeup.uniben.

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