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

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

Prepare for previous session payments.

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1## $Id: utils.py 9154 2012-09-04 07:07:44Z 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        session = str(p_session)
66        try:
67            academic_session = grok.getSite()['configuration'][session]
68        except KeyError:
69            return _(u'Session configuration object is not available.'), None
70        # Determine fee.
71        if category == 'schoolfee':
72            return _('School fee has to be paid by two instalments.'), None
73        if category == 'transfer':
74            amount = academic_session.transfer_fee
75        elif category == 'gown':
76            amount = academic_session.gown_fee
77        elif category == 'bed_allocation':
78            amount = academic_session.booking_fee
79        elif category == 'hostel_maintenance':
80            amount = academic_session.maint_fee
81        elif category == 'clearance':
82            amount = academic_session.clearance_fee
83            p_item = student['studycourse'].certificate.code
84        elif category == 'schoolfee_1':
85            try:
86                certificate = student['studycourse'].certificate
87                p_item = certificate.code
88            except (AttributeError, TypeError):
89                return _('Study course data are incomplete.'), None
90            payment_allowed = False
91            if student.state == CLEARED:
92                payment_allowed = True
93                amount = academic_session.school_fee_base
94            elif student.state == RETURNING or\
95                (student.is_postgrad and student.state == PAID):
96                if student.state == RETURNING:
97                    p_session, p_level = self.getReturningData(student)
98                else:
99                    # Returning postgraduate students also pay for the
100                    # next session but their level always remains the same.
101                    p_session += 1
102                initial_instalment_made = False
103                for key in student['payments'].keys():
104                    ticket = student['payments'][key]
105                    if ticket.p_category == 'schoolfee_1' and \
106                        ticket.p_state == 'paid':
107                        initial_instalment_made = True
108                    if ticket.p_state == 'paid' and\
109                        ticket.p_category == 'schoolfee_2' and \
110                        ticket.p_item == p_item and \
111                        ticket.p_session == p_session-1: #  = current session
112                        payment_allowed = True
113                if not initial_instalment_made:
114                    payment_allowed = True
115                try:
116                    academic_session = grok.getSite()[
117                        'configuration'][str(p_session)]
118                except KeyError:
119                    return _(u'Session configuration object is not available.'), None
120                amount = academic_session.school_fee_base
121            else:
122                return _('Wrong state.'), None
123            if not payment_allowed:
124                return _('The previous 2nd school fee instalment '
125                         'has not yet been paid.'), None
126        elif category == 'schoolfee_2':
127            try:
128                certificate = student['studycourse'].certificate
129                p_item = certificate.code
130            except (AttributeError, TypeError):
131                return _('Study course data are incomplete.'), None
132            payment_allowed = False
133            for key in student['payments'].keys():
134                ticket = student['payments'][key]
135                if ticket.p_state == 'paid' and\
136                   ticket.p_category == 'schoolfee_1' and \
137                   ticket.p_item == p_item and \
138                   ticket.p_session == p_session:
139                   payment_allowed = True
140            if not payment_allowed:
141                return _('The 1st school fee instalment '
142                         'has not yet been paid or session has '
143                         'not yet been started.'), None
144            amount = academic_session.school_fee_base
145        if amount in (0.0, None):
146            return _(u'Amount could not be determined.'), None
147        # Add session specific penalty fee.
148        if category == 'schoolfee_1' and student.is_postgrad:
149            amount += academic_session.penalty_pg
150        elif category == 'schoolfee_1':
151            amount += academic_session.penalty_ug
152        # Create ticket.
153        for key in student['payments'].keys():
154            ticket = student['payments'][key]
155            if ticket.p_state == 'paid' and\
156               ticket.p_category == category and \
157               ticket.p_item == p_item and \
158               ticket.p_session == p_session:
159                  return _('This type of payment has already been made.'), None
160        payment = createObject(u'waeup.StudentOnlinePayment')
161        timestamp = ("%d" % int(time()*10000))[1:]
162        payment.p_id = "p%s" % timestamp
163        payment.p_category = category
164        payment.p_item = p_item
165        payment.p_session = p_session
166        payment.p_level = p_level
167        payment.p_current = p_current
168        payment.amount_auth = amount
169        return None, payment
170
171    # AAUE prefix
172    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.