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

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

Merged with waeup.uniben 8820:HEAD.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## $Id: utils.py 8823 2012-06-27 08:09:19Z 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        """Create Payment object and set the payment data of a student for
52        the payment category specified.
53
54        """
55        details = {}
56        p_item = u''
57        amount = 0.0
58        error = u''
59        p_session = student['studycourse'].current_session
60        p_level = student['studycourse'].current_level
61        session = str(p_session)
62        try:
63            academic_session = grok.getSite()['configuration'][session]
64        except KeyError:
65            return _(u'Session configuration object is not available.'), None
66        # Determine fee.
67        if category == 'schoolfee':
68            return _('School fee has to be paid by two instalments.'), None
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' and \
96                        ticket.p_state == 'paid':
97                        initial_instalment_made = True
98                    if ticket.p_state == 'paid' and\
99                        ticket.p_category == 'schoolfee_2' and \
100                        ticket.p_item == p_item and \
101                        ticket.p_session == p_session-1: #  = current session
102                        payment_allowed = True
103                if not initial_instalment_made:
104                    payment_allowed = True
105                amount = academic_session.school_fee_base
106            else:
107                return _('Wrong state.'), None
108            if not payment_allowed:
109                return _('The previous 2nd school fee instalment '
110                         'has not yet been paid.'), None
111        elif category == 'schoolfee_2':
112            try:
113                certificate = student['studycourse'].certificate
114                p_item = certificate.code
115            except (AttributeError, TypeError):
116                return _('Study course data are incomplete.'), None
117            payment_allowed = False
118            for key in student['payments'].keys():
119                ticket = student['payments'][key]
120                if ticket.p_state == 'paid' and\
121                   ticket.p_category == 'schoolfee_1' and \
122                   ticket.p_item == p_item and \
123                   ticket.p_session == p_session:
124                   payment_allowed = True
125            if not payment_allowed:
126                return _('The 1st school fee instalment '
127                         'has not yet been paid or session has '
128                         'not yet been started.'), None
129            amount = academic_session.school_fee_base
130        if amount in (0.0, None):
131            return _(u'Amount could not be determined.'), None
132        # Add session specific penalty fee.
133        if category == 'schoolfee_1' and student.is_postgrad:
134            amount += academic_session.penalty_pg
135        elif category == 'schoolfee_1':
136            amount += academic_session.penalty_ug
137        # Create ticket.
138        for key in student['payments'].keys():
139            ticket = student['payments'][key]
140            if ticket.p_state == 'paid' and\
141               ticket.p_category == category and \
142               ticket.p_item == p_item and \
143               ticket.p_session == p_session:
144                  return _('This type of payment has already been made.'), None
145        payment = createObject(u'waeup.StudentOnlinePayment')
146        timestamp = "%d" % int(time()*1000)
147        payment.p_id = "p%s" % timestamp
148        payment.p_category = category
149        payment.p_item = p_item
150        payment.p_session = p_session
151        payment.p_level = p_level
152        payment.amount_auth = amount
153        return None, payment
154
155    # AAUE prefix
156    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.