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

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

Fix flow of payments.

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