Ignore:
Timestamp:
25 Jun 2018, 09:44:43 (6 years ago)
Author:
Henrik Bettermann
Message:

Changing output of SessionPaymentsOverviewExporter?, see docstring.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r15042 r15060  
    448448            'zope.mgr - students.browser.DatacenterExportJobContainerJobConfig '
    449449            '- exported: students '
    450             '(None, None, None, None, None, None, , , all, all, all), '
     450            '(None, None, None, None, None, None, , , all, all, all, all), '
    451451            'job_id=%s'
    452452            % job_id in logcontent)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r15055 r15060  
    590590    """The Session Payments Overview Exporter first filters the set of students
    591591    by searching the students catalog. Then it exports some student base data
    592     together with lists of payment years for a predefined range of payment
    593     categories.
     592    together with the total amount paid in predefined payment categories
     593    over the previous three session (referring to current academic session).
     594    Sample output:
     595
     596    header: ``...schoolfee13,schoolfee14,schoolfee15,gown13,gown14,gown15...``
     597
     598    data: ``...2000.0,,3000.0,,,1000.0,...``
     599
     600    This csv data string means that the student paid 2000 school fee in 2013
     601    3000 in 2015. She furthermore paid 1000 for gown rental in 2015.
    594602    """
    595603    grok.name('sessionpaymentsoverview')
    596604
    597605    paycats = ('schoolfee', 'clearance', 'gown', 'transcript')
    598     fields = ('student_id', 'matric_number', 'display_fullname',
     606    regular_fields = ('student_id', 'matric_number', 'display_fullname',
    599607        'state', 'certcode', 'faccode', 'depcode', 'is_postgrad',
    600608        'current_level', 'current_session', 'current_mode',
    601609        'entry_session', 'reg_number'
    602         ) + paycats
     610        )
    603611    title = _(u'Session Payments Overview')
    604612
    605     def mangle_value(self, value, name, context=None):
    606         """
    607         """
    608         if name in self.paycats and context is not None:
    609             value = ''
     613    @property
     614    def paycatyears(self):
     615        cas = grok.getSite()['configuration'].current_academic_session
     616        paycatyears = []
     617        if cas:
     618            year_range = range(cas - 2, cas+1)
     619            year_range_tuple = tuple([str(year)[2:] for year in year_range])
     620            paycatyears = [
     621                cat+year for cat in self.paycats for year in year_range_tuple]
     622        return paycatyears
     623
     624    @property
     625    def fields(self):
     626        return self.regular_fields + tuple(self.paycatyears)
     627
     628    def mangle_value(self, value, name, context=None):
     629        """
     630        """
     631        amounts = dict()
     632        for catyear in self.paycatyears:
     633            amounts[catyear] = 0.0
     634        if name[:-2] in self.paycats and context is not None:
    610635            for ticket in context['payments'].values():
    611                 if ticket.p_category == name:
     636                if ticket.p_category == name[:-2]:
    612637                    if ticket.p_state in ('waived', 'paid'):
    613                         value += '%s ' % ticket.p_session
    614             value = value.strip().replace(' ', '+')
     638                        if str(ticket.p_session)[2:] == name[-2:]:
     639                            amounts[name] += ticket.amount_auth
     640            if amounts[name] == 0.0:
     641                value = ''
     642            elif isinstance(amounts[name], float):
     643                value = round(amounts[name], 2)
    615644        return super(
    616645            StudentExporter, self).mangle_value(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r15051 r15060  
    12391239        super(SessionPaymentsOverviewExporterTest, self).setUp()
    12401240        self.setup_for_export()
     1241        grok.getSite()['configuration'].current_academic_session = curr_year - 4
    12411242        return
    12421243
     
    12621263            'student_id,matric_number,display_fullname,state,certcode,'
    12631264            'faccode,depcode,is_postgrad,current_level,current_session,'
    1264             'current_mode,entry_session,reg_number,schoolfee,clearance,'
    1265             'gown,transcript\r\n'
    1266             'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,2012,'
    1267             'ug_ft,2010,123,2012,,,' in result
     1265            'current_mode,entry_session,reg_number,schoolfee12,'
     1266            'schoolfee13,schoolfee14,clearance12,clearance13,clearance14,'
     1267            'gown12,gown13,gown14,transcript12,transcript13,transcript14\r\n'
     1268            'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,'
     1269            '2012,ug_ft,2010,123,'
     1270            '12.12,,,,,,,,,,,\r\n' in result
    12681271            )
    12691272        return
    12701273
    12711274    def test_export_all(self):
    1272         # we can really export students
    1273         # set values we can expect in export file
    12741275        self.setup_student(self.student)
    12751276        # We add successful payments.
     
    13021303        result = open(self.outfile, 'rb').read()
    13031304        self.assertTrue(
    1304             'student_id,matric_number,display_fullname,state,certcode,'
    1305             'faccode,depcode,is_postgrad,current_level,current_session,'
    1306             'current_mode,entry_session,reg_number,schoolfee,clearance,'
    1307             'gown,transcript\r\nA111111,234,Anna M. Tester,created,CERT1,'
    1308             'NA,NA,0,200,2012,ug_ft,2010,123,2013+2013+2014+2012,,,\r\n'
     1305            'student_id,matric_number,display_fullname,state,certcode,faccode,'
     1306            'depcode,is_postgrad,current_level,current_session,'
     1307            'current_mode,entry_session,reg_number,'
     1308            'schoolfee12,schoolfee13,schoolfee14,'
     1309            'clearance12,clearance13,clearance14,'
     1310            'gown12,gown13,gown14,'
     1311            'transcript12,transcript13,transcript14\r\n'
     1312            'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,2012,ug_ft,'
     1313            '2010,123,'
     1314            '12.12,14.14,1.01,,,,,,,,,\r\n'
    13091315            in result
    13101316            )
Note: See TracChangeset for help on using the changeset viewer.