[10120] | 1 | ## $Id: utils.py 10171 2013-05-10 13:59:17Z 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, |
---|
| 36 | previous_session, previous_level): |
---|
| 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 | if previous_session < student['studycourse'].entry_session: |
---|
| 45 | return _('The previous session must not fall below ' |
---|
| 46 | 'your entry session.'), None |
---|
| 47 | if category == 'schoolfee': |
---|
| 48 | # School fee is always paid for the following session |
---|
| 49 | if previous_session > student['studycourse'].current_session: |
---|
| 50 | return _('This is not a previous session.'), None |
---|
| 51 | else: |
---|
| 52 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 53 | return _('This is not a previous session.'), None |
---|
| 54 | p_session = previous_session |
---|
| 55 | p_level = previous_level |
---|
| 56 | p_current = False |
---|
| 57 | else: |
---|
| 58 | p_session = student['studycourse'].current_session |
---|
| 59 | p_level = student['studycourse'].current_level |
---|
| 60 | p_current = True |
---|
| 61 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 62 | if academic_session == None: |
---|
| 63 | return _(u'Session configuration object is not available.'), None |
---|
| 64 | # Determine fee. |
---|
| 65 | if category == 'schoolfee': |
---|
| 66 | try: |
---|
| 67 | certificate = student['studycourse'].certificate |
---|
| 68 | p_item = certificate.code |
---|
| 69 | except (AttributeError, TypeError): |
---|
| 70 | return _('Study course data are incomplete.'), None |
---|
| 71 | if previous_session: |
---|
| 72 | # Students can pay for previous sessions in all |
---|
| 73 | # workflow states. Fresh students are excluded by the |
---|
| 74 | # update method of the PreviousPaymentAddFormPage. |
---|
| 75 | if previous_level == 100: |
---|
| 76 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 77 | else: |
---|
| 78 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 79 | else: |
---|
| 80 | if student.state == CLEARED: |
---|
| 81 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 82 | elif student.state == RETURNING: |
---|
| 83 | # In case of returning school fee payment the |
---|
| 84 | # payment session and level contain the values of |
---|
| 85 | # the session the student has paid for. Payment |
---|
| 86 | # session is always next session. |
---|
| 87 | p_session, p_level = self.getReturningData(student) |
---|
| 88 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 89 | if academic_session == None: |
---|
| 90 | return _( |
---|
| 91 | u'Session configuration object is not available.' |
---|
| 92 | ), None |
---|
| 93 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 94 | elif student.is_postgrad and student.state == PAID: |
---|
| 95 | # Returning postgraduate students also pay for the |
---|
| 96 | # next session but their level always remains the |
---|
| 97 | # same. |
---|
| 98 | p_session += 1 |
---|
| 99 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 100 | if academic_session == None: |
---|
| 101 | return _( |
---|
| 102 | u'Session configuration object is not available.' |
---|
| 103 | ), None |
---|
| 104 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 105 | elif category == 'clearance': |
---|
| 106 | try: |
---|
| 107 | p_item = student['studycourse'].certificate.code |
---|
| 108 | except (AttributeError, TypeError): |
---|
| 109 | return _('Study course data are incomplete.'), None |
---|
| 110 | amount = academic_session.clearance_fee |
---|
| 111 | elif category == 'bed_allocation': |
---|
| 112 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
| 113 | amount = academic_session.booking_fee |
---|
| 114 | elif category == 'hostel_maintenance': |
---|
| 115 | amount = academic_session.maint_fee |
---|
| 116 | bedticket = student['accommodation'].get( |
---|
| 117 | str(student.current_session), None) |
---|
| 118 | if bedticket: |
---|
| 119 | p_item = bedticket.bed_coordinates |
---|
| 120 | else: |
---|
| 121 | # Should not happen because this is already checked |
---|
| 122 | # in the browser module, but anyway ... |
---|
| 123 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 124 | p_item = trans(_('no bed allocated'), portal_language) |
---|
| 125 | if amount in (0.0, None): |
---|
| 126 | return _('Amount could not be determined.'), None |
---|
| 127 | for key in student['payments'].keys(): |
---|
| 128 | ticket = student['payments'][key] |
---|
| 129 | if ticket.p_state == 'paid' and\ |
---|
| 130 | ticket.p_category == category and \ |
---|
| 131 | ticket.p_item == p_item and \ |
---|
| 132 | ticket.p_session == p_session: |
---|
| 133 | return _('This type of payment has already been made.'), None |
---|
| 134 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 135 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 136 | payment.p_id = "p%s" % timestamp |
---|
| 137 | payment.p_category = category |
---|
| 138 | payment.p_item = p_item |
---|
| 139 | payment.p_session = p_session |
---|
| 140 | payment.p_level = p_level |
---|
| 141 | payment.p_current = p_current |
---|
| 142 | payment.amount_auth = amount |
---|
| 143 | return None, payment |
---|
| 144 | |
---|
[10120] | 145 | # AAUA prefix |
---|
| 146 | STUDENT_ID_PREFIX = u'A' |
---|