Ignore:
Timestamp:
21 May 2015, 07:38:15 (10 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/src/waeup/kofa/students
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.