[10120] | 1 | ## $Id: utils.py 11648 2014-05-14 05:26:13Z 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 | |
---|
[10171] | 35 | def setPaymentDetails(self, category, student, |
---|
[10173] | 36 | previous_session=None, previous_level=None): |
---|
[10171] | 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: |
---|
[10173] | 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 |
---|
[10171] | 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. |
---|
[10181] | 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'): |
---|
[10173] | 61 | if category == 'schoolfee' and ratio > 0: |
---|
| 62 | return _('Payment by instalments required.'), None |
---|
[10181] | 63 | if category =='schoolfee_1' and ratio == 0: |
---|
[10173] | 64 | return _('Payment by instalments not allowed.'), None |
---|
| 65 | if student.state == CLEARED: |
---|
| 66 | if category == 'schoolfee': |
---|
[10171] | 67 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
[10173] | 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': |
---|
[10171] | 82 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[10173] | 83 | elif category == 'schoolfee_1': |
---|
| 84 | amount = getattr(certificate, 'school_fee_2', 0.0) * ratio |
---|
[10192] | 85 | if student['studycourse'].entry_session in ( |
---|
| 86 | 2005, 2006, 2007) and student.current_mode == 'ug_pt': |
---|
[10180] | 87 | amount -= 20000.0 |
---|
[10173] | 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': |
---|
[10171] | 99 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[10173] | 100 | elif category == 'schoolfee_1': |
---|
| 101 | amount = getattr(certificate, 'school_fee_2', 0.0) * ratio |
---|
[10181] | 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) |
---|
[10171] | 109 | if amount in (0.0, None): |
---|
| 110 | return _('Amount could not be determined.'), None |
---|
[11648] | 111 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 112 | return _('This type of payment has already been made.'), None |
---|
[11454] | 113 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 114 | return _('Payment temporarily disabled.'), None |
---|
[10171] | 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 | |
---|
[10120] | 126 | # AAUA prefix |
---|
| 127 | STUDENT_ID_PREFIX = u'A' |
---|