[16639] | 1 | ## $Id: utils.py 17568 2023-08-31 09:12:24Z henrik $ |
---|
[15614] | 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 | from time import time |
---|
| 19 | from zope.component import createObject, getUtility |
---|
| 20 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
| 21 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
| 22 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[16615] | 23 | from kofacustom.edocons.interfaces import MessageFactory as _ |
---|
[15614] | 24 | |
---|
| 25 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
| 26 | """A collection of customized methods. |
---|
| 27 | |
---|
| 28 | """ |
---|
| 29 | |
---|
[16702] | 30 | # prefix |
---|
[16700] | 31 | STUDENT_ID_PREFIX = u'N' |
---|
[17095] | 32 | |
---|
| 33 | # Maximum size of upload files in kB |
---|
| 34 | MAX_KB = 500 |
---|
[17075] | 35 | |
---|
| 36 | SKIP_UPLOAD_VIEWLETS = ( |
---|
| 37 | 'acceptanceletterupload', |
---|
| 38 | 'certificateupload', |
---|
| 39 | 'evidencenameupload', |
---|
| 40 | 'refereeletterupload' |
---|
| 41 | ) |
---|
[16702] | 42 | |
---|
| 43 | def setPaymentDetails(self, category, student, |
---|
| 44 | previous_session=None, previous_level=None, combi=[]): |
---|
| 45 | """Create a payment ticket and set the payment data of a |
---|
| 46 | student for the payment category specified. |
---|
| 47 | """ |
---|
| 48 | p_item = u'' |
---|
| 49 | amount = 0.0 |
---|
| 50 | if previous_session: |
---|
| 51 | if previous_session < student['studycourse'].entry_session: |
---|
| 52 | return _('The previous session must not fall below ' |
---|
| 53 | 'your entry session.'), None |
---|
| 54 | if category == 'schoolfee': |
---|
| 55 | # School fee is always paid for the following session |
---|
| 56 | if previous_session > student['studycourse'].current_session: |
---|
| 57 | return _('This is not a previous session.'), None |
---|
| 58 | else: |
---|
| 59 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 60 | return _('This is not a previous session.'), None |
---|
| 61 | p_session = previous_session |
---|
| 62 | p_level = previous_level |
---|
| 63 | p_current = False |
---|
| 64 | else: |
---|
| 65 | p_session = student['studycourse'].current_session |
---|
| 66 | p_level = student['studycourse'].current_level |
---|
| 67 | p_current = True |
---|
| 68 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 69 | if academic_session == None: |
---|
| 70 | return _(u'Session configuration object is not available.'), None |
---|
| 71 | # Determine fee. |
---|
[17031] | 72 | if category in ('schoolfee', 'schoolfee_1', 'secondinstal'): |
---|
| 73 | try: |
---|
| 74 | certificate = student['studycourse'].certificate |
---|
| 75 | p_item = certificate.code |
---|
| 76 | except (AttributeError, TypeError): |
---|
| 77 | return _('Study course data are incomplete.'), None |
---|
| 78 | if previous_session: |
---|
| 79 | # Students can pay for previous sessions in all |
---|
| 80 | # workflow states. Fresh students are excluded by the |
---|
| 81 | # update method of the PreviousPaymentAddFormPage. |
---|
[17107] | 82 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[16704] | 83 | else: |
---|
[17107] | 84 | if student.state == CLEARED: |
---|
| 85 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 86 | elif student.state == RETURNING: |
---|
| 87 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 88 | # In case of returning school fee payment the |
---|
| 89 | # payment session and level contain the values of |
---|
| 90 | # the session the student has paid for. Payment |
---|
| 91 | # session is always next session. |
---|
| 92 | p_session, p_level = self.getReturningData(student) |
---|
| 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 | elif student.is_postgrad and student.state == PAID: |
---|
| 99 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 100 | # Returning postgraduate students also pay for the |
---|
| 101 | # next session but their level always remains the |
---|
| 102 | # same. |
---|
| 103 | p_session += 1 |
---|
| 104 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 105 | if academic_session == None: |
---|
| 106 | return _( |
---|
| 107 | u'Session configuration object is not available.' |
---|
| 108 | ), None |
---|
[17160] | 109 | if category == 'schoolfee_1': |
---|
[17414] | 110 | if student.state == CLEARED: |
---|
[17383] | 111 | amount = round(0.69318182 * amount) |
---|
[17414] | 112 | elif student.state == RETURNING: |
---|
[17384] | 113 | amount = round(0.62162162 * amount) |
---|
[17381] | 114 | # Second instalment can be paid in all states. |
---|
| 115 | if category == 'secondinstal': |
---|
[17415] | 116 | if not student.is_fresh or student.state == RETURNING: |
---|
| 117 | amount = round(0.37837838 * getattr(certificate, 'school_fee_2', 0.0)) |
---|
| 118 | else: |
---|
[17383] | 119 | amount = round(0.30681818 * getattr(certificate, 'school_fee_1', 0.0)) |
---|
[16702] | 120 | elif category == 'clearance': |
---|
| 121 | try: |
---|
| 122 | p_item = student['studycourse'].certificate.code |
---|
| 123 | except (AttributeError, TypeError): |
---|
| 124 | return _('Study course data are incomplete.'), None |
---|
| 125 | amount = academic_session.clearance_fee |
---|
| 126 | elif category == 'bed_allocation': |
---|
[17208] | 127 | acco_details = self.getAccommodationDetails(student) |
---|
| 128 | p_session = acco_details['booking_session'] |
---|
| 129 | p_item = acco_details['bt'] |
---|
[16702] | 130 | amount = academic_session.booking_fee |
---|
| 131 | elif category == 'hostel_maintenance': |
---|
| 132 | amount = 0.0 |
---|
[17208] | 133 | booking_session = grok.getSite()['hostels'].accommodation_session |
---|
| 134 | bedticket = student['accommodation'].get(str(booking_session), None) |
---|
[16702] | 135 | if bedticket is not None and bedticket.bed is not None: |
---|
[17208] | 136 | p_session = booking_session |
---|
[16702] | 137 | p_item = bedticket.bed_coordinates |
---|
| 138 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
| 139 | amount = bedticket.bed.__parent__.maint_fee |
---|
| 140 | else: |
---|
| 141 | # fallback |
---|
| 142 | amount = academic_session.maint_fee |
---|
| 143 | else: |
---|
| 144 | return _(u'No bed allocated.'), None |
---|
| 145 | elif category == 'combi' and combi: |
---|
| 146 | categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES |
---|
| 147 | for cat in combi: |
---|
| 148 | fee_name = cat + '_fee' |
---|
| 149 | cat_amount = getattr(academic_session, fee_name, 0.0) |
---|
| 150 | if not cat_amount: |
---|
| 151 | return _('%s undefined.' % categories[cat]), None |
---|
| 152 | amount += cat_amount |
---|
| 153 | p_item += u'%s + ' % categories[cat] |
---|
| 154 | p_item = p_item.strip(' + ') |
---|
| 155 | else: |
---|
| 156 | fee_name = category + '_fee' |
---|
| 157 | amount = getattr(academic_session, fee_name, 0.0) |
---|
| 158 | if amount in (0.0, None): |
---|
| 159 | return _('Amount could not be determined.'), None |
---|
| 160 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 161 | return _('This type of payment has already been made.'), None |
---|
| 162 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 163 | return _('This category of payments has been disabled.'), None |
---|
| 164 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 165 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 166 | payment.p_id = "p%s" % timestamp |
---|
| 167 | payment.p_category = category |
---|
| 168 | payment.p_item = p_item |
---|
| 169 | payment.p_session = p_session |
---|
| 170 | payment.p_level = p_level |
---|
| 171 | payment.p_current = p_current |
---|
| 172 | payment.amount_auth = amount |
---|
| 173 | payment.p_combi = combi |
---|
| 174 | return None, payment |
---|
[17567] | 175 | |
---|
| 176 | def warnCreditsOOR(self, studylevel, course=None): |
---|
| 177 | studycourse = studylevel.__parent__ |
---|
| 178 | certificate = getattr(studycourse,'certificate', None) |
---|
[17568] | 179 | if None in (studylevel.level, certificate): |
---|
[17567] | 180 | return |
---|
| 181 | limit = 50 |
---|
[17568] | 182 | if studylevel.level == 200 and certificate.code == 'RNS': |
---|
[17567] | 183 | limit = 55 |
---|
| 184 | if course and studylevel.total_credits + course.credits > limit: |
---|
| 185 | return _('Maximum credits exceeded.') |
---|
| 186 | elif studylevel.total_credits > limit: |
---|
| 187 | return _('Maximum credits exceeded.') |
---|
| 188 | return |
---|