source: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/utils.py @ 14641

Last change on this file since 14641 was 14641, checked in by Henrik Bettermann, 8 years ago

NCE part time weekend, both Deltan and none Deltan, are paying a flat acceptance fee.

  • Property svn:keywords set to Id
File size: 6.8 KB
RevLine 
[10765]1## $Id: utils.py 14641 2017-03-21 13:43: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##
18from time import time
19from zope.component import createObject, getUtility
[14336]20from waeup.kofa.fees import FeeTable
[10765]21from waeup.kofa.interfaces import (IKofaUtils,
[14332]22    ADMITTED, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
[10765]23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[14035]24from kofacustom.coewarri.interfaces import MessageFactory as _
[14336]25from kofacustom.coewarri.interswitch.browser import GATEWAY_AMT
[10765]26
[14333]27
28def local_nonlocal(student):
29    lga = getattr(student, 'lga')
30    if lga and lga.startswith('delta'):
31        return 'local'
32    else:
33        return 'non-local'
34
[14336]35PAYMENT_LEVELS = (100, 110, 200, 210, 300, 310, 400, 410, 500, 999)
36
37FEES_PARAMS = (
38        ('local', 'non-local'),
39        ('nce_ft', 'nce_pt', 'ug_ft'),
40        PAYMENT_LEVELS
41    )
42
43FEES_VALUES = (
44      ( # 100      110      200      210      300      310      400      410     500  999
45        (42000.0, 42000.0, 20600.0, 20600.0, 18100.0, 18100.0,     0.0,     0.0, 0.0, 0.0), # nce_ft
46        (55200.0, 55200.0, 42200.0, 42200.0, 44700.0, 44700.0, 42200.0, 42200.0, 0.0, 0.0), # nce_pt
47        (69200.0, 69200.0, 63100.0, 63100.0, 63100.0, 63100.0, 62100.0, 62100.0, 0.0, 0.0), # ug_ft
48      ), # local
49      ( #
50        (54600.0, 54600.0, 22600.0, 22600.0, 20100.0, 20100.0,     0.0,     0.0, 0.0, 0.0), # nce_ft
51        (55200.0, 55200.0, 42200.0, 42200.0, 44700.0, 44700.0, 42200.0, 42200.0, 0.0, 0.0), # nce_pt
52        (79200.0, 79200.0, 63100.0, 63100.0, 63100.0, 63100.0, 62100.0, 62100.0, 0.0, 0.0), # ug_ft
53      ), # non-local
54    )
55
56SCHOOL_FEES = FeeTable(FEES_PARAMS, FEES_VALUES)
57
[10765]58class CustomStudentsUtils(NigeriaStudentsUtils):
59    """A collection of customized methods.
60
61    """
62
[14333]63    def setPaymentDetails(self, category, student,
[14336]64            previous_session=None, previous_level=None):
[14333]65        """Create a payment ticket and set the payment data of a
66        student for the payment category specified.
67        """
68        p_item = u''
69        amount = 0.0
[14336]70        p_session = student['studycourse'].current_session
71        p_level = student['studycourse'].current_level
72        p_current = True
[14333]73        academic_session = self._getSessionConfiguration(p_session)
[14347]74        if previous_session:
75            return _('Previous session payment not yet implemented.'), None
[14333]76        if academic_session == None:
77            return _(u'Session configuration object is not available.'), None
78        # Determine fee.
[14344]79        if category.startswith('schoolfee'):
[14333]80            try:
81                certificate = student['studycourse'].certificate
82                p_item = certificate.code
83            except (AttributeError, TypeError):
84                return _('Study course data are incomplete.'), None
[14336]85            if student.state == RETURNING:
86                # Override p_session and p_level
87                p_session, p_level = self.getReturningData(student)
88                academic_session = self._getSessionConfiguration(p_session)
89                if academic_session == None:
90                    return _(u'Session configuration object '
91                              'is not available.'), None
[14344]92            if p_level in PAYMENT_LEVELS:
93                amount = SCHOOL_FEES.get_fee(
94                    (
95                     local_nonlocal(student),
96                     student.current_mode,
97                     p_level)
98                    )
99            if amount and category in ('schoolfee_1', 'schoolfee_2'):
100                amount /= 2
101            if amount:
102                amount += GATEWAY_AMT
[14333]103        elif category == 'clearance':
104            try:
105                p_item = student['studycourse'].certificate.code
106            except (AttributeError, TypeError):
107                return _('Study course data are incomplete.'), None
[14639]108            if student.entry_mode == 'nce_we_pt':
[14589]109                amount = academic_session.clearance_fee_3
[14639]110            elif student.entry_mode == 'ug_ft':
[14455]111                amount = academic_session.clearance_fee_2
112            else:
113                amount = academic_session.clearance_fee_1
[14641]114            if local_nonlocal(student) == 'non-local'  \
115                and student.entry_mode != 'nce_we_pt':
[14336]116                amount += 5000.0
[14333]117        elif category == 'bed_allocation':
118            p_item = self.getAccommodationDetails(student)['bt']
119            amount = academic_session.booking_fee
120        elif category == 'hostel_maintenance':
121            amount = 0.0
122            bedticket = student['accommodation'].get(
123                str(student.current_session), None)
124            if bedticket is not None and bedticket.bed is not None:
125                p_item = bedticket.bed_coordinates
126                if bedticket.bed.__parent__.maint_fee > 0:
127                    amount = bedticket.bed.__parent__.maint_fee
128                else:
129                    # fallback
130                    amount = academic_session.maint_fee
131            else:
132                return _(u'No bed allocated.'), None
133        elif category == 'transcript':
134            amount = academic_session.transcript_fee
135        elif category == 'transfer':
136            amount = academic_session.transfer_fee
137        elif category == 'late_registration':
138            amount = academic_session.late_registration_fee
139        if amount in (0.0, None):
140            return _('Amount could not be determined.'), None
141        if self.samePaymentMade(student, category, p_item, p_session):
142            return _('This type of payment has already been made.'), None
143        if self._isPaymentDisabled(p_session, category, student):
144            return _('This category of payments has been disabled.'), None
145        payment = createObject(u'waeup.StudentOnlinePayment')
146        timestamp = ("%d" % int(time()*10000))[1:]
147        payment.p_id = "p%s" % timestamp
148        payment.p_category = category
149        payment.p_item = p_item
150        payment.p_session = p_session
151        payment.p_level = p_level
152        payment.p_current = p_current
153        payment.amount_auth = amount
154        return None, payment
155
[14036]156    # prefix
[14332]157    STUDENT_ID_PREFIX = u'R'
158
159    PORTRAIT_CHANGE_STATES = (
160        ADMITTED, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
Note: See TracBrowser for help on using the repository browser.