1 | ## $Id: utils.py 10192 2013-05-22 12:48:32Z 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 | ## |
---|
18 | import grok |
---|
19 | import random |
---|
20 | from time import time |
---|
21 | from zope.component import createObject, getUtility |
---|
22 | from waeup.kofa.interfaces import CLEARED, RETURNING, PAID |
---|
23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
24 | from waeup.kofa.accesscodes import create_accesscode |
---|
25 | from waeup.kofa.interfaces import CLEARED, RETURNING, IKofaUtils |
---|
26 | from waeup.kofa.fees import FeeTable |
---|
27 | from waeup.aaua.interfaces import MessageFactory as _ |
---|
28 | |
---|
29 | |
---|
30 | class 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 | 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 | for key in student['payments'].keys(): |
---|
112 | ticket = student['payments'][key] |
---|
113 | if ticket.p_state == 'paid' and\ |
---|
114 | ticket.p_category == category and \ |
---|
115 | ticket.p_item == p_item and \ |
---|
116 | ticket.p_session == p_session: |
---|
117 | return _('This type of payment has already been made.'), None |
---|
118 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
119 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
120 | payment.p_id = "p%s" % timestamp |
---|
121 | payment.p_category = category |
---|
122 | payment.p_item = p_item |
---|
123 | payment.p_session = p_session |
---|
124 | payment.p_level = p_level |
---|
125 | payment.p_current = p_current |
---|
126 | payment.amount_auth = amount |
---|
127 | return None, payment |
---|
128 | |
---|
129 | # AAUA prefix |
---|
130 | STUDENT_ID_PREFIX = u'A' |
---|