source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/utils.py @ 9111

Last change on this file since 9111 was 8953, checked in by Henrik Bettermann, 12 years ago

Timestanp for p_id in tenth of milliseconds.

  • Property svn:keywords set to Id
File size: 5.2 KB
RevLine 
[7419]1## $Id: utils.py 8953 2012-07-09 10:45:16Z 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
[8599]19from time import time
20from zope.component import createObject
[8475]21from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
[8834]22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]23from waeup.kofa.accesscodes import create_accesscode
[8460]24from waeup.fceokene.interfaces import MessageFactory as _
[6902]25
[8834]26class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]27    """A collection of customized methods.
28
29    """
30
[8270]31    def getReturningData(self, student):
32        """ This method defines what happens after school fee payment
[8319]33        of returning students depending on the student's senate verdict.
[8270]34        """
[8319]35        prev_level = student['studycourse'].current_level
36        cur_verdict = student['studycourse'].current_verdict
37        if cur_verdict in ('A','B','L','M','N','Z',):
38            # Successful student
39            new_level = divmod(int(prev_level),100)[0]*100 + 100
40        elif cur_verdict == 'C':
41            # Student on probation
42            new_level = int(prev_level) + 10
43        else:
44            # Student is somehow in an undefined state.
45            # Level has to be set manually.
46            new_level = prev_level
[8270]47        new_session = student['studycourse'].current_session + 1
48        return new_session, new_level
49
[8599]50    def setPaymentDetails(self, category, student):
51        """Create Payment object and set the payment data of a student for
52        the payment category specified.
53
54        """
[8306]55        details = {}
[8599]56        p_item = u''
57        amount = 0.0
58        error = u''
59        p_session = student['studycourse'].current_session
60        p_level = student['studycourse'].current_level
61        session = str(p_session)
[7151]62        try:
63            academic_session = grok.getSite()['configuration'][session]
64        except KeyError:
[8599]65            return _(u'Session configuration object is not available.'), None
[7151]66        if category == 'transfer':
[8599]67            amount = academic_session.transfer_fee
[7151]68        elif category == 'gown':
[8599]69            amount = academic_session.gown_fee
[7151]70        elif category == 'bed_allocation':
[8599]71            amount = academic_session.booking_fee
[7151]72        elif category == 'hostel_maintenance':
[8599]73            amount = academic_session.maint_fee
[7151]74        elif category == 'clearance':
[8599]75            try:
76                p_item = student['studycourse'].certificate.code
77            except (AttributeError, TypeError):
78                return _('Study course data are incomplete.'), None
79            if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
[8294]80                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
[8599]81                amount = 17250.0
[8294]82            else:
[8599]83                amount = 34250.0
[7151]84        elif category == 'schoolfee':
[8599]85            try:
86                certificate = student['studycourse'].certificate
87                p_item = certificate.code
88            except (AttributeError, TypeError):
89                return _('Study course data are incomplete.'), None
90            if student.state == CLEARED:
91                amount = getattr(certificate, 'school_fee_1', 0.0)
92            elif student.state == RETURNING:
[8306]93                # In case of returning school fee payment the payment session
94                # and level contain the values of the session the student
95                # has paid for.
[8599]96                p_session, p_level = self.getReturningData(student)
97                amount = getattr(certificate, 'school_fee_2', 0.0)
98            elif student.is_postgrad and student.state == PAID:
[8475]99                # Returning postgraduate students also pay for the next session
100                # but their level always remains the same.
[8599]101                p_session += 1
102                amount = getattr(certificate, 'school_fee_2', 0.0)
103        if amount in (0.0, None):
104            return _(u'Amount could not be determined.'), None
105        for key in student['payments'].keys():
106            ticket = student['payments'][key]
107            if ticket.p_state == 'paid' and\
108               ticket.p_category == category and \
109               ticket.p_item == p_item and \
110               ticket.p_session == p_session:
111                  return _('This type of payment has already been made.'), None
[8713]112        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]113        timestamp = ("%d" % int(time()*10000))[1:]
[8599]114        payment.p_id = "p%s" % timestamp
115        payment.p_category = category
116        payment.p_item = p_item
117        payment.p_session = p_session
118        payment.p_level = p_level
119        payment.amount_auth = amount
120        return None, payment
[7621]121
[8460]122    # FCEOkene prefix
[8528]123    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.