Ignore:
Timestamp:
13 Feb 2025, 11:36:26 (2 days ago)
Author:
Henrik Bettermann
Message:

Implement payment ticket exporter with date range filter.

File:
1 edited

Legend:

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

    r17760 r18021  
    1919"""
    2020import grok
     21from datetime import datetime, timedelta
    2122from zope.catalog.interfaces import ICatalog
    22 from zope.component import queryUtility
     23from zope.component import queryUtility, getUtility
    2324from waeup.kofa.applicants.interfaces import (
    2425    IApplicantBaseData, IApplicantsContainer, IApplicantOnlinePayment,
    2526    IApplicantRefereeReport, IApplicant)
    26 from waeup.kofa.interfaces import ICSVExporter
     27from waeup.kofa.interfaces import ICSVExporter, IKofaUtils
    2728from waeup.kofa.interfaces import MessageFactory as _
    2829from waeup.kofa.utils.batching import ExporterBase
    29 from waeup.kofa.utils.helpers import iface_names
     30from waeup.kofa.utils.helpers import iface_names, to_timezone
    3031
    3132class ApplicantsContainerExporter(grok.GlobalUtility, ExporterBase):
     
    213214        """
    214215        container = grok.getSite()['applicants'][kw['container']]
     216        p_start = kw.get('p_start')
     217        p_end = kw.get('p_end')
    215218        container_values = container.values()
    216219        used = [value for value in container_values
    217220                if value.container_code.endswith('+')]
    218221        payments = []
     222        date_format = '%d/%m/%Y'
    219223        for applicant in used:
    220224            for payment in applicant.payments:
     225                if p_start and p_end:
     226                    if not payment.payment_date:
     227                        continue
     228                    payments_start = datetime.strptime(p_start, date_format)
     229                    payments_end = datetime.strptime(p_end, date_format)
     230                    tz = getUtility(IKofaUtils).tzinfo
     231                    payments_start = tz.localize(payments_start)
     232                    payments_end = tz.localize(payments_end) + timedelta(days=1)
     233                    payment_date = to_timezone(payment.payment_date, tz)
     234                    if payment_date < payments_start or payment_date > payments_end:
     235                        continue
    221236                if payment.p_state == 'paid':
    222237                    payments.append(payment)
Note: See TracChangeset for help on using the changeset viewer.