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

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

Implement school fee payment by two instalments. Instalment 1 replaces the original school fee payment, instalment 2 is an additional payment which can only be made if instalment 1 has been paid. Furthermore, instalment 1 can only be made if instalment 2 of the previous session has been paid (returning students only).

  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1## $Id: utils.py 8753 2012-06-18 17:00:00Z 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.aaue.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            amount = academic_session.clearance_fee
79            p_item = student['studycourse'].certificate.code
80        elif category == 'schoolfee_1':
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            payment_allowed = False
87            if student.state == CLEARED:
88                payment_allowed = True
89                amount = academic_session.school_fee_base
90            elif student.state == RETURNING:
91                p_session, p_level = self.getReturningData(student)
92                initial_instalment_made = False
93                for key in student['payments'].keys():
94                    ticket = student['payments'][key]
95                    if ticket.p_category == 'schoolfee_1':
96                        initial_instalment_made = True
97                    if ticket.p_state == 'paid' and\
98                       ticket.p_category == 'schoolfee_2' and \
99                       ticket.p_item == p_item and \
100                       ticket.p_session == p_session-1: #  = current session
101                       payment_allowed = True
102                if not initial_instalment_made:
103                    payment_allowed = True
104                amount = academic_session.school_fee_base
105            else:
106                return _('Wrong state.'), None
107            if not payment_allowed:
108                return _('The previous 2nd school fee instalment '
109                         'has not yet been paid.'), None
110        elif category == 'schoolfee_2':
111            try:
112                certificate = student['studycourse'].certificate
113                p_item = certificate.code
114            except (AttributeError, TypeError):
115                return _('Study course data are incomplete.'), None
116            payment_allowed = False
117            for key in student['payments'].keys():
118                ticket = student['payments'][key]
119                if ticket.p_state == 'paid' and\
120                   ticket.p_category == 'schoolfee_1' and \
121                   ticket.p_item == p_item and \
122                   ticket.p_session == p_session:
123                   payment_allowed = True
124            if not payment_allowed:
125                return _('The 1st school fee instalment '
126                         'has not yet been paid.'), None
127            amount = academic_session.school_fee_base
128        if amount in (0.0, None):
129            return _(u'Amount could not be determined.'), None
130        # Add session specific penalty fee.
131        if category == 'schoolfee_1' and student.is_postgrad:
132            amount += academic_session.penalty_pg
133        elif category == 'schoolfee_1':
134            amount += academic_session.penalty_ug
135        # Create ticket.
136        for key in student['payments'].keys():
137            ticket = student['payments'][key]
138            if ticket.p_state == 'paid' and\
139               ticket.p_category == category and \
140               ticket.p_item == p_item and \
141               ticket.p_session == p_session:
142                  return _('This type of payment has already been made.'), None
143        payment = createObject(u'waeup.StudentOnlinePayment')
144        timestamp = "%d" % int(time()*1000)
145        payment.p_id = "p%s" % timestamp
146        payment.p_category = category
147        payment.p_item = p_item
148        payment.p_session = p_session
149        payment.p_level = p_level
150        payment.amount_auth = amount
151        return None, payment
152
153    VERDICTS_DICT = {
154        'NY': 'not yet',
155        'A': 'Successful student',
156        'B': 'Student with carryover courses',
157        'C': 'Student on probation',
158        'D': 'Withdrawn from the faculty',
159        'E': 'Student who were previously on probation',
160        'F': 'Medical case',
161        'G': 'Absent from examination',
162        'H': 'Withheld results',
163        'I': 'Expelled/rusticated/suspended student',
164        'J': 'Temporary withdrawn from the university',
165        'K': 'Unregistered student',
166        'L': 'Referred student',
167        'M': 'Reinstatement',
168        'N': 'Student on transfer',
169        'O': 'NCE-III repeater',
170        'Y': 'No previous verdict',
171        'X': 'New 300 level student',
172        'Z': 'Successful student (provisional)',
173        'A1': 'First Class',
174        'A2': 'Second Class Upper',
175        'A3': 'Second Class Lower',
176        'A4': 'Third Class',
177        'A5': 'Pass',
178        'A6': 'Distinction',
179        'A7': 'Credit',
180        'A8': 'Merit',
181        }
182
183    # AAUE separators
184    SEPARATORS_DICT = {
185        'form.fst_sit_fname': _(u'First Sitting Record'),
186        'form.scd_sit_fname': _(u'Second Sitting Record'),
187        'form.alr_fname': _(u'Advanced Level Record'),
188        'form.hq_type': _(u'Higher Education Record'),
189        'form.hq2_type': _(u'Second Higher Education Record'),
190        'form.nysc_year': _(u'NYSC Information'),
191        'form.employer': _(u'Employment History'),
192        'form.former_matric': _(u'Former AAUE Student'),
193        }
194
195    # AAUE prefix
196    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.