Changeset 9574 for main/waeup.kofa/trunk


Ignore:
Timestamp:
8 Nov 2012, 13:25:38 (12 years ago)
Author:
Henrik Bettermann
Message:

Add StudentPaymentsOverviewExporter?.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r9427 r9574  
    1919"""
    2020import grok
     21from datetime import datetime
    2122from zope.catalog.interfaces import ICatalog
    2223from zope.component import queryUtility
     
    320321    def export_student(self, student, filepath=None):
    321322        return self.export(get_bedtickets([student]), filepath)
     323
     324class StudentPaymentsOverviewExporter(StudentsExporter):
     325    """Exporter for students with payment overview.
     326    """
     327    grok.name('paymentsoverview')
     328
     329    curr_year = datetime.now().year
     330    year_range = range(curr_year - 9, curr_year + 1)
     331    year_range_tuple = tuple([str(year) for year in year_range])
     332
     333    #: Fieldnames considered by this exporter
     334    fields = ('student_id', ) + (
     335        'state', 'certcode', 'faccode', 'depcode', 'is_postgrad',
     336        'current_level', 'current_session',
     337        ) + year_range_tuple
     338
     339    #: The title under which this exporter will be displayed
     340    title = _(u'Student Payments Overview')
     341
     342    def mangle_value(self, value, name, context=None):
     343        if name in self.year_range_tuple and context is not None:
     344            value = ''
     345            for ticket in context['payments'].values():
     346                if ticket.p_state == 'paid' and \
     347                    ticket.p_category == 'schoolfee' and \
     348                    ticket.p_session == int(name):
     349                    value = ticket.amount_auth
     350                    break
     351        return super(
     352            StudentsExporter, self).mangle_value(
     353            value, name, context=context)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9543 r9574  
    55from waeup.kofa.students.export import (
    66    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
    7     CourseTicketExporter, PaymentsExporter, BedTicketsExporter)
     7    CourseTicketExporter, PaymentsExporter, BedTicketsExporter,
     8    StudentPaymentsOverviewExporter)
    89from waeup.kofa.students.payments import StudentOnlinePayment
    910from waeup.kofa.students.accommodation import BedTicket
     
    1213from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
    1314from waeup.kofa.testing import FunctionalLayer
     15
     16curr_year = datetime.datetime.now().year
     17year_range = range(curr_year - 9, curr_year + 1)
     18year_range_str = ','.join([str(i) for i in year_range])
     19
    1420
    1521class StudentsExporterTest(StudentImportExportSetup):
     
    531537            )
    532538        return
     539
     540class StudentPaymentsOverviewExporterTest(StudentImportExportSetup):
     541
     542    layer = FunctionalLayer
     543
     544    def setUp(self):
     545        super(StudentPaymentsOverviewExporterTest, self).setUp()
     546        self.setup_for_export()
     547        return
     548
     549    def test_ifaces(self):
     550        # make sure we fullfill interface contracts
     551        obj = StudentPaymentsOverviewExporter()
     552        verifyObject(ICSVExporter, obj)
     553        verifyClass(ICSVExporter, StudentPaymentsOverviewExporter)
     554        return
     555
     556    def test_get_as_utility(self):
     557        # we can get a payments exporter as utility
     558        result = queryUtility(ICSVExporter, name="paymentsoverview")
     559        self.assertTrue(result is not None)
     560        return
     561
     562    def test_export(self):
     563        self.setup_student(self.student)
     564        exporter = StudentPaymentsOverviewExporter()
     565        exporter.export([self.student], self.outfile)
     566        result = open(self.outfile, 'rb').read()
     567        self.assertEqual(
     568            'student_id,state,certcode,faccode,depcode,is_postgrad,'
     569            'current_level,current_session,'
     570            '%s\r\n'
     571            'A111111,created,CERT1,NA,NA,0,200,2012,'
     572            ',,,,,,,,,\r\n' % year_range_str,
     573            result
     574            )
     575        return
     576
     577    def test_export_all(self):
     578        # we can really export students
     579        # set values we can expect in export file
     580        self.setup_student(self.student)
     581        # We add successful payments
     582        payment = StudentOnlinePayment()
     583        payment.p_id = 'my-id'
     584        payment.p_session = 2009
     585        payment.amount_auth = 12.12
     586        payment.p_state = u'paid'
     587        self.student['payments']['my-2ndpayment'] = payment
     588        exporter = StudentPaymentsOverviewExporter()
     589        exporter.export_all(self.app, self.outfile)
     590        result = open(self.outfile, 'rb').read()
     591        self.assertEqual(
     592            'student_id,state,certcode,faccode,depcode,is_postgrad,'
     593            'current_level,current_session,'
     594            '%s\r\nA111111,created,CERT1,NA,NA,0,'
     595            '200,2012,,,,,,,12.12,,,\r\n' % year_range_str,
     596            result
     597            )
     598        return
Note: See TracChangeset for help on using the changeset viewer.