source: main/waeup.aaua/trunk/src/waeup/aaua/students/utils.py @ 10174

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

Configure school fee payment by installments.

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1## $Id: utils.py 10173 2013-05-12 05:28:42Z 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
19import random
20from time import time
21from zope.component import createObject, getUtility
22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from waeup.kofa.accesscodes import create_accesscode
25from waeup.kofa.interfaces import CLEARED, RETURNING, IKofaUtils
26from waeup.kofa.fees import FeeTable
27from waeup.aaua.interfaces import MessageFactory as _
28
29
30class CustomStudentsUtils(NigeriaStudentsUtils):
31    """A collection of customized methods.
32
33    """
34
35    def setPaymentDetails(self, category, student,
36            previous_session=None, previous_level=None):
37        """Create Payment object and set the payment data of a student for
38        the payment category specified.
39
40        """
41        p_item = u''
42        amount = 0.0
43        if previous_session:
44            return _('Previous session payment not yet implemented.'), None
45        p_session = student['studycourse'].current_session
46        p_level = student['studycourse'].current_level
47        p_current = True
48        academic_session = self._getSessionConfiguration(p_session)
49        if academic_session == None:
50            return _(u'Session configuration object is not available.'), None
51        # Determine fee.
52        if category in ('schoolfee', 'schoolfee_1',  'schoolfee_2'):
53            try:
54                certificate = student['studycourse'].certificate
55                p_item = certificate.code
56            except (AttributeError, TypeError):
57                return _('Study course data are incomplete.'), None
58            ratio = getattr(certificate, 'ratio', 0.0)
59            if ratio is None:
60                ratio = 0.0
61            if category == 'schoolfee' and ratio > 0:
62                return _('Payment by instalments required.'), None
63            if category in ('schoolfee_1',  'schoolfee_2') and ratio == 0:
64                return _('Payment by instalments not allowed.'), None
65            if student.state == CLEARED:
66                if category == 'schoolfee':
67                    amount = getattr(certificate, 'school_fee_1', 0.0)
68                elif category == 'schoolfee_1':
69                    amount = getattr(certificate, 'school_fee_1', 0.0) * ratio
70                elif category == 'schoolfee_2':
71                    amount = getattr(certificate, 'school_fee_1', 0.0) * (1- ratio)
72            elif student.state == RETURNING:
73                # In case of returning school fee payment the
74                # payment session and level contain the values of
75                # the session the student has paid for. Payment
76                # session is always next session.
77                p_session, p_level = self.getReturningData(student)
78                academic_session = self._getSessionConfiguration(p_session)
79                if academic_session == None:
80                    return _(
81                        u'Session configuration object is not available.'
82                        ), None
83                if category == 'schoolfee':
84                    amount = getattr(certificate, 'school_fee_2', 0.0)
85                elif category == 'schoolfee_1':
86                    amount = getattr(certificate, 'school_fee_2', 0.0) * ratio
87                elif category == 'schoolfee_2' and ratio:
88                    amount = getattr(certificate, 'school_fee_2', 0.0) * (1- ratio)
89            elif student.is_postgrad and student.state == PAID:
90                # Returning postgraduate students also pay for the
91                # next session but their level always remains the
92                # same.
93                p_session += 1
94                academic_session = self._getSessionConfiguration(p_session)
95                if academic_session == None:
96                    return _(
97                        u'Session configuration object is not available.'
98                        ), None
99                if category == 'schoolfee':
100                    amount = getattr(certificate, 'school_fee_2', 0.0)
101                elif category == 'schoolfee_1':
102                    amount = getattr(certificate, 'school_fee_2', 0.0) * ratio
103                elif category == 'schoolfee_2' and ratio:
104                    amount = getattr(certificate, 'school_fee_2', 0.0) * (1- ratio)
105        if amount in (0.0, None):
106            return _('Amount could not be determined.'), None
107        for key in student['payments'].keys():
108            ticket = student['payments'][key]
109            if ticket.p_state == 'paid' and\
110               ticket.p_category == category and \
111               ticket.p_item == p_item and \
112               ticket.p_session == p_session:
113                  return _('This type of payment has already been made.'), None
114        payment = createObject(u'waeup.StudentOnlinePayment')
115        timestamp = ("%d" % int(time()*10000))[1:]
116        payment.p_id = "p%s" % timestamp
117        payment.p_category = category
118        payment.p_item = p_item
119        payment.p_session = p_session
120        payment.p_level = p_level
121        payment.p_current = p_current
122        payment.amount_auth = amount
123        return None, payment
124
125    # AAUA prefix
126    STUDENT_ID_PREFIX = u'A'
Note: See TracBrowser for help on using the repository browser.