source: main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py @ 17980

Last change on this file since 17980 was 17979, checked in by Henrik Bettermann, 9 days ago

NUGA LEVY TO BE ADDED TO SCHOOL CHARGES (#1387)

  • Property svn:keywords set to Id
File size: 39.5 KB
RevLine 
[7419]1## $Id: utils.py 17979 2024-12-31 13:53:46Z 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##
[11773]18import grok
[17457]19import os
20import csv
[8598]21from time import time
[16108]22from reportlab.platypus import Paragraph, Table
[9459]23from zope.component import createObject, getUtility
[16106]24from reportlab.lib.styles import getSampleStyleSheet
[16108]25from waeup.kofa.browser.pdf import ENTRY1_STYLE
[16359]26from waeup.kofa.interfaces import (IKofaUtils, ADMITTED, CLEARANCE,
[16445]27    CLEARED, REQUESTED, RETURNING, PAID, REGISTERED, VALIDATED, GRADUATED)
[13251]28from waeup.kofa.utils.helpers import to_timezone
[16108]29from waeup.kofa.students.utils import (
30    trans, render_student_data, formatted_text, render_transcript_data,
31    SLIP_STYLE)
[8821]32from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8020]33from waeup.uniben.interfaces import MessageFactory as _
[6902]34
[17457]35SCHOOLFEES = dict()
36
37schoolfees_path = os.path.join(
[17930]38    os.path.dirname(__file__), 'schoolfees_24.csv')
39reader = csv.DictReader(open(schoolfees_path, 'rb'))
40SCHOOLFEES[24] = {line['code']: {item[0]:item[1] for item in line.items()}
41    for line in reader}
42
43schoolfees_path = os.path.join(
[17707]44    os.path.dirname(__file__), 'schoolfees_23.csv')
45reader = csv.DictReader(open(schoolfees_path, 'rb'))
46SCHOOLFEES[23] = {line['code']: {item[0]:item[1] for item in line.items()}
47    for line in reader}
48
49schoolfees_path = os.path.join(
[17457]50    os.path.dirname(__file__), 'schoolfees_22.csv')
51reader = csv.DictReader(open(schoolfees_path, 'rb'))
52SCHOOLFEES[22] = {line['code']: {item[0]:item[1] for item in line.items()}
53    for line in reader}
54
55
56schoolfees_path = os.path.join(
57    os.path.dirname(__file__), 'schoolfees_20.csv')
58reader = csv.DictReader(open(schoolfees_path, 'rb'))
59SCHOOLFEES[20] = {line['code']: {item[0]:item[1] for item in line.items()}
60    for line in reader}
61
62
63schoolfees_path = os.path.join(
64    os.path.dirname(__file__), 'schoolfees_17.csv')
65reader = csv.DictReader(open(schoolfees_path, 'rb'))
66SCHOOLFEES[17] = {line['code']: {item[0]:item[1] for item in line.items()}
67    for line in reader}
68
69schoolfees_path = os.path.join(
70    os.path.dirname(__file__), 'schoolfees_12.csv')
71reader = csv.DictReader(open(schoolfees_path, 'rb'))
72SCHOOLFEES[12] = {line['code']: {item[0]:item[1] for item in line.items()}
73    for line in reader}
74
[8821]75class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]76    """A collection of customized methods.
77
78    """
79
[16382]80    SEPARATORS_DICT = {
81        'form.fst_sit_fname': _(u'First Sitting Record'),
82        'form.scd_sit_fname': _(u'Second Sitting Record'),
83        'form.alr_fname': _(u'Advanced Level Record'),
84        'form.hq_type': _(u'Higher Education Record'),
85        'form.hq2_type': _(u'Second Higher Education Record'),
86        'form.nysc_year': _(u'NYSC Information'),
87        'form.employer': _(u'Employment History'),
88        'form.former_matric': _(u'Former Student'),
89        'form.fever': _(u'History of Symptoms'),
90        'form.asthma': _(u'Medical History'),
91        'form.lagos_abuja': _(u'Travel History'),
92        'form.company_suspected': _(u'History of Contact/Infection'),
[17255]93        'form.genotype': _(u'TISHIP Registration Form Data'),
[16382]94        }
95
[8270]96    def getReturningData(self, student):
97        """ This method defines what happens after school fee payment
[8319]98        of returning students depending on the student's senate verdict.
[8270]99        """
[8319]100        prev_level = student['studycourse'].current_level
101        cur_verdict = student['studycourse'].current_verdict
[16714]102        if cur_verdict == 'N' and prev_level in (100, 200):
[15482]103            new_level = prev_level
[17536]104        elif cur_verdict in ('A','B','M','N','Z',):
[8319]105            # Successful student
106            new_level = divmod(int(prev_level),100)[0]*100 + 100
[17536]107        elif cur_verdict in ('C', 'L',):
[8319]108            # Student on probation
109            new_level = int(prev_level) + 10
110        else:
111            # Student is somehow in an undefined state.
112            # Level has to be set manually.
113            new_level = prev_level
[8270]114        new_session = student['studycourse'].current_session + 1
115        return new_session, new_level
116
[17743]117    ACCOMMODATION_SPAN = 5
[13251]118
[13248]119    def checkAccommodationRequirements(self, student, acc_details):
120        if acc_details.get('expired', False):
121            startdate = acc_details.get('startdate')
122            enddate = acc_details.get('enddate')
123            if startdate and enddate:
124                tz = getUtility(IKofaUtils).tzinfo
125                startdate = to_timezone(
126                    startdate, tz).strftime("%d/%m/%Y %H:%M:%S")
127                enddate = to_timezone(
128                    enddate, tz).strftime("%d/%m/%Y %H:%M:%S")
129                return _("Outside booking period: ${a} - ${b}",
130                         mapping = {'a': startdate, 'b': enddate})
131            else:
132                return _("Outside booking period.")
[13777]133        if not student.is_postgrad and student.current_mode != 'ug_ft':
[13446]134            return _("Only undergraduate full-time students are eligible to book accommodation.")
[13283]135        bt = acc_details.get('bt')
136        if not bt:
[13248]137            return _("Your data are incomplete.")
138        if not student.state in acc_details['allowed_states']:
139            return _("You are in the wrong registration state.")
[17255]140        #if student['studycourse'].current_session != acc_details[
141        #    'booking_session']:
142        #    return _('Your current session does not '
143        #             'match accommodation session.')
144        if  acc_details['booking_session'] - student[
145            'studycourse'].current_session > self.ACCOMMODATION_SPAN:
146            return _('Your current session does not allow ' + \
147                    'to book accommodation.')
[13283]148        stage = bt.split('_')[2]
[13777]149        if not student.is_postgrad and stage != 'fr' and not student[
[14328]150            'studycourse'].previous_verdict in (
[15392]151                'A', 'B', 'F', 'J', 'L', 'M', 'C', 'Z'):
[13283]152            return _("Your are not eligible to book accommodation.")
[15307]153        bsession = str(acc_details['booking_session'])
154        if bsession in student['accommodation'].keys() \
155            and not 'booking expired' in \
156            student['accommodation'][bsession].bed_coordinates:
[13248]157            return _('You already booked a bed space in '
158                     'current accommodation session.')
159        return
[13244]160
[13295]161    def getAccommodationDetails(self, student):
162        """Determine the accommodation data of a student.
163        """
164        d = {}
165        d['error'] = u''
166        hostels = grok.getSite()['hostels']
167        d['booking_session'] = hostels.accommodation_session
168        d['allowed_states'] = hostels.accommodation_states
169        d['startdate'] = hostels.startdate
170        d['enddate'] = hostels.enddate
171        d['expired'] = hostels.expired
172        # Determine bed type
173        studycourse = student['studycourse']
174        certificate = getattr(studycourse,'certificate',None)
175        entry_session = studycourse.entry_session
176        current_level = studycourse.current_level
177        if None in (entry_session, current_level, certificate):
178            return d
179        if student.sex == 'f':
180            sex = 'female'
181        else:
182            sex = 'male'
[13777]183        if student.is_postgrad:
184            bt = 'all'
185            special_handling = 'pg'
186        else:
187            end_level = certificate.end_level
188            if current_level == 10:
189                bt = 'pr'
190            elif entry_session == grok.getSite()['hostels'].accommodation_session:
191                bt = 'fr'
192            elif current_level >= end_level:
193                bt = 'fi'
194            else:
195                bt = 're'
196            special_handling = 'regular'
[15354]197            desired_hostel = student['accommodation'].desired_hostel
198            if student.faccode in ('MED', 'DEN') and (
199                not desired_hostel or desired_hostel.startswith('clinical')):
[13777]200                special_handling = 'clinical'
201            elif student.certcode in ('BARTMAS', 'BARTTHR', 'BARTFAA',
[17324]202                                      'BAEDFAA', 'BSCEDECHED', 'BAFAA',
[17603]203                                      'BARTMUS', 'BSCEDECHED', 'BEDECHEDU'):
[13777]204                special_handling = 'ekenwan'
[13295]205        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
206        return d
207
[9520]208    def _paymentMade(self, student, session):
209        if len(student['payments']):
210            for ticket in student['payments'].values():
211                if ticket.p_state == 'paid' and \
212                    ticket.p_category == 'schoolfee' and \
213                    ticket.p_session == session:
214                    return True
215        return False
216
[13566]217    def _isPaymentDisabled(self, p_session, category, student):
218        academic_session = self._getSessionConfiguration(p_session)
[14688]219        if category == 'schoolfee':
220            if 'sf_all' in academic_session.payment_disabled:
221                return True
[16516]222            if student.state == RETURNING and \
223                'sf_return' in academic_session.payment_disabled:
224                return True
[14688]225            if student.current_mode == 'found' and \
226                'sf_found' in academic_session.payment_disabled:
227                return True
228            if student.is_postgrad:
229                if 'sf_pg' in academic_session.payment_disabled:
230                    return True
231                return False
232            if student.current_mode.endswith('ft') and \
233                'sf_ft' in academic_session.payment_disabled:
234                return True
235            if student.current_mode.endswith('pt') and \
236                'sf_pt' in academic_session.payment_disabled:
237                return True
238            if student.current_mode.startswith('dp') and \
239                'sf_dp' in academic_session.payment_disabled:
240                return True
241            if student.current_mode.endswith('sw') and \
242                'sf_sw' in academic_session.payment_disabled:
243                return True
[13566]244        if category == 'hostel_maintenance' and \
245            'maint_all' in academic_session.payment_disabled:
246            return True
[16025]247        if category == 'clearance':
248            if 'cl_all' in academic_session.payment_disabled:
249                return True
250            if student.is_jupeb and \
251                'cl_jupeb' in academic_session.payment_disabled:
252                return True
[16374]253            if not student.is_jupeb and \
254                'cl_allexj' in academic_session.payment_disabled:
255                return True
[13566]256        return False
257
[13251]258    #def _hostelApplicationPaymentMade(self, student, session):
259    #    if len(student['payments']):
260    #        for ticket in student['payments'].values():
261    #            if ticket.p_state == 'paid' and \
262    #                ticket.p_category == 'hostel_application' and \
263    #                ticket.p_session == session:
264    #                return True
265    #    return False
[12566]266
[14960]267    def _pharmdInstallments(self, student):
268        installments = 0.0
269        if len(student['payments']):
270            for ticket in student['payments'].values():
271                if ticket.p_state == 'paid' and \
272                    ticket.p_category.startswith('pharmd') and \
273                    ticket.p_session == student.current_session:
274                    installments += ticket.amount_auth
275        return installments
276
[15320]277    def samePaymentMade(self, student, category, p_item, p_session):
[15447]278        if category in ('bed_allocation', 'transcript'):
[15320]279            return False
280        for key in student['payments'].keys():
281            ticket = student['payments'][key]
282            if ticket.p_state == 'paid' and\
283               ticket.p_category == category and \
284               ticket.p_item == p_item and \
285               ticket.p_session == p_session:
286                  return True
287        return False
288
[17606]289    def setCDLPaymentDetails(self, category, student,
290            previous_session, previous_level, combi):
291        """Create Payment object and set the payment data of a CDL student for
292        the payment category specified.
293        """
294        p_item = u''
295        amount = 0.0
296        if previous_session:
297            if previous_session < student['studycourse'].entry_session:
298                return _('The previous session must not fall below '
299                         'your entry session.'), None
300            if category == 'schoolfee':
301                # School fee is always paid for the following session
302                if previous_session > student['studycourse'].current_session:
303                    return _('This is not a previous session.'), None
304            else:
305                if previous_session > student['studycourse'].current_session - 1:
306                    return _('This is not a previous session.'), None
307            p_session = previous_session
308            p_level = previous_level
309            p_current = False
310        else:
311            p_session = student['studycourse'].current_session
312            p_level = student['studycourse'].current_level
313            p_current = True
314        academic_session = self._getSessionConfiguration(p_session)
315        if academic_session == None:
316            return _(u'Session configuration object is not available.'), None
317        # Determine fee.
318        if category == 'schoolfee':
319            try:
320                certificate = student['studycourse'].certificate
321                p_item = certificate.code
322            except (AttributeError, TypeError):
323                return _('Study course data are incomplete.'), None
324            if previous_session:
325                # Students can pay for previous sessions in all
326                # workflow states.  Fresh students are excluded by the
327                # update method of the PreviousPaymentAddFormPage.
328                if previous_level == 100:
329                    amount = getattr(certificate, 'school_fee_1', 0.0)
330                else:
331                    amount = getattr(certificate, 'school_fee_2', 0.0)
332            else:
333                if student.state == CLEARED:
334                    amount = getattr(certificate, 'school_fee_1', 0.0)
335                elif student.state == RETURNING:
336                    # In case of returning school fee payment the
337                    # payment session and level contain the values of
338                    # the session the student has paid for. Payment
339                    # session is always next session.
340                    p_session, p_level = self.getReturningData(student)
341                    academic_session = self._getSessionConfiguration(p_session)
342                    if academic_session == None:
343                        return _(
344                            u'Session configuration object is not available.'
345                            ), None
346                    amount = getattr(certificate, 'school_fee_2', 0.0)
347                elif student.is_postgrad and student.state == PAID:
348                    # Returning postgraduate students also pay for the
349                    # next session but their level always remains the
350                    # same.
351                    p_session += 1
352                    academic_session = self._getSessionConfiguration(p_session)
353                    if academic_session == None:
354                        return _(
355                            u'Session configuration object is not available.'
356                            ), None
357                    amount = getattr(certificate, 'school_fee_2', 0.0)
358        elif category == 'clearance':
359            try:
360                p_item = student['studycourse'].certificate.code
361            except (AttributeError, TypeError):
362                return _('Study course data are incomplete.'), None
363            amount = academic_session.clearance_fee
364        elif category == 'combi' and combi:
365            categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES
366            for cat in combi:
367                fee_name = cat + '_fee'
368                cat_amount = getattr(academic_session, fee_name, 0.0)
369                if not cat_amount:
370                    return _('%s undefined.' % categories[cat]), None
371                amount += cat_amount
372                p_item += u'%s + ' % categories[cat]
373            p_item = p_item.strip(' + ')
374        else:
375            fee_name = category + '_fee'
376            amount = getattr(academic_session, fee_name, 0.0)
377        if amount in (0.0, None):
378            return _('Amount could not be determined.'), None
379        if self.samePaymentMade(student, category, p_item, p_session):
380            return _('This type of payment has already been made.'), None
381        if self._isPaymentDisabled(p_session, category, student):
382            return _('This category of payments has been disabled.'), None
383        payment = createObject(u'waeup.StudentOnlinePayment')
384        timestamp = ("%d" % int(time()*10000))[1:]
385        payment.p_id = "p%s" % timestamp
386        payment.p_category = category
387        payment.p_item = p_item
388        payment.p_session = p_session
389        payment.p_level = p_level
390        payment.p_current = p_current
391        payment.amount_auth = amount
392        payment.p_combi = combi
393        return None, payment
394
395
[9152]396    def setPaymentDetails(self, category, student,
[15666]397            previous_session, previous_level, combi):
[8598]398        """Create Payment object and set the payment data of a student for
399        the payment category specified.
400
401        """
[17606]402        if grok.getSite().__name__ == 'uniben-cdl':
403            return self.setCDLPaymentDetails(category, student,
404                previous_session, previous_level, combi)
[8598]405        p_item = u''
406        amount = 0.0
[9152]407        if previous_session:
[9520]408            if previous_session < student['studycourse'].entry_session:
409                return _('The previous session must not fall below '
410                         'your entry session.'), None
411            if category == 'schoolfee':
412                # School fee is always paid for the following session
413                if previous_session > student['studycourse'].current_session:
414                    return _('This is not a previous session.'), None
415            else:
416                if previous_session > student['studycourse'].current_session - 1:
417                    return _('This is not a previous session.'), None
[9152]418            p_session = previous_session
419            p_level = previous_level
420            p_current = False
421        else:
422            p_session = student['studycourse'].current_session
423            p_level = student['studycourse'].current_level
424            p_current = True
[9520]425        academic_session = self._getSessionConfiguration(p_session)
426        if academic_session == None:
[8598]427            return _(u'Session configuration object is not available.'), None
[8676]428        # Determine fee.
[16873]429        if category.startswith('pharmd') \
[14960]430            and student.current_mode == 'special_ft':
431            amount = 80000.0
[16780]432        elif category == 'plag_test':
433            amount = 2500.0
434            if student.is_postgrad:
435                amount = 5000.0
[15108]436        #elif category == 'develop' and student.is_postgrad:
437        #    amount = academic_session.development_fee
[13251]438        elif category == 'bed_allocation':
[17236]439            acco_details = self.getAccommodationDetails(student)
440            p_session = acco_details['booking_session']
441            p_item = acco_details['bt']
[15268]442            desired_hostel = student['accommodation'].desired_hostel
[15314]443            if not desired_hostel:
444                return _(u'Select your favoured hostel first.'), None
445            if desired_hostel and desired_hostel != 'no':
[15268]446                p_item = u'%s (%s)' % (p_item, desired_hostel)
[13251]447            amount = academic_session.booking_fee
[15002]448            if student.is_postgrad:
449                amount += 500
[13251]450        elif category == 'hostel_maintenance':
451            amount = 0.0
[17236]452            booking_session = grok.getSite()['hostels'].accommodation_session
453            bedticket = student['accommodation'].get(str(booking_session), None)
[13500]454            if bedticket is not None and bedticket.bed is not None:
[13251]455                p_item = bedticket.bed_coordinates
[17236]456                p_session = booking_session
[13251]457                if bedticket.bed.__parent__.maint_fee > 0:
458                    amount = bedticket.bed.__parent__.maint_fee
459                else:
460                    # fallback
461                    amount = academic_session.maint_fee
462            else:
[13508]463                return _(u'No bed allocated.'), None
[13251]464        #elif category == 'hostel_application':
465        #    amount = 1000.0
466        #elif category.startswith('tempmaint'):
467        #    if not self._hostelApplicationPaymentMade(
468        #        student, student.current_session):
469        #        return _(
470        #            'You have not yet paid the hostel application fee.'), None
471        #    if category == 'tempmaint_1':
472        #        amount = 8150.0
473        #    elif category == 'tempmaint_2':
474        #        amount = 12650.0
475        #    elif category == 'tempmaint_3':
476        #        amount = 9650.0
[7151]477        elif category == 'clearance':
[9796]478            p_item = student.certcode
479            if p_item is None:
[8598]480                return _('Study course data are incomplete.'), None
[17606]481            if student.is_jupeb:
[14897]482                amount = 50000.0
483            elif student.faccode.startswith('FCETA'):
[13869]484                # ASABA and AKOKA
[14932]485                amount = 35000.0
[17112]486            elif student.depcode == 'DMIC':
487                amount = 70000.0
[17361]488            elif student.faccode in ('BMS', 'MED', 'DEN') \
489                and not student.is_postgrad:
[14897]490                amount = 80000.0
[15574]491            elif student.faccode == 'DCOEM':
492                return _('Acceptance fee payment not necessary.'), None
[11479]493            else:
[14897]494                amount = 60000.0
[17975]495        elif student.is_jupeb:
[17963]496            try:
497                certificate = student['studycourse'].certificate
498                p_item = certificate.code
499            except (AttributeError, TypeError):
500                return _('Study course data are incomplete.'), None
[17975]501            if student.state == CLEARED and category == 'schoolfee':
502                amount = 220000.0
503            if student.state == CLEARED and category == 'schoolfee_1':
504                amount = 110000.0
505            elif category == 'secondinstall':
506                amount = 110000.0
[7151]507        elif category == 'schoolfee':
[8598]508            try:
509                certificate = student['studycourse'].certificate
510                p_item = certificate.code
511            except (AttributeError, TypeError):
512                return _('Study course data are incomplete.'), None
[17457]513            try:
514                if student.entry_session < 2017:
515                    schoolfees_dict = SCHOOLFEES[12][p_item]
516                elif student.entry_session < 2020:
517                    schoolfees_dict = SCHOOLFEES[17][p_item]
518                elif student.entry_session < 2022:
519                    schoolfees_dict = SCHOOLFEES[20][p_item]
[17707]520                elif student.entry_session < 2023:
521                    schoolfees_dict = SCHOOLFEES[22][p_item]
[17930]522                elif student.entry_session < 2024:
523                    schoolfees_dict = SCHOOLFEES[23][p_item]
[17457]524                else:
[17930]525                    schoolfees_dict = SCHOOLFEES[24][p_item]
[17457]526            except KeyError:
527                return _('School fee not yet fixed: p_item = %s' % p_item), None
[9152]528            if previous_session:
[9520]529                # Students can pay for previous sessions in all workflow states.
530                # Fresh students are excluded by the update method of the
531                # PreviousPaymentAddFormPage.
[9157]532                if previous_session == student['studycourse'].entry_session:
[9152]533                    if student.is_foreigner:
[17457]534                        amount = schoolfees_dict['initial_foreigner']
[9152]535                    else:
[17457]536                        amount = schoolfees_dict['initial']
[9006]537                else:
[9152]538                    if student.is_foreigner:
[17457]539                        amount = schoolfees_dict['returning_foreigner']
[9152]540                    else:
[17457]541                        amount = schoolfees_dict['returning']
[9152]542            else:
543                if student.state == CLEARED:
544                    if student.is_foreigner:
[17457]545                        amount = schoolfees_dict['initial_foreigner']
[9152]546                    else:
[17457]547                        amount = schoolfees_dict['initial']
[14858]548                elif student.state == PAID and student.is_postgrad:
[9513]549                    p_session += 1
[9520]550                    academic_session = self._getSessionConfiguration(p_session)
551                    if academic_session == None:
[9513]552                        return _(u'Session configuration object is not available.'), None
553                    if student.is_foreigner:
[17457]554                        amount = schoolfees_dict['returning_foreigner']
[9513]555                    else:
[17457]556                        amount = schoolfees_dict['returning']
[9152]557                elif student.state == RETURNING:
558                    # In case of returning school fee payment the payment session
559                    # and level contain the values of the session the student
560                    # has paid for.
561                    p_session, p_level = self.getReturningData(student)
[9520]562                    academic_session = self._getSessionConfiguration(p_session)
563                    if academic_session == None:
[9152]564                        return _(u'Session configuration object is not available.'), None
[9570]565
[9520]566                    # Students are only allowed to pay for the next session
567                    # if current session payment has really been made,
568                    # i.e. payment object exists and is paid.
[9570]569                    #if not self._paymentMade(
570                    #    student, student.current_session):
571                    #    return _('You have not yet paid your current/active' +
572                    #             ' session. Please use the previous session' +
573                    #             ' payment form first.'), None
574
[9152]575                    if student.is_foreigner:
[17457]576                        amount = schoolfees_dict['returning_foreigner']
[9152]577                    else:
[17457]578                        amount = schoolfees_dict['returning']
[14960]579                # PHARMD school fee amount is fixed and previously paid
580                # installments in current session are deducted.
[15363]581                if student.current_mode == 'special_ft' \
582                    and student.state in (RETURNING, CLEARED):
583                    if student.is_foreigner:
584                        amount = 260000.0 - self._pharmdInstallments(student)
585                    else:
586                        amount = 160000.0 - self._pharmdInstallments(student)
[17457]587            try:
588                amount = float(amount)
589            except ValueError:
590                return _(u'School fee not yet fixed: p_item = %s' % p_item), None
[9006]591            # Give 50% school fee discount to staff members.
592            if student.is_staff:
593                amount /= 2
[17979]594            # Add additional school fees
595            if student.state == CLEARED and getattr(certificate, 'school_fee_3'):
596                amount += getattr(certificate, 'school_fee_3')
597            elif student.state == PAID and student.is_postgrad and getattr(
598                                                    certificate, 'school_fee_4'):
599                amount += getattr(certificate, 'school_fee_4')
600            elif student.state == RETURNING and getattr(
601                                                    certificate, 'school_fee_4'):
602                amount += getattr(certificate, 'school_fee_4')
[16873]603        else:
604            fee_name = category + '_fee'
605            amount = getattr(academic_session, fee_name, 0.0)
[8598]606        if amount in (0.0, None):
[9520]607            return _('Amount could not be determined.'), None
[8676]608        # Add session specific penalty fee.
609        if category == 'schoolfee' and student.is_postgrad:
610            amount += academic_session.penalty_pg
[15108]611            amount += academic_session.development_fee
[13757]612        elif category == 'schoolfee' and student.current_mode == ('ug_ft'):
[13756]613            amount += academic_session.penalty_ug_ft
[13757]614        elif category == 'schoolfee' and student.current_mode == ('ug_pt'):
[13756]615            amount += academic_session.penalty_ug_pt
[13998]616        elif category == 'schoolfee' and student.current_mode == ('ug_sw'):
617            amount += academic_session.penalty_sw
[14717]618        elif category == 'schoolfee' and student.current_mode in (
619            'dp_ft', 'dp_pt'):
620            amount += academic_session.penalty_dp
[9727]621        if category.startswith('tempmaint'):
622            p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category]
623            p_item = unicode(p_item)
624            # Now we change the category because tempmaint payments
[12566]625            # will be obsolete when Uniben returns to Kofa bed allocation.
[9727]626            category = 'hostel_maintenance'
[8676]627        # Create ticket.
[15320]628        if self.samePaymentMade(student, category, p_item, p_session):
[11644]629            return _('This type of payment has already been made.'), None
[11459]630        if self._isPaymentDisabled(p_session, category, student):
[13814]631            return _('This category of payments has been disabled.'), None
[8715]632        payment = createObject(u'waeup.StudentOnlinePayment')
[8950]633        timestamp = ("%d" % int(time()*10000))[1:]
[8598]634        payment.p_id = "p%s" % timestamp
635        payment.p_category = category
636        payment.p_item = p_item
637        payment.p_session = p_session
638        payment.p_level = p_level
[9152]639        payment.p_current = p_current
[8598]640        payment.amount_auth = amount
641        return None, payment
[7621]642
[14588]643    def warnCreditsOOR(self, studylevel, course=None):
[9831]644        studycourse = studylevel.__parent__
645        certificate = getattr(studycourse,'certificate', None)
646        current_level = studycourse.current_level
647        if None in (current_level, certificate):
[14588]648            return
[16438]649        if studylevel.__parent__.previous_verdict == 'R':
650            return
[9831]651        end_level = certificate.end_level
[15840]652        if studylevel.student.faccode in (
653            'MED', 'DEN', 'BMS') and studylevel.level == 200:
654            limit = 61
655        elif current_level >= end_level:
[17912]656            if studycourse.current_verdict == 'R':
657                limit = 999
658            else:
659                limit = 51
[14588]660        else:
661            limit = 50
662        if course and studylevel.total_credits + course.credits > limit:
663            return _('Maximum credits exceeded.')
664        elif studylevel.total_credits > limit:
665            return _('Maximum credits exceeded.')
666        return
[9831]667
[16406]668    def warnCourseAlreadyPassed(self, studylevel, course):
669        """Return message if course has already been passed at
670        previous levels.
671        """
[16413]672
673        # med: we may need to put this matter on hold and allow
674        # all the students to register.
675        return False
676
[16406]677        previous_verdict = studylevel.__parent__.previous_verdict
678        if previous_verdict in ('C', 'M'):
679            return False
680        for slevel in studylevel.__parent__.values():
681            for cticket in slevel.values():
682                if cticket.code == course.code \
683                    and cticket.total_score >= cticket.passmark:
684                    return _('Course has already been passed at previous level.')
685        return False
686
[11773]687    def clearance_disabled_message(self, student):
688        if student.is_postgrad:
689            return None
690        try:
691            session_config = grok.getSite()[
692                'configuration'][str(student.current_session)]
693        except KeyError:
694            return _('Session configuration object is not available.')
695        if not session_config.clearance_enabled:
696            return _('Clearance is disabled for this session.')
697        return None
698
[16100]699    def renderPDFTranscript(self, view, filename='transcript.pdf',
700                  student=None,
701                  studentview=None,
702                  note=None,
703                  signatures=(),
704                  sigs_in_footer=(),
705                  digital_sigs=(),
706                  show_scans=True, topMargin=1.5,
707                  omit_fields=(),
708                  tableheader=None,
709                  no_passport=False,
710                  save_file=False):
711        """Render pdf slip of a transcripts.
712        """
713        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
714        # XXX: tell what the different parameters mean
715        style = getSampleStyleSheet()
716        creator = self.getPDFCreator(student)
717        data = []
718        doc_title = view.label
719        author = '%s (%s)' % (view.request.principal.title,
720                              view.request.principal.id)
721        footer_text = view.label.split('\n')
722        if len(footer_text) > 2:
723            # We can add a department in first line
724            footer_text = footer_text[1]
725        else:
726            # Only the first line is used for the footer
727            footer_text = footer_text[0]
728        if getattr(student, 'student_id', None) is not None:
729            footer_text = "%s - %s - " % (student.student_id, footer_text)
730
731        # Insert student data table
732        if student is not None:
733            #bd_translation = trans(_('Base Data'), portal_language)
734            #data.append(Paragraph(bd_translation, HEADING_STYLE))
735            data.append(render_student_data(
736                studentview, view.context,
737                omit_fields, lang=portal_language,
738                slipname=filename,
739                no_passport=no_passport))
740
741        transcript_data = view.context.getTranscriptData()
742        levels_data = transcript_data[0]
743
744        contextdata = []
745        f_label = trans(_('Course of Study:'), portal_language)
746        f_label = Paragraph(f_label, ENTRY1_STYLE)
747        f_text = formatted_text(view.context.certificate.longtitle)
748        f_text = Paragraph(f_text, ENTRY1_STYLE)
749        contextdata.append([f_label,f_text])
750
751        f_label = trans(_('Faculty:'), portal_language)
752        f_label = Paragraph(f_label, ENTRY1_STYLE)
753        f_text = formatted_text(
754            view.context.certificate.__parent__.__parent__.__parent__.longtitle)
755        f_text = Paragraph(f_text, ENTRY1_STYLE)
756        contextdata.append([f_label,f_text])
757
758        f_label = trans(_('Department:'), portal_language)
759        f_label = Paragraph(f_label, ENTRY1_STYLE)
760        f_text = formatted_text(
761            view.context.certificate.__parent__.__parent__.longtitle)
762        f_text = Paragraph(f_text, ENTRY1_STYLE)
763        contextdata.append([f_label,f_text])
764
765        f_label = trans(_('Entry Session:'), portal_language)
766        f_label = Paragraph(f_label, ENTRY1_STYLE)
767        f_text = formatted_text(
768            view.session_dict.get(view.context.entry_session))
769        f_text = Paragraph(f_text, ENTRY1_STYLE)
770        contextdata.append([f_label,f_text])
771
772        f_label = trans(_('Final Session:'), portal_language)
773        f_label = Paragraph(f_label, ENTRY1_STYLE)
774        f_text = formatted_text(
775            view.session_dict.get(view.context.current_session))
776        f_text = Paragraph(f_text, ENTRY1_STYLE)
777        contextdata.append([f_label,f_text])
778
779        f_label = trans(_('Entry Mode:'), portal_language)
780        f_label = Paragraph(f_label, ENTRY1_STYLE)
781        f_text = formatted_text(view.studymode_dict.get(
782            view.context.entry_mode))
783        f_text = Paragraph(f_text, ENTRY1_STYLE)
784        contextdata.append([f_label,f_text])
785
786        f_label = trans(_('Final Verdict:'), portal_language)
787        f_label = Paragraph(f_label, ENTRY1_STYLE)
788        f_text = formatted_text(view.studymode_dict.get(
789            view.context.current_verdict))
790        f_text = Paragraph(f_text, ENTRY1_STYLE)
791        contextdata.append([f_label,f_text])
792
793        f_label = trans(_('Cumulative GPA:'), portal_language)
794        f_label = Paragraph(f_label, ENTRY1_STYLE)
795        format_float = getUtility(IKofaUtils).format_float
796        cgpa = format_float(transcript_data[1], 3)
797        if student.state == GRADUATED:
798            f_text = formatted_text('%s (%s)' % (
799                cgpa, self.getClassFromCGPA(transcript_data[1], student)[1]))
800        else:
801            f_text = formatted_text('%s' % cgpa)
[17498]802            if not transcript_data[1]:
803                f_text = formatted_text('No results yet!')
[16100]804        f_text = Paragraph(f_text, ENTRY1_STYLE)
805        contextdata.append([f_label,f_text])
806
807        contexttable = Table(contextdata,style=SLIP_STYLE)
808        data.append(contexttable)
809
[17498]810        if transcript_data[1]:
811            transcripttables = render_transcript_data(
812                view, tableheader, levels_data, lang=portal_language)
813            data.extend(transcripttables)
[16100]814
815        # Insert signatures
816        # XXX: We are using only sigs_in_footer in waeup.kofa, so we
817        # do not have a test for the following lines.
818        if signatures and not sigs_in_footer:
819            data.append(Spacer(1, 20))
820            # Render one signature table per signature to
821            # get date and signature in line.
822            for signature in signatures:
823                signaturetables = get_signature_tables(signature)
824                data.append(signaturetables[0])
825
826        # Insert digital signatures
827        if digital_sigs:
828            data.append(Spacer(1, 20))
829            sigs = digital_sigs.split('\n')
830            for sig in sigs:
831                data.append(Paragraph(sig, NOTE_STYLE))
832
833        view.response.setHeader(
834            'Content-Type', 'application/pdf')
835        try:
836            pdf_stream = creator.create_pdf(
837                data, None, doc_title, author=author, footer=footer_text,
[16906]838                note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin,
839                view=view)
[16100]840        except IOError:
841            view.flash(_('Error in image file.'))
842            return view.redirect(view.url(view.context))
843        if save_file:
844            self._saveTranscriptPDF(student, pdf_stream)
845            return
846        return pdf_stream
847
[14038]848    #: A tuple containing the names of registration states in which changing of
849    #: passport pictures is allowed.
[17814]850    PORTRAIT_CHANGE_STATES = (CLEARANCE, ADMITTED, REQUESTED)
[14038]851
[17807]852    def allowPortraitChange(self, student):
853        """Check if student is allowed to change the portrait file.
854        """
855        if student.is_jupeb:
856            return False
857        if student.state not in self.PORTRAIT_CHANGE_STATES:
858            return False
859        return True
860
[16611]861    #: A tuple containing the names of registration states in which changing of
862    #: scanned signatures is allowed.
[16620]863    SIGNATURE_CHANGE_STATES = (CLEARED, RETURNING, PAID, REGISTERED, VALIDATED, )
[16611]864
[17870]865    def final_clearance_enabled(self, student):
[17875]866        studycourse = student['studycourse']
867        certificate = getattr(studycourse,'certificate',None)
868        current_level = studycourse.current_level
869        if None in (current_level, certificate):
870            return False
871        if student.is_postgrad:
872            return True
873        end_level = certificate.end_level
874        if current_level >= end_level:
875            return True
876        return False
[17870]877
[8441]878    # Uniben prefix
[17145]879    @property
880    def STUDENT_ID_PREFIX(self):
881        if grok.getSite().__name__ == 'uniben-cdl':
882            return u'C'
883        return u'B'
[15980]884
885    STUDENT_EXPORTER_NAMES = (
886            'students',
887            'studentstudycourses',
[16840]888            'studentstudycourses_1',
[15980]889            'studentstudylevels',
[16840]890            #'studentstudylevels_1',
[15980]891            'coursetickets',
[16840]892            #'coursetickets_1',
[15980]893            'studentpayments',
894            'bedtickets',
895            'trimmed',
896            'outstandingcourses',
897            'unpaidpayments',
898            'sfpaymentsoverview',
899            'sessionpaymentsoverview',
900            'studylevelsoverview',
901            'combocard',
902            'bursary',
903            'accommodationpayments',
904            'transcriptdata',
905            'trimmedpayments',
[16390]906            'medicalhistory',
[17915]907            'routingslip',
[17396]908            'nysc',
[15980]909            )
Note: See TracBrowser for help on using the repository browser.