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

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

Customize maxCredits.

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1## $Id: utils.py 10051 2013-03-28 17:03:36Z 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 kofacustom.nigeria.students.utils import NigeriaStudentsUtils
23from waeup.kofa.accesscodes import create_accesscode
24from waeup.aaue.interfaces import MessageFactory as _
25
26class CustomStudentsUtils(NigeriaStudentsUtils):
27    """A collection of customized methods.
28
29    """
30
31    def getReturningData(self, student):
32        """ This method defines what happens after school fee payment
33        of returning students depending on the student's senate verdict.
34        """
35        prev_level = student['studycourse'].current_level
36        cur_verdict = student['studycourse'].current_verdict
37        if cur_verdict in ('A','B','L','M','N','Z',):
38            # Successful student
39            new_level = divmod(int(prev_level),100)[0]*100 + 100
40        elif cur_verdict == 'C':
41            # Student on probation
42            new_level = int(prev_level) + 10
43        else:
44            # Student is somehow in an undefined state.
45            # Level has to be set manually.
46            new_level = prev_level
47        new_session = student['studycourse'].current_session + 1
48        return new_session, new_level
49
50    def setPaymentDetails(self, category, student,
51            previous_session=None, previous_level=None):
52        """Create Payment object and set the payment data of a student for
53        the payment category specified.
54
55        """
56        details = {}
57        p_item = u''
58        amount = 0.0
59        error = u''
60        if previous_session:
61            return _('Previous session payment not yet implemented.'), None
62        p_session = student['studycourse'].current_session
63        p_level = student['studycourse'].current_level
64        p_current = True
65        academic_session = self._getSessionConfiguration(p_session)
66        if academic_session == None:
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            amount = academic_session.clearance_fee
79            p_item = student['studycourse'].certificate.code
80        elif category == 'schoolfee':
81            try:
82                certificate = student['studycourse'].certificate
83                p_item = certificate.code
84            except (AttributeError, TypeError):
85                return _('Study course data are incomplete.'), None
86            if student.state == CLEARED:
87                amount = academic_session.school_fee
88            elif student.state == RETURNING or\
89                (student.is_postgrad and student.state == PAID):
90                academic_session = self._getSessionConfiguration(p_session)
91                if academic_session == None:
92                    return _(u'Session configuration object is not available.'), None
93                if student.state == RETURNING:
94                    p_session, p_level = self.getReturningData(student)
95                else:
96                    # Returning postgraduate students also pay for the
97                    # next session but their level always remains the same.
98                    p_session += 1
99                try:
100                    academic_session = grok.getSite()[
101                        'configuration'][str(p_session)]
102                except KeyError:
103                    return _(u'Session configuration object is not available.'), None
104                amount = academic_session.school_fee
105            else:
106                return _('Wrong state.'), None
107        if amount in (0.0, None):
108            return _(u'Amount could not be determined.'), None
109        # Add session specific penalty fee.
110        if category == 'schoolfee' and student.is_postgrad:
111            amount += academic_session.penalty_pg
112        elif category == 'schoolfee':
113            amount += academic_session.penalty_ug
114        # Create ticket.
115        for key in student['payments'].keys():
116            ticket = student['payments'][key]
117            if ticket.p_state == 'paid' and\
118               ticket.p_category == category and \
119               ticket.p_item == p_item and \
120               ticket.p_session == p_session:
121                  return _('This type of payment has already been made.'), None
122        payment = createObject(u'waeup.StudentOnlinePayment')
123        timestamp = ("%d" % int(time()*10000))[1:]
124        payment.p_id = "p%s" % timestamp
125        payment.p_category = category
126        payment.p_item = p_item
127        payment.p_session = p_session
128        payment.p_level = p_level
129        payment.p_current = p_current
130        payment.amount_auth = amount
131        return None, payment
132
133    def maxCredits(self, studylevel):
134        """Return maximum credits.
135
136        """
137        return 48
138
139    # AAUE prefix
140    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.