source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/export.py @ 17421

Last change on this file since 17421 was 16706, checked in by Henrik Bettermann, 3 years ago

Customize SchoolFeePaymentsOverviewExporter?.

  • Property svn:keywords set to Id
File size: 4.8 KB
RevLine 
[11543]1## $Id: export.py 16706 2021-11-08 18:52:17Z 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"""Exporters for student related stuff.
19"""
[16706]20from waeup.kofa.students.export import (
21    SchoolFeePaymentsOverviewExporter, StudentExporter)
[15563]22from kofacustom.iuokada.students.interfaces import (
[11545]23    ICustomStudent,
24    ICustomStudentStudyCourse,
25    ICustomStudentStudyLevel,
26    ICustomCourseTicket,
[11543]27    ICustomStudentOnlinePayment)
28from kofacustom.nigeria.students.export import (
[12084]29    NigeriaStudentExporter,
[11545]30    NigeriaStudentStudyCourseExporter,
31    NigeriaStudentStudyLevelExporter,
32    NigeriaCourseTicketExporter,
[12878]33    NigeriaStudentPaymentExporter)
[11543]34from waeup.kofa.utils.helpers import iface_names
35
[12084]36class CustomStudentExporter(NigeriaStudentExporter):
[11543]37    """Exporter for Students.
38    """
39
40    fields = tuple(sorted(iface_names(
41        ICustomStudent, omit=['loggerInfo']))) + (
42        'password', 'state', 'history', 'certcode', 'is_postgrad',
[16403]43        'current_level', 'current_session', 'entry_session')
[11543]44
45class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter):
46    """Exporter for StudentStudyCourses.
47    """
48
49    fields = tuple(
50        sorted(iface_names(ICustomStudentStudyCourse))) + ('student_id',)
51
[11545]52class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
53    """Exporter for StudentStudyLevels.
54    """
55    #: Fieldnames considered by this exporter
56    fields = tuple(sorted(iface_names(
[12878]57        ICustomStudentStudyLevel))) + (
[11545]58        'student_id', 'number_of_tickets','certcode')
59
[11543]60class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
61    """Exporter for CourseTickets.
62    """
63
64    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
65        ['level', 'code', 'level_session'])) + ('student_id',
66        'certcode', 'display_fullname')
67
[12878]68class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
[11543]69    """Exporter for OnlinePayment instances.
70    """
71
72    fields = tuple(
73        sorted(iface_names(
74            ICustomStudentOnlinePayment, exclude_attribs=False,
75            omit=['display_item']))) + (
[16665]76            'student_id','state','current_session', 'entry_session',
77            'faculty', 'department')
[11543]78
[16665]79    def mangle_value(self, value, name, context=None):
80        """The mangler determines the student's id, registration
81        state and current session.
82        """
83        if context is not None:
84            student = context.student
85            if name in ['faculty', 'department'] and student is not None:
86                try:
87                    if name == 'department':
88                        value = student['studycourse'].certificate.__parent__.__parent__.title
89                    else:
90                        value = student['studycourse'].certificate.__parent__.__parent__.__parent__.title
91                except AttributeError:
92                    value = 'N/A'
93        return super(
94            CustomStudentPaymentExporter, self).mangle_value(
95            value, name, context=context)
96
[16706]97class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter):
98    """
99    """
100
101    def mangle_value(self, value, name, context=None):
102        """
103        """
104        if name in self.year_range_tuple and context is not None:
105            value = 0
106            for ticket in context['payments'].values():
107                if ticket.p_category in (
108                    'schoolfee',
109                    'schoolfee40',
110                    'secondinstal ',
111                    'clearance',) and ticket.p_session == int(name):
112                    if ticket.p_state == 'waived':
113                        value = 'waived'
114                        break
115                    if ticket.p_state == 'scholarship':
116                        value = 'scholarship'
117                        break
118                    if ticket.p_state == 'paid':
119                        try:
120                            value += ticket.amount_auth
121                        except TypeError:
122                            pass
123            if value == 0:
124                value = ''
125            elif isinstance(value, float):
126                value = round(value, 2)
127        return super(
128            StudentExporter, self).mangle_value(
129            value, name, context=context)
130
Note: See TracBrowser for help on using the repository browser.