source: main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py @ 13350

Last change on this file since 13350 was 13348, checked in by Henrik Bettermann, 10 years ago

Move PORTRAIT_CHANGE_STATES to CustomStudentsUtils?.

  • Property svn:keywords set to Id
File size: 8.4 KB
RevLine 
[7419]1## $Id: utils.py 13348 2015-10-26 09:41:53Z 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##
[7151]18import grok
[8600]19from time import time
20from zope.component import createObject
[10922]21from waeup.kofa.interfaces import (
[13348]22    ADMITTED, CLEARED, RETURNING, PAID, academic_sessions_vocab)
[8823]23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]24from waeup.kofa.accesscodes import create_accesscode
[10922]25from waeup.kofa.students.utils import trans
[8444]26from waeup.aaue.interfaces import MessageFactory as _
[6902]27
[8823]28class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]29    """A collection of customized methods.
30
31    """
32
[13348]33    PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING)
34
[10641]35    gpa_boundaries = ((1, 'FRNS'),
36                      (1.5, 'Pass'),
37                      (2.4, '3rd Class Honours'),
38                      (3.5, '2nd Class Honours Lower Division'),
39                      (4.5, '2nd Class Honours Upper Division'),
40                      (5, '1st Class Honours'))
41
[11596]42    def constructMatricNumber(self, student):
43        next_integer = grok.getSite()['configuration'].next_matric_integer
44        if next_integer == 0:
45            return None
[11593]46        faccode = student.faccode
47        depcode = student.depcode
48        year = unicode(student.entry_session)[2:]
[11605]49        if student.current_mode in ('ug_pt', 'de_pt') \
50            and student.state in (PAID, ) \
51            and student.is_fresh:
[12975]52            return None, "PTP/%s/%s/%s/%05d" % (
53                faccode, depcode, year, next_integer)
54
[11596]55        #if student.current_mode in ('pg_ft', 'pg_pt'):
[12975]56        #    return None, "SPS/%s/%s/%s/%05d" % (
57        #    faccode, depcode, year, next_integer)
[11596]58        #if student.current_mode in ('dp_ft', 'dp_pt'):
[12975]59        #    return None, "DIP/%s/%s/%s/%05d" % (
60        #    faccode, depcode, year, next_integer)
[11596]61        #if student.current_mode == 'found':
[12975]62        #    return _(
63        #    'Foundation programme students don\'t have matric number.'), None
[11620]64        #return None, "%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
[12975]65
[11620]66        return _('Matriculation number cannot be set.'), None
[11593]67
[8270]68    def getReturningData(self, student):
69        """ This method defines what happens after school fee payment
[8319]70        of returning students depending on the student's senate verdict.
[8270]71        """
[8319]72        prev_level = student['studycourse'].current_level
73        cur_verdict = student['studycourse'].current_verdict
74        if cur_verdict in ('A','B','L','M','N','Z',):
75            # Successful student
76            new_level = divmod(int(prev_level),100)[0]*100 + 100
77        elif cur_verdict == 'C':
78            # Student on probation
79            new_level = int(prev_level) + 10
80        else:
81            # Student is somehow in an undefined state.
82            # Level has to be set manually.
83            new_level = prev_level
[8270]84        new_session = student['studycourse'].current_session + 1
85        return new_session, new_level
86
[9154]87    def setPaymentDetails(self, category, student,
88            previous_session=None, previous_level=None):
[8600]89        """Create Payment object and set the payment data of a student for
90        the payment category specified.
91
92        """
[8306]93        details = {}
[8600]94        p_item = u''
95        amount = 0.0
96        error = u''
[9154]97        if previous_session:
98            return _('Previous session payment not yet implemented.'), None
[8600]99        p_session = student['studycourse'].current_session
100        p_level = student['studycourse'].current_level
[9154]101        p_current = True
[9527]102        academic_session = self._getSessionConfiguration(p_session)
103        if academic_session == None:
[8600]104            return _(u'Session configuration object is not available.'), None
[8677]105        # Determine fee.
[7151]106        if category == 'transfer':
[8600]107            amount = academic_session.transfer_fee
[10467]108        elif category == 'transcript':
109            amount = academic_session.transcript_fee
[7151]110        elif category == 'gown':
[8600]111            amount = academic_session.gown_fee
[7151]112        elif category == 'bed_allocation':
[8600]113            amount = academic_session.booking_fee
[7151]114        elif category == 'hostel_maintenance':
[8600]115            amount = academic_session.maint_fee
[7151]116        elif category == 'clearance':
[11653]117            if student.faccode == 'FP':
118                amount = academic_session.clearance_fee_fp
119            else:
120                amount = academic_session.clearance_fee
[8753]121            p_item = student['studycourse'].certificate.code
[11004]122        elif category == 'late_registration':
[13035]123            amount = academic_session.late_registration_fee
[9905]124        elif category == 'schoolfee':
[8600]125            try:
[8753]126                certificate = student['studycourse'].certificate
127                p_item = certificate.code
[8600]128            except (AttributeError, TypeError):
129                return _('Study course data are incomplete.'), None
[8753]130            if student.state == CLEARED:
[10922]131                if student.faccode == 'FP':
[11653]132                    amount = academic_session.school_fee_3
[10930]133                else:
[11624]134                    amount = academic_session.school_fee_1
[8961]135            elif student.state == RETURNING or\
136                (student.is_postgrad and student.state == PAID):
[9527]137                academic_session = self._getSessionConfiguration(p_session)
138                if academic_session == None:
139                    return _(u'Session configuration object is not available.'), None
[8961]140                if student.state == RETURNING:
141                    p_session, p_level = self.getReturningData(student)
142                else:
143                    # Returning postgraduate students also pay for the
144                    # next session but their level always remains the same.
145                    p_session += 1
146                try:
147                    academic_session = grok.getSite()[
148                        'configuration'][str(p_session)]
149                except KeyError:
150                    return _(u'Session configuration object is not available.'), None
[11624]151                amount = academic_session.school_fee_2
[8600]152            else:
[8753]153                return _('Wrong state.'), None
[8600]154        if amount in (0.0, None):
155            return _(u'Amount could not be determined.'), None
[8677]156        # Add session specific penalty fee.
[9905]157        if category == 'schoolfee' and student.is_postgrad:
[8677]158            amount += academic_session.penalty_pg
[9905]159        elif category == 'schoolfee':
[8677]160            amount += academic_session.penalty_ug
161        # Create ticket.
[8600]162        for key in student['payments'].keys():
163            ticket = student['payments'][key]
164            if ticket.p_state == 'paid' and\
165               ticket.p_category == category and \
166               ticket.p_item == p_item and \
167               ticket.p_session == p_session:
168                  return _('This type of payment has already been made.'), None
[11455]169        if self._isPaymentDisabled(p_session, category, student):
170            return _('Payment temporarily disabled.'), None
[8712]171        payment = createObject(u'waeup.StudentOnlinePayment')
[8954]172        timestamp = ("%d" % int(time()*10000))[1:]
[8600]173        payment.p_id = "p%s" % timestamp
174        payment.p_category = category
175        payment.p_item = p_item
176        payment.p_session = p_session
177        payment.p_level = p_level
[9154]178        payment.p_current = p_current
[8600]179        payment.amount_auth = amount
180        return None, payment
[7621]181
[10922]182    def _admissionText(self, student, portal_language):
183        inst_name = grok.getSite()['configuration'].name
184        entry_session = student['studycourse'].entry_session
185        entry_session = academic_sessions_vocab.getTerm(entry_session).title
186        text = trans(_(
[10953]187            'This is to inform you that you have been offered provisional'
188            ' admission into ${a} for the ${b} academic session as follows:',
[10922]189            mapping = {'a': inst_name, 'b': entry_session}),
190            portal_language)
191        return text
192
[10051]193    def maxCredits(self, studylevel):
194        """Return maximum credits.
195
196        """
197        return 48
198
[8444]199    # AAUE prefix
200    STUDENT_ID_PREFIX = u'E'
Note: See TracBrowser for help on using the repository browser.