source: main/kofacustom.ekodisco/trunk/src/kofacustom/ekodisco/students/utils.py @ 17935

Last change on this file since 17935 was 11456, checked in by Henrik Bettermann, 11 years ago

Apply _isPaymentDisabled method.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: utils.py 11456 2014-02-27 11:01:18Z 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##
18from time import time
19from zope.component import createObject, getUtility
20from waeup.kofa.interfaces import (IKofaUtils,
21    CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
22from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
23from kofacustom.ekodisco.interfaces import MessageFactory as _
24
25class CustomStudentsUtils(NigeriaStudentsUtils):
26    """A collection of customized methods.
27
28    """
29
30    # refix
31    STUDENT_ID_PREFIX = u'X'
32
33    def setPaymentDetails(self, category, student,
34            previous_session, previous_level):
35        """Create Payment object and set the payment data of a student for
36        the payment category specified.
37
38        """
39        p_item = u''
40        amount = 0.0
41        if previous_session:
42            if previous_session < student['studycourse'].entry_session:
43                return _('The previous session must not fall below '
44                         'your entry session.'), None
45            if category == 'schoolfee':
46                # School fee is always paid for the following session
47                if previous_session > student['studycourse'].current_session:
48                    return _('This is not a previous session.'), None
49            else:
50                if previous_session > student['studycourse'].current_session - 1:
51                    return _('This is not a previous session.'), None
52            p_session = previous_session
53            p_level = previous_level
54            p_current = False
55        else:
56            p_session = student['studycourse'].current_session
57            p_level = student['studycourse'].current_level
58            p_current = True
59        academic_session = self._getSessionConfiguration(p_session)
60        if academic_session == None:
61            return _(u'Session configuration object is not available.'), None
62        # Determine fee.
63        if category == 'schoolfee':
64            try:
65                certificate = student['studycourse'].certificate
66                p_item = certificate.code
67            except (AttributeError, TypeError):
68                return _('Contract data are incomplete.'), None
69            amount = getattr(certificate, 'school_fee_1', 0.0)
70        else:
71            amount = 999.0
72            p_item = u'To be set'
73        if amount in (0.0, None):
74            return _('Amount could not be determined.'), None
75        for key in student['payments'].keys():
76            ticket = student['payments'][key]
77            if ticket.p_state == 'paid' and\
78               ticket.p_category == category and \
79               ticket.p_item == p_item and \
80               ticket.p_session == p_session:
81                  return _('This type of payment has already been made.'), None
82        if self._isPaymentDisabled(p_session, category, student):
83            return _('Payment temporarily disabled.'), None
84        payment = createObject(u'waeup.StudentOnlinePayment')
85        timestamp = ("%d" % int(time()*10000))[1:]
86        payment.p_id = "p%s" % timestamp
87        payment.p_category = category
88        payment.p_item = p_item
89        payment.p_session = p_session
90        payment.p_level = p_level
91        payment.p_current = p_current
92        payment.amount_auth = amount
93        return None, payment
Note: See TracBrowser for help on using the repository browser.