Changeset 15042


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.

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

Legend:

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

    r15037 r15042  
    441.6.1.dev0 (unreleased)
    55=======================
     6
     7* Fix `CourseTicketExporter`. Ticket level and session filter
     8  did not work.
     9
     10* Add payment category filter to payment exporters.
    611
    712* Remove 'hidden' attribute from ordereddSelectionList which has
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r15032 r15042  
    220220        if not job.kwargs.has_key('selected'):
    221221            args = ', '.join(['%s=%s' % (item[0], item[1])
    222                 for item in job.kwargs.items()])
     222                for item in job.kwargs.items()
     223                if item[1] not in ('all', '', None)])
    223224        else:
    224225            args = 'selection'
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r14939 r15042  
    447447        self.assertTrue(
    448448            'zope.mgr - students.browser.DatacenterExportJobContainerJobConfig '
    449             '- exported: students (None, None, None, None, None, None, None, None), '
     449            '- exported: students '
     450            '(None, None, None, None, None, None, , , all, all, all), '
    450451            'job_id=%s'
    451452            % job_id in logcontent)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r14983 r15042  
    33713371    def _set_session_values(self):
    33723372        vocab_terms = academic_sessions_vocab.by_value.values()
    3373         self.sessions = sorted(
     3373        self.sessions = [(_('All Sessions'), 'all')]
     3374        self.sessions += sorted(
    33743375            [(x.title, x.token) for x in vocab_terms], reverse=True)
    3375         self.sessions += [(_('All Sessions'), 'all')]
    33763376        return
    33773377
    33783378    def _set_level_values(self):
    33793379        vocab_terms = course_levels.by_value.values()
    3380         self.levels = sorted(
     3380        self.levels = [(_('All Levels'), 'all')]
     3381        self.levels += sorted(
    33813382            [(x.title, x.token) for x in vocab_terms])
    3382         self.levels += [(_('All Levels'), 'all')]
    33833383        return
    33843384
    33853385    def _set_mode_values(self):
    33863386        utils = getUtility(IKofaUtils)
    3387         self.modes = sorted([(value, key) for key, value in
     3387        self.modes =[(_('All Modes'), 'all')]
     3388        self.modes += sorted([(value, key) for key, value in
    33883389                      utils.STUDY_MODES_DICT.items()])
    3389         self.modes +=[(_('All Modes'), 'all')]
     3390        return
     3391
     3392    def _set_paycat_values(self):
     3393        utils = getUtility(IKofaUtils)
     3394        self.paycats =[(_('All Payment Categories'), 'all')]
     3395        self.paycats += sorted([(value, key) for key, value in
     3396                      utils.PAYMENT_CATEGORIES.items()])
    33903397        return
    33913398
     
    34263433
    34273434    def update(self, START=None, session=None, level=None, mode=None,
    3428                payments_start=None, payments_end=None,
    3429                exporter=None):
     3435               payments_start=None, payments_end=None, ct_level=None,
     3436               ct_session=None, paycat=None, exporter=None):
    34303437        self._set_session_values()
    34313438        self._set_level_values()
    34323439        self._set_mode_values()
     3440        self._set_paycat_values()
    34333441        self._set_exporter_values()
    34343442        if START is None:
     
    34533461        if mode == 'all':
    34543462            mode = None
    3455         if payments_start == '':
    3456             payments_start = None
    3457         if payments_end == '':
    3458             payments_end = None
    34593463        if (mode,
    34603464            level,
     
    34643468            self.certcode) == (None, None, None, None, None, None):
    34653469            # Export all students including those without certificate
    3466             if payments_start:
    3467                 job_id = self.context.start_export_job(exporter,
    3468                                               self.request.principal.id,
    3469                                               payments_start = payments_start,
    3470                                               payments_end = payments_end)
    3471             else:
    3472                 job_id = self.context.start_export_job(exporter,
    3473                                               self.request.principal.id)
    3474         else:
    3475             if payments_start:
    3476                 job_id = self.context.start_export_job(exporter,
    3477                                               self.request.principal.id,
    3478                                               current_session=session,
    3479                                               current_level=level,
    3480                                               current_mode=mode,
    3481                                               faccode=self.faccode,
    3482                                               depcode=self.depcode,
    3483                                               certcode=self.certcode,
    3484                                               payments_start = payments_start,
    3485                                               payments_end = payments_end)
    3486             else:
    3487                 job_id = self.context.start_export_job(exporter,
    3488                                               self.request.principal.id,
    3489                                               current_session=session,
    3490                                               current_level=level,
    3491                                               current_mode=mode,
    3492                                               faccode=self.faccode,
    3493                                               depcode=self.depcode,
    3494                                               certcode=self.certcode)
     3470            job_id = self.context.start_export_job(exporter,
     3471                                          self.request.principal.id,
     3472                                          payments_start = payments_start,
     3473                                          payments_end = payments_end,
     3474                                          paycat=paycat,
     3475                                          ct_level = ct_level,
     3476                                          ct_session = ct_session,
     3477                                          )
     3478        else:
     3479            job_id = self.context.start_export_job(exporter,
     3480                                          self.request.principal.id,
     3481                                          current_session=session,
     3482                                          current_level=level,
     3483                                          current_mode=mode,
     3484                                          faccode=self.faccode,
     3485                                          depcode=self.depcode,
     3486                                          certcode=self.certcode,
     3487                                          payments_start = payments_start,
     3488                                          payments_end = payments_end,
     3489                                          paycat=paycat,
     3490                                          ct_level = ct_level,
     3491                                          ct_session = ct_session,)
    34953492        ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    34963493        self.context.logger.info(
    3497             '%s - exported: %s (%s, %s, %s, %s, %s, %s, %s, %s), job_id=%s'
     3494            '%s - exported: %s (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s), job_id=%s'
    34983495            % (ob_class, exporter, session, level, mode, self.faccode,
    3499             self.depcode, self.certcode, payments_start, payments_end, job_id))
     3496            self.depcode, self.certcode, payments_start, payments_end,
     3497            ct_level, ct_session, paycat, job_id))
    35003498        self.flash(_('Export started for students with') +
    35013499                   ' current_session=%s, current_level=%s, study_mode=%s' % (
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt

    r14984 r15042  
    6767  </span>
    6868
     69  <span id="paycat" style="display: none;">
     70    <br />
     71    <label for="paycat" i18n:translate="">
     72      Payment Categories
     73    </label>
     74    <select name="paycat" class="form-control half">
     75      <option tal:repeat="item view/paycats"
     76              tal:attributes="value python:item[1]">
     77        <span tal:replace="python: item[0]">schoolfee</span>
     78      </option>
     79    </select>
     80    <br />
     81  </span>
    6982
    7083  <span id="ct_data" style="display: none;">
     
    91104    <br />
    92105  </span>
     106
    93107  <br />
    94108
     
    104118          document.getElementById('exporter').value == 'studentunpaidpayments') {
    105119          document.getElementById('payment_dates').style.display = 'block';
     120          document.getElementById('paycat').style.display = 'block';
    106121          document.getElementById('ct_data').style.display = 'none';
    107122      } else if (document.getElementById('exporter').value == 'coursetickets')  {
    108123          document.getElementById('ct_data').style.display = 'block';
    109124          document.getElementById('payment_dates').style.display = 'none';
     125          document.getElementById('paycat').style.display = 'none';
    110126      } else {
    111127          document.getElementById('ct_data').style.display = 'none';
    112128          document.getElementById('payment_dates').style.display = 'none';
     129          document.getElementById('paycat').style.display = 'none';
    113130      }
    114131  }
  • 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    """
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r14992 r15042  
    4242from waeup.kofa.app import University
    4343from waeup.kofa.payments.interfaces import IPayer
     44from waeup.kofa.students.payments import StudentOnlinePayment
    4445from waeup.kofa.students.student import Student
    4546from waeup.kofa.students.studylevel import StudentStudyLevel
     
    5859URL_LECTURER_LANDING = 'http://localhost/app/my_courses'
    5960
     61curr_year = datetime.now().year
    6062
    6163def lookup_submit_value(name, value, browser):
     
    34843486        return job_id
    34853487
     3488    def add_payment(self, student):
     3489        # get a payment with all fields set
     3490        payment = StudentOnlinePayment()
     3491        payment.creation_date = datetime(2012, 12, 13)
     3492        payment.p_id = 'my-id'
     3493        payment.p_category = u'schoolfee'
     3494        payment.p_state = 'paid'
     3495        payment.ac = u'666'
     3496        payment.p_item = u'p-item'
     3497        payment.p_level = 100
     3498        payment.p_session = curr_year - 6
     3499        payment.payment_date = datetime(2012, 12, 13)
     3500        payment.amount_auth = 12.12
     3501        payment.r_amount_approved = 12.12
     3502        payment.r_code = u'r-code'
     3503        # XXX: there is no addPayment method to give predictable names
     3504        self.payment = student['payments']['my-payment'] = payment
     3505        return payment
     3506
    34863507    def test_datacenter_export(self):
    34873508        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    35183539            'zope.mgr - students.browser.DatacenterExportJobContainerJobConfig '
    35193540            '- exported: bursary (2004, 100, ug_ft, None, None, None, '
    3520             '13/12/2012, 14/12/2012), job_id=%s'
     3541            '13/12/2012, 14/12/2012, all, all, all), job_id=%s'
    35213542            % job_id in logcontent
    35223543            )
     
    35723593
    35733594    def test_faculties_export(self):
     3595        self.add_payment(self.student)
    35743596        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    35753597        facs_path = 'http://localhost/app/faculties'
     
    35833605        self.browser.getControl(name="payments_start").value = '13/12/2012'
    35843606        self.browser.getControl(name="payments_end").value = '14/12/2012'
     3607        self.browser.getControl(name="paycat").value = ['schoolfee']
    35853608        self.browser.getControl("Create CSV file").click()
    35863609
     
    35953618            'filename="WAeUP.Kofa_bursary_%s.csv' % job_id in
    35963619            self.browser.headers['content-disposition'])
     3620        self.assertTrue(
     3621            '666,12.12,2012-12-13 00:00:00#,schoolfee,1,my-id,p-item,100,2012,'
     3622            'paid,2012-12-13 00:00:00#,12.12,r-code,,K1000000,234,123,Anna,,'
     3623            'Tester,created,2004,2004,,fac1,dep1,CERT1' in self.browser.contents)
    35973624        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
    35983625        job_id = self.app['datacenter'].running_exports[0][0]
     
    36083635            'zope.mgr - students.browser.FacultiesExportJobContainerJobConfig '
    36093636            '- exported: bursary (2004, 100, ug_ft, None, None, None, '
    3610             '13/12/2012, 14/12/2012), job_id=%s'
     3637            '13/12/2012, 14/12/2012, all, all, schoolfee), job_id=%s'
    36113638            % job_id in logcontent
    36123639            )
     
    36693696            'zope.mgr - students.browser.FacultyExportJobContainerJobConfig '
    36703697            '- exported: students (2004, 100, ug_ft, fac1, None, None, '
    3671             '13/12/2012, 14/12/2012), job_id=%s'
     3698            '13/12/2012, 14/12/2012, all, all, all), job_id=%s'
    36723699            % job_id in logcontent
    36733700            )
     
    37213748            'zope.mgr - students.browser.DepartmentExportJobContainerJobConfig '
    37223749            '- exported: students (2004, 100, ug_ft, None, dep1, None, '
    3723             '13/12/2012, 14/12/2012), job_id=%s'
     3750            '13/12/2012, 14/12/2012, all, all, all), job_id=%s'
    37243751            % job_id in logcontent
    37253752            )
     
    37673794        self.assertTrue(
    37683795            'zope.mgr - students.browser.CertificateExportJobContainerJobConfig '
    3769             '- exported: students (2004, 100, None, None, None, CERT1, None, None), '
     3796            '- exported: students '
     3797            '(2004, 100, None, None, None, CERT1, , , None, None, None), '
    37703798            'job_id=%s'
    37713799            % job_id in logcontent
Note: See TracChangeset for help on using the changeset viewer.