Changeset 11730
- Timestamp:
- 4 Jul 2014, 07:46:16 (10 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r11729 r11730 4 4 1.3dev (unreleased) 5 5 =================== 6 7 * Filter payment ticket data exports by specifying the payment_date period. 6 8 7 9 * Application payment slips can only be downloaded if application form is -
main/waeup.kofa/trunk/layout/static/css/base.css
r11719 r11730 255 255 } 256 256 257 .datepicker-short { 258 width: 15%; 259 } 260 257 261 .ui-widget-header .ui-icon { 258 262 background-image: url("../img/ui-icons_222222_256x240.png"); -
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r11254 r11730 347 347 self.assertTrue( 348 348 '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' 350 351 % job_id in logcontent) 351 352 self.assertTrue( -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r11676 r11730 3176 3176 3177 3177 def update(self, START=None, session=None, level=None, mode=None, 3178 payments_start=None, payments_end=None, 3178 3179 exporter=None): 3179 3180 self._set_session_values() … … 3183 3184 if START is None: 3184 3185 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 3185 3195 if session == 'all': 3186 3196 session=None … … 3189 3199 if mode == 'all': 3190 3200 mode = None 3201 if payments_start == '': 3202 payments_start = None 3203 if payments_end == '': 3204 payments_end = None 3191 3205 if (mode, level, session, 3192 3206 self.depcode, self.certcode) == (None, None, None, None, None): 3193 3207 # Export all students including those without certificate 3194 3208 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) 3196 3212 else: 3197 3213 job_id = self.context.start_export_job(exporter, … … 3201 3217 current_mode=mode, 3202 3218 depcode=self.depcode, 3203 certcode=self.certcode) 3219 certcode=self.certcode, 3220 payments_start = payments_start, 3221 payments_end = payments_end) 3204 3222 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 3205 3223 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' 3207 3225 % (ob_class, exporter, session, level, mode, self.depcode, 3208 self.certcode, job_id))3226 self.certcode, payments_start, payments_end, job_id)) 3209 3227 self.flash(_('Export started for students with') + 3210 3228 ' current_session=%s, current_level=%s, study_mode=%s' % ( -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt
r11254 r11730 14 14 Exporter (Data Type) 15 15 </label> 16 <select name="exporter" class="form-control half">16 <select id="exporter" name="exporter" class="form-control half" onclick="test()"> 17 17 <option tal:repeat="item view/exporters" 18 18 tal:attributes="value python:item[1]"> … … 50 50 </option> 51 51 </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 /> 53 68 <input type="submit" name="START" i18n:translate="" 54 69 value="Create CSV file" 55 70 class="btn btn-primary" /> 56 71 </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 14 14 Exporter (Data Type) 15 15 </label> 16 <select name="exporter" class="form-control half">16 <select id="exporter" name="exporter" class="form-control half" onclick="test()"> 17 17 <option tal:repeat="item view/exporters" 18 18 tal:attributes="value python:item[1]"> … … 40 40 </option> 41 41 </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 /> 43 58 <input type="submit" name="START" i18n:translate="" 44 59 value="Create CSV file" 45 60 class="btn btn-primary" /> 46 61 </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 92 92 return tickets 93 93 94 def get_payments(students): 95 """Get all payments of `students`. 96 """ 94 def 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' 97 99 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) 111 134 return payments 112 135 … … 156 179 students.append(ticket.student) 157 180 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 158 188 query = StudentsQuery(**kw) 159 189 return query.query() … … 316 346 317 347 def filter_func(self, x, **kw): 318 return get_payments(x )348 return get_payments(x, **kw) 319 349 320 350 def mangle_value(self, value, name, context=None): … … 336 366 337 367 def filter_func(self, x, **kw): 338 return get_pa id_payments(x)368 return get_payments(x, paid=True, **kw) 339 369 340 370 #: Fieldnames considered by this exporter -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r11676 r11730 3233 3233 return job_id 3234 3234 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 3235 3296 def test_faculties_export(self): 3236 3297 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 3243 3304 self.browser.getControl(name="level").value = ['100'] 3244 3305 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' 3245 3308 self.browser.getControl("Create CSV file").click() 3246 3309 … … 3267 3330 self.assertTrue( 3268 3331 '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' 3270 3334 % job_id in logcontent 3271 3335 ) … … 3290 3354 self.browser.getControl(name="level").value = ['100'] 3291 3355 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' 3292 3360 self.browser.getControl("Create CSV file").click() 3293 3361 … … 3314 3382 self.assertTrue( 3315 3383 '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' 3317 3386 % job_id in logcontent 3318 3387 ) … … 3360 3429 self.assertTrue( 3361 3430 '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' 3363 3433 % job_id in logcontent 3364 3434 ) -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
r11702 r11730 761 761 return 762 762 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 763 821 class BursaryDataExporterTest(StudentImportExportSetup): 764 822
Note: See TracChangeset for help on using the changeset viewer.