Changeset 11730


Ignore:
Timestamp:
4 Jul 2014, 07:46:16 (10 years ago)
Author:
Henrik Bettermann
Message:

Filter payment ticket data exports by specifying the payment_date period.

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

Legend:

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

    r11729 r11730  
    441.3dev (unreleased)
    55===================
     6
     7* Filter payment ticket data exports by specifying the payment_date period.
    68
    79* Application payment slips can only be downloaded if application form is
  • main/waeup.kofa/trunk/layout/static/css/base.css

    r11719 r11730  
    255255}
    256256
     257.datepicker-short {
     258    width: 15%;
     259}
     260
    257261.ui-widget-header .ui-icon {
    258262    background-image: url("../img/ui-icons_222222_256x240.png");
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r11254 r11730  
    347347        self.assertTrue(
    348348            'zope.mgr - students.browser.DatacenterExportJobContainerJobConfig '
    349             '- exported: students (None, None, None, None, None), job_id=%s'
     349            '- exported: students (None, None, None, None, None, None, None), '
     350            'job_id=%s'
    350351            % job_id in logcontent)
    351352        self.assertTrue(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r11676 r11730  
    31763176
    31773177    def update(self, START=None, session=None, level=None, mode=None,
     3178               payments_start=None, payments_end=None,
    31783179               exporter=None):
    31793180        self._set_session_values()
     
    31833184        if START is None:
    31843185            return
     3186        if payments_start or payments_end:
     3187            date_format = '%d/%m/%Y'
     3188            try:
     3189                dummy = datetime.strptime(payments_start, date_format)
     3190                dummy = datetime.strptime(payments_end, date_format)
     3191            except ValueError:
     3192                self.flash(_('Payment dates do not match format d/m/Y.'),
     3193                           type="danger")
     3194                return
    31853195        if session == 'all':
    31863196            session=None
     
    31893199        if mode == 'all':
    31903200            mode = None
     3201        if payments_start == '':
     3202            payments_start = None
     3203        if payments_end == '':
     3204            payments_end = None
    31913205        if (mode, level, session,
    31923206            self.depcode, self.certcode) == (None, None, None, None, None):
    31933207            # Export all students including those without certificate
    31943208            job_id = self.context.start_export_job(exporter,
    3195                                           self.request.principal.id)
     3209                                          self.request.principal.id,
     3210                                          payments_start = payments_start,
     3211                                          payments_end = payments_end)
    31963212        else:
    31973213            job_id = self.context.start_export_job(exporter,
     
    32013217                                          current_mode=mode,
    32023218                                          depcode=self.depcode,
    3203                                           certcode=self.certcode)
     3219                                          certcode=self.certcode,
     3220                                          payments_start = payments_start,
     3221                                          payments_end = payments_end)
    32043222        ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    32053223        self.context.logger.info(
    3206             '%s - exported: %s (%s, %s, %s, %s, %s), job_id=%s'
     3224            '%s - exported: %s (%s, %s, %s, %s, %s, %s, %s), job_id=%s'
    32073225            % (ob_class, exporter, session, level, mode, self.depcode,
    3208             self.certcode, job_id))
     3226            self.certcode, payments_start, payments_end, job_id))
    32093227        self.flash(_('Export started for students with') +
    32103228                   ' current_session=%s, current_level=%s, study_mode=%s' % (
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt

    r11254 r11730  
    1414    Exporter (Data Type)
    1515  </label>
    16   <select name="exporter" class="form-control half">
     16  <select id="exporter" name="exporter" class="form-control half" onclick="test()">
    1717    <option tal:repeat="item view/exporters"
    1818            tal:attributes="value python:item[1]">
     
    5050    </option>
    5151  </select>
    52   <br /><br />
     52  <br />
     53  <span id="payment_dates" style="display: none;">
     54    <label for="mode" i18n:translate="">
     55      Payment Date
     56    </label>
     57    <br />
     58    from
     59    <input class="datepicker-le-year datepicker-short textType"
     60           id="payments_start"
     61           name="payments_start" type="text" value="" />
     62    to <input class="datepicker-le-year datepicker-short textType"
     63           id="payments_end"
     64           name="payments_end" type="text" value="" />
     65    <br />
     66  </span>
     67  <br />
    5368  <input type="submit" name="START"  i18n:translate=""
    5469    value="Create CSV file"
    5570    class="btn btn-primary" />
    5671</form>
     72
     73<script type="text/javascript">
     74  function test() {
     75      if (document.getElementById('exporter').value == 'bursary' ||
     76          document.getElementById('exporter').value == 'studentpayments') {
     77          document.getElementById('payment_dates').style.display = 'block';
     78      } else {
     79          document.getElementById('payment_dates').style.display = 'none';
     80      }
     81  }
     82</script>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt

    r11254 r11730  
    1414    Exporter (Data Type)
    1515  </label>
    16   <select name="exporter" class="form-control half">
     16  <select id="exporter" name="exporter" class="form-control half" onclick="test()">
    1717    <option tal:repeat="item view/exporters"
    1818            tal:attributes="value python:item[1]">
     
    4040    </option>
    4141  </select>
    42   <br /><br />
     42  <br />
     43  <span id="payment_dates" style="display: none;">
     44    <label for="mode" i18n:translate="">
     45      Payment Date
     46    </label>
     47    <br />
     48    from
     49    <input class="datepicker-le-year datepicker-short textType"
     50           id="payments_start"
     51           name="payments_start" type="text" value="" />
     52    to <input class="datepicker-le-year datepicker-short textType"
     53           id="payments_end"
     54           name="payments_end" type="text" value="" />
     55    <br />
     56  </span>
     57  <br />
    4358  <input type="submit" name="START"  i18n:translate=""
    4459    value="Create CSV file"
    4560    class="btn btn-primary" />
    4661</form>
     62
     63<script type="text/javascript">
     64  function test() {
     65      if (document.getElementById('exporter').value == 'bursary' ||
     66          document.getElementById('exporter').value == 'studentpayments') {
     67          document.getElementById('payment_dates').style.display = 'block';
     68      } else {
     69          document.getElementById('payment_dates').style.display = 'none';
     70      }
     71  }
     72</script>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r11702 r11730  
    9292    return tickets
    9393
    94 def get_payments(students):
    95     """Get all payments of `students`.
    96     """
     94def get_payments(students, paid=False, **kw):
     95    """Get all payments of `students` within given payment_date period.
     96
     97    """
     98    date_format = '%d/%m/%Y'
    9799    payments = []
    98     for student in students:
    99         for payment in student.get('payments', {}).values():
    100             payments.append(payment)
    101     return payments
    102 
    103 def get_paid_payments(students):
    104     """Get all paid payments of `students`.
    105     """
    106     payments = []
    107     for student in students:
    108         for payment in student.get('payments', {}).values():
    109             if payment.p_state == 'paid':
    110                 payments.append(payment)
     100    payments_start = kw.get('payments_start')
     101    payments_end = kw.get('payments_end')
     102    if payments_start and payments_end:
     103        # Payment period given
     104        payments_start = datetime.strptime(payments_start, date_format)
     105        payments_end = datetime.strptime(payments_end, date_format)
     106        if paid:
     107            # Only paid tickets in payment period are considered
     108            for student in students:
     109                for payment in student.get('payments', {}).values():
     110                    if payment.p_state == 'paid' and \
     111                        payment.payment_date > payments_start and \
     112                        payment.payment_date < payments_end:
     113                        payments.append(payment)
     114        else:
     115            # All tickets in payment period are considered
     116            for student in students:
     117                for payment in student.get('payments', {}).values():
     118                    if payment.payment_date > payments_start and \
     119                        payment.payment_date < payments_end:
     120                        payments.append(payment)
     121    else:
     122        # Payment period not given
     123        if paid:
     124            # Only paid tickets are considered
     125            for student in students:
     126                for payment in student.get('payments', {}).values():
     127                    if payment.p_state == 'paid':
     128                        payments.append(payment)
     129        else:
     130            # All tickets are considered
     131            for student in students:
     132                for payment in student.get('payments', {}).values():
     133                    payments.append(payment)
    111134    return payments
    112135
     
    156179                students.append(ticket.student)
    157180            return list(set(students))
     181        # Payments can be filtered by payment_date. The period boundaries
     182        # are not keys of the catalog and must thus be removed from kw.
     183        try:
     184            del kw['payments_start']
     185            del kw['payments_end']
     186        except KeyError:
     187            pass
    158188        query = StudentsQuery(**kw)
    159189        return query.query()
     
    316346
    317347    def filter_func(self, x, **kw):
    318         return get_payments(x)
     348        return get_payments(x, **kw)
    319349
    320350    def mangle_value(self, value, name, context=None):
     
    336366
    337367    def filter_func(self, x, **kw):
    338         return get_paid_payments(x)
     368        return get_payments(x, paid=True, **kw)
    339369
    340370    #: Fieldnames considered by this exporter
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r11676 r11730  
    32333233        return job_id
    32343234
     3235    def test_datacenter_export(self):
     3236        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     3237        self.browser.open('http://localhost/app/datacenter/@@exportconfig')
     3238        self.browser.getControl(name="exporter").value = ['bursary']
     3239        self.browser.getControl(name="session").value = ['2004']
     3240        self.browser.getControl(name="level").value = ['100']
     3241        self.browser.getControl(name="mode").value = ['ug_ft']
     3242        self.browser.getControl(name="payments_start").value = '13/12/2012'
     3243        self.browser.getControl(name="payments_end").value = '14/12/2012'
     3244        self.browser.getControl("Create CSV file").click()
     3245
     3246        # When the job is finished and we reload the page...
     3247        job_id = self.wait_for_export_job_completed()
     3248        # ... the csv file can be downloaded ...
     3249        self.browser.open('http://localhost/app/datacenter/@@export')
     3250        self.browser.getLink("Download").click()
     3251        self.assertEqual(self.browser.headers['content-type'],
     3252            'text/csv; charset=UTF-8')
     3253        self.assertTrue(
     3254            'filename="WAeUP.Kofa_bursary_%s.csv' % job_id in
     3255            self.browser.headers['content-disposition'])
     3256        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
     3257        job_id = self.app['datacenter'].running_exports[0][0]
     3258        # ... and discarded
     3259        self.browser.open('http://localhost/app/datacenter/@@export')
     3260        self.browser.getControl("Discard").click()
     3261        self.assertEqual(len(self.app['datacenter'].running_exports), 0)
     3262        # Creation, downloading and discarding is logged
     3263        logfile = os.path.join(
     3264            self.app['datacenter'].storage, 'logs', 'datacenter.log')
     3265        logcontent = open(logfile).read()
     3266        self.assertTrue(
     3267            'zope.mgr - students.browser.DatacenterExportJobContainerJobConfig '
     3268            '- exported: bursary (2004, 100, ug_ft, None, None, '
     3269            '13/12/2012, 14/12/2012), job_id=%s'
     3270            % job_id in logcontent
     3271            )
     3272        self.assertTrue(
     3273            'zope.mgr - browser.pages.ExportCSVView '
     3274            '- downloaded: WAeUP.Kofa_bursary_%s.csv, job_id=%s'
     3275            % (job_id, job_id) in logcontent
     3276            )
     3277        self.assertTrue(
     3278            'zope.mgr - browser.pages.ExportCSVPage '
     3279            '- discarded: job_id=%s' % job_id in logcontent
     3280            )
     3281
     3282    def test_payment_dates(self):
     3283        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     3284        self.browser.open('http://localhost/app/datacenter/@@exportconfig')
     3285        self.browser.getControl(name="exporter").value = ['bursary']
     3286        self.browser.getControl(name="session").value = ['2004']
     3287        self.browser.getControl(name="level").value = ['100']
     3288        self.browser.getControl(name="mode").value = ['ug_ft']
     3289        self.browser.getControl(name="payments_start").value = '13/12/2012'
     3290        # If one payment date is missing, an error message appears
     3291        self.browser.getControl(name="payments_end").value = ''
     3292        self.browser.getControl("Create CSV file").click()
     3293        self.assertTrue('Payment dates do not match format d/m/Y'
     3294            in self.browser.contents)
     3295
    32353296    def test_faculties_export(self):
    32363297        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    32433304        self.browser.getControl(name="level").value = ['100']
    32443305        self.browser.getControl(name="mode").value = ['ug_ft']
     3306        self.browser.getControl(name="payments_start").value = '13/12/2012'
     3307        self.browser.getControl(name="payments_end").value = '14/12/2012'
    32453308        self.browser.getControl("Create CSV file").click()
    32463309
     
    32673330        self.assertTrue(
    32683331            'zope.mgr - students.browser.FacultiesExportJobContainerJobConfig '
    3269             '- exported: bursary (2004, 100, ug_ft, None, None), job_id=%s'
     3332            '- exported: bursary (2004, 100, ug_ft, None, None, '
     3333            '13/12/2012, 14/12/2012), job_id=%s'
    32703334            % job_id in logcontent
    32713335            )
     
    32903354        self.browser.getControl(name="level").value = ['100']
    32913355        self.browser.getControl(name="mode").value = ['ug_ft']
     3356        # The testbrowser does not hide the payment period fields, but
     3357        # values are ignored when using the students exporter.
     3358        self.browser.getControl(name="payments_start").value = '13/12/2012'
     3359        self.browser.getControl(name="payments_end").value = '14/12/2012'
    32923360        self.browser.getControl("Create CSV file").click()
    32933361
     
    33143382        self.assertTrue(
    33153383            'zope.mgr - students.browser.DepartmentExportJobContainerJobConfig '
    3316             '- exported: students (2004, 100, ug_ft, dep1, None), job_id=%s'
     3384            '- exported: students (2004, 100, ug_ft, dep1, None, '
     3385            '13/12/2012, 14/12/2012), job_id=%s'
    33173386            % job_id in logcontent
    33183387            )
     
    33603429        self.assertTrue(
    33613430            'zope.mgr - students.browser.CertificateExportJobContainerJobConfig '
    3362             '- exported: students (2004, 100, None, None, CERT1), job_id=%s'
     3431            '- exported: students (2004, 100, None, None, CERT1, None, None), '
     3432            'job_id=%s'
    33633433            % job_id in logcontent
    33643434            )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r11702 r11730  
    761761        return
    762762
     763    def test_export_filtered_by_date(self):
     764        # payments_start and payments_end are being ignored
     765        self.setup_student(self.student)
     766        self.app['students'].addStudent(self.student)
     767        notify(grok.ObjectModifiedEvent(self.student))
     768        exporter = StudentPaymentsExporter()
     769        # A key xxx does not exist
     770        self.assertRaises(
     771            KeyError, exporter.export_filtered, self.app, self.outfile,
     772            current_session=None,
     773            current_level=None, xxx='nonsense')
     774        # payments_start and payments_end do exist but must match format '%Y-%m-%d'
     775        self.assertRaises(
     776            ValueError, exporter.export_filtered, self.app, self.outfile,
     777            current_session=None, current_level=None,
     778            payments_start='nonsense', payments_end='nonsense')
     779        # If they match the format they are ignored by get_filtered and the
     780        # exporter works properly
     781        exporter.export_filtered(
     782            self.app, self.outfile,
     783            current_session=None, current_level=None,
     784            payments_start='01/04/2012', payments_end='02/04/2012')
     785        result = open(self.outfile, 'rb').read()
     786        self.assertEqual(
     787            result,
     788            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
     789            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
     790            'r_code,r_desc,student_id,state,current_session\r\n'
     791
     792            '666,12.12,2012-04-01 13:12:01,schoolfee,1,my-id,'
     793            'p-item,100,2012,paid,2012-04-01 14:12:01,12.12,'
     794            'r-code,,A111111,created,2012\r\n'
     795            )
     796        # no results if payment_date is outside the given period
     797        exporter.export_filtered(
     798            self.app, self.outfile,
     799            current_session=None, current_level=None,
     800            payments_start='31/03/2012', payments_end='01/04/2012')
     801        result = open(self.outfile, 'rb').read()
     802        self.assertEqual(
     803            result,
     804            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
     805            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
     806            'r_code,r_desc,student_id,state,current_session\r\n'
     807            )
     808        exporter.export_filtered(
     809            self.app, self.outfile,
     810            current_session=None, current_level=None,
     811            payments_start='02/04/2012', payments_end='03/04/2012')
     812        result = open(self.outfile, 'rb').read()
     813        self.assertEqual(
     814            result,
     815            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
     816            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
     817            'r_code,r_desc,student_id,state,current_session\r\n'
     818            )
     819        return
     820
    763821class BursaryDataExporterTest(StudentImportExportSetup):
    764822
Note: See TracChangeset for help on using the changeset viewer.