Ignore:
Timestamp:
6 Jun 2018, 11:10:07 (6 years ago)
Author:
Henrik Bettermann
Message:

Fix CourseTicketExporter. Ticket level and session filter did not work.

Add payment category filter to payment exporters. Optimize Python code.

File:
1 edited

Legend:

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

    r14984 r15042  
    135135    payments_start = kw.get('payments_start')
    136136    payments_end = kw.get('payments_end')
    137     if payments_start and payments_end:
    138         # Payment period given
    139         payments_start = datetime.strptime(payments_start, date_format)
    140         payments_end = datetime.strptime(payments_end, date_format)
    141         tz = getUtility(IKofaUtils).tzinfo
    142         payments_start = tz.localize(payments_start)
    143         payments_end = tz.localize(payments_end) + timedelta(days=1)
    144         if p_states:
    145             # Only tickets in certain states and payment period are considered
    146             for student in students:
    147                 for payment in student.get('payments', {}).values():
    148                     if payment.payment_date and payment.p_state in p_states:
    149                         payment_date = to_timezone(payment.payment_date, tz)
    150                         if payment_date > payments_start and \
    151                             payment_date < payments_end:
    152                             payments.append(payment)
    153         else:
    154             # All tickets in payment period are considered
    155             for student in students:
    156                 for payment in student.get('payments', {}).values():
    157                     if payment.payment_date:
    158                         payment_date = to_timezone(payment.payment_date, tz)
    159                         if payment_date > payments_start and \
    160                             payment_date < payments_end:
    161                             payments.append(payment)
    162     else:
    163         # Payment period not given
    164         if p_states:
    165             # Only paid tickets are considered
    166             for student in students:
    167                 for payment in student.get('payments', {}).values():
    168                     if payment.p_state in p_states:
    169                         payments.append(payment)
    170         else:
    171             # All tickets are considered
    172             for student in students:
    173                 for payment in student.get('payments', {}).values():
    174                     payments.append(payment)
     137    paycat = kw.get('paycat')
     138    for student in students:
     139        for payment in student.get('payments', {}).values():
     140            if payments_start and payments_end:
     141                if not payment.payment_date:
     142                    continue
     143                payments_start = datetime.strptime(payments_start, date_format)
     144                payments_end = datetime.strptime(payments_end, date_format)
     145                tz = getUtility(IKofaUtils).tzinfo
     146                payments_start = tz.localize(payments_start)
     147                payments_end = tz.localize(payments_end) + timedelta(days=1)
     148                payment_date = to_timezone(payment.payment_date, tz)
     149                if payment_date < payments_start or payment_date > payments_end:
     150                    continue
     151            if p_states and not payment.p_state in p_states:
     152                continue
     153            if paycat not in ('all', None) and payment.p_category != paycat:
     154                continue
     155            payments.append(payment)
    175156    return payments
    176157
     
    218199                students.append(ticket.student)
    219200            return list(set(students))
    220         # Payments can be filtered by payment_date. The period boundaries
    221         # are not keys of the catalog and must thus be removed from kw.
     201        # Payments can be filtered by payment date and payment category.
     202        # These parameters are not keys of the catalog and must thus be
     203        # removed from kw.
    222204        try:
    223205            del kw['payments_start']
    224206            del kw['payments_end']
     207            del kw['paycat']
    225208        except KeyError:
    226209            pass
     210        # Coursetickets can be filtered level and session.
     211        # These parameters are not keys of the catalog and must thus be
     212        # removed from kw.
    227213        try:
    228214            del kw['ct_level']
     
    433419    by searching the students catalog. Then it exports student payment
    434420    tickets by iterating over the items of the student's ``payments``
    435     container. If the payment period is given only tickets, which were
     421    container. If the payment period is given, only tickets, which were
    436422    paid in payment period, are considered for export.
    437423    """
Note: See TracChangeset for help on using the changeset viewer.