Changeset 12971


Ignore:
Timestamp:
21 May 2015, 07:38:15 (9 years ago)
Author:
Henrik Bettermann
Message:

Add StudentUnpaidPaymentExporter? to export only unpaid tickets. This exporter is designed for finding and finally purging outdated payment ticket.

Location:
main/waeup.kofa/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r12960 r12971  
    441.3.2.dev0 (unreleased)
    55=======================
     6
     7* Add StudentUnpaidPaymentExporter to export only unpaid tickets.
     8  This exporter is designed for finding and finally purging outdated
     9  payment ticket.
    610
    711* Remove deprecated xml importer and exporter components.
  • main/waeup.kofa/trunk/docs/source/userdocs/datacenter/export.rst

    r12953 r12971  
    213213  .. automethod:: waeup.kofa.students.export.StudentPaymentExporter.mangle_value()
    214214
     215Student Unpaid Payment Exporter
     216-------------------------------
     217
     218.. autoclass:: waeup.kofa.students.export.StudentUnpaidPaymentExporter()
     219
     220  .. autoattribute:: waeup.kofa.students.export.StudentUnpaidPaymentExporter.title
     221
    215222Bed Ticket Exporter
    216223-------------------
  • main/waeup.kofa/trunk/docs/source/userdocs/students.rst

    r12969 r12971  
    3939The `Student` class is a container class which means, there are not only attributes describing the student but also content. Each student container contains exactly three sub-containers: ``studycourse``  (instance of `StudentStudyCourse`), ``payments`` (instance of `StudentPaymentsContainer`)  ``accommodation`` (instance of `StudentAccommodation`). The purposes of them are described further below.
    4040
    41 Let's talk about the attributes and methods belonging to the `Student` class, the so-called 'external behaviour' of student objects. The data stored with each student object are subdivided into three parts: base data, personal data and clearance data.
     41Let's talk about the attributes and methods belonging to the `Student` class, the so-called 'external behaviour' of student objects specified in Zope 'interfaces'. The data stored with each student object are subdivided into three parts: base data, personal data and clearance data. Each part has its own interface.
    4242
    43 Now comes the point where we have to briefly introduce Zope's (see :ref:`prerequisites`) concept of 'interfaces'.
     43.. note::
     44
     45  Interfaces are one of the pillars of Zope's Component Architecture (ZCA, see also :ref:`prerequisites`). They document the 'external behaviour' of objects. In Kofa interfaces are used to specify the attributes, methods and schema fields of objects. The first two are well-known Python concepts. A Zope schema field is a bit more complicated. It's a detailed description of a field to be submitted via forms to the server, or which is processed by a batch processor. In both cases the input data are being validated against the schema. In Kofa, schema fields in interfaces are also used to automtically add `FieldProperty` attributes of the same name to most content classes. This is done by a function called :py:func:`attrs_to_fields<waeup.kofa.utils.helpers.attrs_to_fields>`. These class attributes ensure that corresponding attributes of instances of this class - when being added or changed - always meet the requirements of the schema. Another big advantage of such class attributes is, that attributes with a `FieldProperty` do not need to be set in `__init__` methods.
    4446
    4547
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt

    r11730 r12971  
    7474  function test() {
    7575      if (document.getElementById('exporter').value == 'bursary' ||
    76           document.getElementById('exporter').value == 'studentpayments') {
     76          document.getElementById('exporter').value == 'studentpayments' ||
     77          document.getElementById('exporter').value == 'studentunpaidpayments') {
    7778          document.getElementById('payment_dates').style.display = 'block';
    7879      } else {
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt

    r11730 r12971  
    6464  function test() {
    6565      if (document.getElementById('exporter').value == 'bursary' ||
    66           document.getElementById('exporter').value == 'studentpayments') {
     66          document.getElementById('exporter').value == 'studentpayments' ||
     67          document.getElementById('exporter').value == 'studentunpaidpayments') {
    6768          document.getElementById('payment_dates').style.display = 'block';
    6869      } else {
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r12873 r12971  
    8686    return tickets
    8787
    88 def get_payments(students, paid=False, **kw):
     88def get_payments(students, p_state=None, **kw):
    8989    """Get all payments of `students` within given payment_date period.
    9090    """
     
    100100        payments_start = tz.localize(payments_start)
    101101        payments_end = tz.localize(payments_end)
    102         if paid:
    103             # Only paid tickets in payment period are considered
     102        if p_state:
     103            # Only paid or unpaid tickets in payment period are considered
    104104            for student in students:
    105105                for payment in student.get('payments', {}).values():
    106                     if payment.payment_date and payment.p_state == 'paid':
     106                    if payment.payment_date and payment.p_state == p_state:
    107107                        payment_date = to_timezone(payment.payment_date, tz)
    108108                        if payment_date > payments_start and \
     
    120120    else:
    121121        # Payment period not given
    122         if paid:
     122        if p_state:
    123123            # Only paid tickets are considered
    124124            for student in students:
    125125                for payment in student.get('payments', {}).values():
    126                     if payment.p_state == 'paid':
     126                    if payment.p_state == p_state:
    127127                        payments.append(payment)
    128128        else:
     
    382382            value, name, context=context)
    383383
     384class StudentUnpaidPaymentExporter(StudentPaymentExporter):
     385    """The Student Unpaid Payment Exporter works just like the
     386    Student Payments Exporter but it exports only unpaid tickets.
     387    This exporter is designed for finding and finally purging outdated
     388    payment ticket.
     389    """
     390    grok.name('studentunpaidpayments')
     391
     392    title = _(u'Student Unpaid Payments')
     393
     394    def filter_func(self, x, **kw):
     395        return get_payments(x, p_state='unpaid', **kw)
     396
    384397class DataForBursaryExporter(StudentPaymentExporter):
    385398    """The DataForBursary Exporter works just like the Student Payments Exporter
     
    392405
    393406    def filter_func(self, x, **kw):
    394         return get_payments(x, paid=True, **kw)
     407        return get_payments(x, p_state='paid', **kw)
    395408
    396409    fields = tuple(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/student.py

    r12104 r12971  
    421421    """
    422422
    423     STUDENT_EXPORTER_NAMES = getUtility(
    424         IStudentsUtils).STUDENT_EXPORTER_NAMES
    425 
    426     for name in STUDENT_EXPORTER_NAMES:
     423    STUDENT_BACKUP_EXPORTER_NAMES = getUtility(
     424        IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
     425
     426    for name in STUDENT_BACKUP_EXPORTER_NAMES:
    427427        exporter = getUtility(ICSVStudentExporter, name=name)
    428428        csv_data = exporter.export_student(student)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r12865 r12971  
    3232    StudentPaymentsOverviewExporter, StudentStudyLevelsOverviewExporter,
    3333    ComboCardDataExporter, DataForBursaryExporter,
     34    StudentUnpaidPaymentExporter,
    3435    get_students,)
    3536from waeup.kofa.students.accommodation import BedTicket
     
    895896        result = open(self.outfile, 'rb').read()
    896897       
     898        return
     899
     900class StudentUnpaidPaymentExporterTest(StudentImportExportSetup):
     901
     902    layer = FunctionalLayer
     903
     904    def setUp(self):
     905        super(StudentUnpaidPaymentExporterTest, self).setUp()
     906        self.setup_for_export()
     907        return
     908
     909    def test_export_all(self):
     910        # we can really export all payments
     911        # set values we can expect in export file
     912        self.setup_student(self.student)
     913        exporter = StudentUnpaidPaymentExporter()
     914        exporter.export_all(self.app, self.outfile)
     915        result = open(self.outfile, 'rb').read()
     916        # No unpaid ticket exists
     917        self.assertEqual(
     918            result,
     919            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
     920            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
     921            'r_code,r_desc,student_id,state,current_session\r\n'
     922            )
     923        # Make ticket unpaid
     924        self.payment.p_state = 'unpaid'
     925        exporter.export_all(self.app, self.outfile)
     926        result = open(self.outfile, 'rb').read()
     927        self.assertEqual(
     928            result,
     929            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
     930            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
     931            'r_code,r_desc,student_id,state,current_session\r\n'
     932
     933            '666,12.12,2012-04-01 13:12:01#,schoolfee,1,my-id,'
     934            'p-item,100,2012,unpaid,2012-04-01 14:12:01#,12.12,'
     935            'r-code,,A111111,created,2012\r\n'
     936            )
    897937        return
    898938
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py

    r12104 r12971  
    182182
    183183        # The student data were put into CSV files
    184         STUDENT_EXPORTER_NAMES = getUtility(
    185             IStudentsUtils).STUDENT_EXPORTER_NAMES
    186 
    187         for name in STUDENT_EXPORTER_NAMES:
     184        STUDENT_BACKUP_EXPORTER_NAMES = getUtility(
     185            IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
     186
     187        for name in STUDENT_BACKUP_EXPORTER_NAMES:
    188188            csv_path = os.path.join(del_dir, '%s.csv' % name)
    189189            self.assertTrue(os.path.isfile(csv_path))
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r12902 r12971  
    954954    STUDENT_EXPORTER_NAMES = ('students', 'studentstudycourses',
    955955            'studentstudylevels', 'coursetickets',
    956             'studentpayments', 'bedtickets', 'paymentsoverview',
     956            'studentpayments', 'studentunpaidpayments',
     957            'bedtickets', 'paymentsoverview',
    957958            'studylevelsoverview', 'combocard', 'bursary')
     959
     960    #: A tuple containing all exporter names needed for backing
     961    #: up student data
     962    STUDENT_BACKUP_EXPORTER_NAMES = ('students', 'studentstudycourses',
     963            'studentstudylevels', 'coursetickets',
     964            'studentpayments', 'bedtickets')
    958965
    959966    #: A prefix used when generating new student ids. Each student id will
  • main/waeup.kofa/trunk/src/waeup/kofa/university/department.py

    r12906 r12971  
    3131from waeup.kofa.utils.batching import VirtualExportJobContainer
    3232from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
    33 from waeup.kofa.utils.helpers import attrs_to_fields
    3433from waeup.kofa.university.interfaces import IDepartment
    3534
Note: See TracChangeset for help on using the changeset viewer.