source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/utils.py @ 16241

Last change on this file since 16241 was 16166, checked in by Henrik Bettermann, 4 years ago

Fix setPaymentDetails.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: utils.py 16166 2020-07-15 06:25:56Z 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##
18"""General helper functions and utilities for the application section.
19"""
20
21import grok
22from time import time
23from kofacustom.nigeria.applicants.utils import NigeriaApplicantsUtils
24from waeup.kofa.applicants.workflow import (INITIALIZED,
25    STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED)
26from kofacustom.iuokada.applicants.interfaces import DESTINATION_COST
27from kofacustom.iuokada.interfaces import MessageFactory as _
28
29
30
31class ApplicantsUtils(NigeriaApplicantsUtils):
32    """A collection of parameters and methods subject to customization.
33    """
34
35    ADDITIONAL_FILES = (
36                 ('First Sitting Result','fst_sit_scan.pdf'),
37                 ('Second Sitting Result','scd_sit_scan.pdf'),
38                 ('Higher Qualification Result','hq_scan.pdf'),
39                 ('Advanced Level Result','alr_scan.pdf'),
40                 ('JAMB Result','jamb.pdf'),
41                 ('Statement of Result','res_stat.pdf'),
42                 ('NYSC Certificate','nysc.pdf'),
43                 )
44
45    APP_TYPES_DICT = {
46        'pude': ['Post-UDE Screening', 'PUDE'],
47        'sandwich': ['Part-Time Degree in Education', 'SAND'],
48        'pt': ['Part-Time Degree Programmes', 'PTP'],
49        'putme': ['Post-UTME Screening Exercise', 'PUTME'],
50        'app': ['General Studies', 'APP'],
51        'ct': ['Certificate Programmes', 'CTP'],
52        'dp': ['Diploma Programmes', 'DPP'],
53        'pgft': ['Postgraduate Full-Time Programmes', 'PG'],
54        'pgpt': ['Postgraduate Part-Time Programmes', 'PG'],
55        'pre': ['Pre-Degree Studies', 'PRE'],
56        'cbt': ['CBT Practice Test', 'CBT'],
57        'ase': ['Admission Screening Exercise', 'ASE'], # successor of putme
58        'pg': ['Postgraduate Programmes', 'PG'],
59        'ug': ['Undergraduate Programmes', 'UG'],
60        'tscf': ['Transcript Application (without student record)', 'TRF'],
61        'tscs': ['Transcript Application (with student record)', 'TRS'],
62        }
63
64    SEPARATORS_DICT = {
65        'form.applicant_id': _(u'Base Data'),
66        'form.course1': _(u'Programmes/Courses Desired'),
67        'form.hq_type': _(u'Highest Educational Record (Degrees, Diplomas etc.)'),
68        'form.presently': _(u'Course or Programme Presently Attending'),
69        'form.nysc_year': _(u'NYSC Information/Exemption Certificate'),
70        'form.employer': _(u'Employment History'),
71        'form.jamb_subjects': _(u'JAMB Data (All Applicants)'),
72        'form.jamb_subjects_list': _(u'JAMB Data (All Applicants)'),
73        'form.notice': _(u'Application Process Information'),
74        'form.pp_school': _(u'Post Primary School Qualification'),
75        'form.presently_inst': _(u'Presently attending a course or programme'),
76        'form.fst_sit_fname': _(u'First Sitting Record'),
77        'form.scd_sit_fname': _(u'Second Sitting Record'),
78        'form.referees': _(u'Referees (will be automatically invited by email after final submission)'),
79        'form.parents_name': _(u'Parents / Guardian'),
80        }
81
82    def sortCertificates(self, context, resultset):
83        """Sort already filtered certificates in `AppCatCertificateSource`.
84        """
85        resultlist = sorted(resultset, key=lambda
86            value: value.__parent__.__parent__.__parent__.code +
87            value.__parent__.__parent__.code +
88            value.code)
89        curr_course = context.course1
90        if curr_course is not None and curr_course not in resultlist:
91            resultlist = [curr_course,] + resultlist
92        return resultlist
93
94    def getCertTitle(self, context, value):
95        """Compose the titles in `AppCatCertificateSource`.
96        """
97        try: title = "%s / %s / %s (%s)" % (
98            value.__parent__.__parent__.__parent__.title,
99            value.__parent__.__parent__.title,
100            value.title, value.code)
101        except AttributeError:
102            title = "NA / %s (%s)" % (value.title, value.code)
103        return title
104
105    def setPaymentDetails(self, container, payment, applicant):
106        """Set the payment data of an applicant.
107        In contrast to its `StudentsUtils` counterpart, the payment ticket
108        must exist and is an argument of this method.
109        """
110        timestamp = ("%d" % int(time()*10000))[1:]
111        session = str(container.year)
112        try:
113            session_config = grok.getSite()['configuration'][session]
114        except KeyError:
115            return _(u'Session configuration object is not available.')
116        payment.p_id = "p%s" % timestamp
117        payment.p_item = container.title
118        payment.p_session = container.year
119        payment.amount_auth = 0.0
120        if applicant.special:
121            if applicant.special_application:
122                fee_name = applicant.special_application + '_fee'
123                payment.amount_auth = getattr(session_config, fee_name, None)
124                if payment.amount_auth in (0.0, None):
125                    return _('Amount could not be determined.')
126                payment.p_category = applicant.special_application
127            return
128        elif applicant.container_code.startswith('tsc'):
129            cost = DESTINATION_COST[applicant.charge][1]
130            payment.amount_auth = applicant.no_copies * cost
131            payment.p_category = 'transcript'
132            return
133        else:
134            payment.p_category = 'application'
135            container_fee = container.application_fee
136            if not container_fee:
137                return _('Amount could not be determined.')
138            payment.amount_auth = container_fee
139        return
Note: See TracBrowser for help on using the repository browser.