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

Last change on this file since 15837 was 15674, checked in by Henrik Bettermann, 5 years ago

Adjust to changes in bae package.

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1## $Id: utils.py 15674 2019-10-13 21:06:08Z 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, p_combi=[]):
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        try:
53            certificate = student['studycourse'].certificate
54            p_item = certificate.code
55        except (AttributeError, TypeError):
56            return _('Study course data are incomplete.'), None
57        ratio = getattr(certificate, 'ratio', 0.0)
58        if ratio is None:
59            ratio = 0.0
60        if category in ('schoolfee', 'schoolfee_1'):
61            if category == 'schoolfee' and ratio > 0:
62                return _('Payment by instalments required.'), None
63            if category =='schoolfee_1' 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 student.state == RETURNING:
71                # In case of returning school fee payment the
72                # payment session and level contain the values of
73                # the session the student has paid for. Payment
74                # session is always next session.
75                p_session, p_level = self.getReturningData(student)
76                academic_session = self._getSessionConfiguration(p_session)
77                if academic_session == None:
78                    return _(
79                        u'Session configuration object is not available.'
80                        ), None
81                if category == 'schoolfee':
82                    amount = getattr(certificate, 'school_fee_2', 0.0)
83                elif category == 'schoolfee_1':
84                    amount = getattr(certificate, 'school_fee_2', 0.0) * ratio
85                    if student['studycourse'].entry_session in (
86                        2005, 2006, 2007) and student.current_mode == 'ug_pt':
87                        amount -= 20000.0
88            elif student.is_postgrad and student.state == PAID:
89                # Returning postgraduate students also pay for the
90                # next session but their level always remains the
91                # same.
92                p_session += 1
93                academic_session = self._getSessionConfiguration(p_session)
94                if academic_session == None:
95                    return _(
96                        u'Session configuration object is not available.'
97                        ), None
98                if category == 'schoolfee':
99                    amount = getattr(certificate, 'school_fee_2', 0.0)
100                elif category == 'schoolfee_1':
101                    amount = getattr(certificate, 'school_fee_2', 0.0) * ratio
102        elif category ==  'schoolfee_2':
103            if ratio == 0:
104                return _('Payment by instalments not allowed.'), None
105            if student['studycourse'].entry_session == student.current_session:
106                amount = getattr(certificate, 'school_fee_1', 0.0) * (1- ratio)
107            else:
108                amount = getattr(certificate, 'school_fee_2', 0.0) * (1- ratio)
109        if amount in (0.0, None):
110            return _('Amount could not be determined.'), None
111        if self.samePaymentMade(student, category, p_item, p_session):
112            return _('This type of payment has already been made.'), None
113        if self._isPaymentDisabled(p_session, category, student):
114            return _('Payment temporarily disabled.'), None
115        payment = createObject(u'waeup.StudentOnlinePayment')
116        timestamp = ("%d" % int(time()*10000))[1:]
117        payment.p_id = "p%s" % timestamp
118        payment.p_category = category
119        payment.p_item = p_item
120        payment.p_session = p_session
121        payment.p_level = p_level
122        payment.p_current = p_current
123        payment.amount_auth = amount
124        return None, payment
125
126    # AAUA prefix
127    STUDENT_ID_PREFIX = u'A'
Note: See TracBrowser for help on using the repository browser.