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

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

In Uniben we have special pg students which follow the ug workflow.

See ticket 838:

Whereas the full time LLM students are to register all the four courses once, the part time LLM students are only permitted to register any two of the four courses in their first year and the remaining two courses including any carryover in the second or third year. Presently they do not have any problem with full time LLM online course registration but they certainly are not happy with the way LLM part time students are registering their cousres online as if they are full time students.

  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1## $Id: utils.py 9251 2012-09-28 06:22:59Z 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.uniben.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, previous_level):
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            p_session = previous_session
62            p_level = previous_level
63            p_current = False
64        else:
65            p_session = student['studycourse'].current_session
66            p_level = student['studycourse'].current_level
67            p_current = True
68        session = str(p_session)
69        try:
70            academic_session = grok.getSite()['configuration'][session]
71        except KeyError:
72            return _(u'Session configuration object is not available.'), None
73        # Determine fee.
74        if category == 'transfer':
75            amount = academic_session.transfer_fee
76        elif category == 'gown':
77            amount = academic_session.gown_fee
78        elif category == 'bed_allocation':
79            amount = academic_session.booking_fee
80        elif category == 'hostel_maintenance':
81            amount = academic_session.maint_fee
82        elif category == 'clearance':
83            try:
84                p_item = student['studycourse'].certificate.code
85            except (AttributeError, TypeError):
86                return _('Study course data are incomplete.'), None
87            if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
88                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
89                amount = 17250.0
90            else:
91                amount = 34250.0
92        elif category == 'schoolfee':
93            try:
94                certificate = student['studycourse'].certificate
95                p_item = certificate.code
96            except (AttributeError, TypeError):
97                return _('Study course data are incomplete.'), None
98            if previous_session:
99                if previous_session < student['studycourse'].entry_session:
100                    return _('The previous session must not fall below '
101                             'your entry session.'), None
102                if previous_session > student['studycourse'].current_session - 1:
103                    return _('This is not a previous session.'), None
104                if previous_session == student['studycourse'].entry_session:
105                    if student.is_foreigner:
106                        amount = getattr(certificate, 'school_fee_3', 0.0)
107                    else:
108                        amount = getattr(certificate, 'school_fee_1', 0.0)
109                else:
110                    if student.is_foreigner:
111                        amount = getattr(certificate, 'school_fee_4', 0.0)
112                    else:
113                        amount = getattr(certificate, 'school_fee_2', 0.0)
114            else:
115                if student.state == CLEARED:
116                    if student.is_foreigner:
117                        amount = getattr(certificate, 'school_fee_3', 0.0)
118                    else:
119                        amount = getattr(certificate, 'school_fee_1', 0.0)
120                elif student.state == RETURNING:
121                    # In case of returning school fee payment the payment session
122                    # and level contain the values of the session the student
123                    # has paid for.
124                    p_session, p_level = self.getReturningData(student)
125                    if student.is_foreigner:
126                        amount = getattr(certificate, 'school_fee_4', 0.0)
127                    else:
128                        amount = getattr(certificate, 'school_fee_2', 0.0)
129                    try:
130                        academic_session = grok.getSite()[
131                            'configuration'][str(p_session)]
132                    except KeyError:
133                        return _(u'Session configuration object is not available.'), None
134                elif student.state == PAID  and student.is_postgrad and \
135                    not student.is_special_postgrad:
136                    # Regular returning postgraduate students also pay
137                    # for the next session but their level always remains the same.
138                    p_session += 1
139                    if student.is_foreigner:
140                        amount = getattr(certificate, 'school_fee_4', 0.0)
141                    else:
142                        amount = getattr(certificate, 'school_fee_2', 0.0)
143                    try:
144                        academic_session = grok.getSite()[
145                            'configuration'][str(p_session)]
146                    except KeyError:
147                        return _(u'Session configuration object is not available.'), None
148            # Give 50% school fee discount to staff members.
149            if student.is_staff:
150                amount /= 2
151        if amount in (0.0, None):
152            return _('Amount could not be determined.' +
153                     ' Would you like to pay for a previous session?'), None
154        # Add session specific penalty fee.
155        if category == 'schoolfee' and student.is_postgrad:
156            amount += academic_session.penalty_pg
157        elif category == 'schoolfee':
158            amount += academic_session.penalty_ug
159        # Create ticket.
160        for key in student['payments'].keys():
161            ticket = student['payments'][key]
162            if ticket.p_state == 'paid' and\
163               ticket.p_category == category and \
164               ticket.p_item == p_item and \
165               ticket.p_session == p_session:
166                  return _('This type of payment has already been made.' +
167                           ' Would you like to pay for a previous session?'), None
168        payment = createObject(u'waeup.StudentOnlinePayment')
169        timestamp = ("%d" % int(time()*10000))[1:]
170        payment.p_id = "p%s" % timestamp
171        payment.p_category = category
172        payment.p_item = p_item
173        payment.p_session = p_session
174        payment.p_level = p_level
175        payment.p_current = p_current
176        payment.amount_auth = amount
177        return None, payment
178
179    # Uniben prefix
180    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.