Changeset 8420 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 11 May 2012, 14:18:47 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r8404 r8420 591 591 'b':self.context.p_id}) 592 592 593 class OnlinePayment CallbackPage(UtilityView, grok.View):594 """ Callbackview593 class OnlinePaymentApprovePage(UtilityView, grok.View): 594 """ Approval view 595 595 """ 596 596 grok.context(IApplicantOnlinePayment) 597 grok.name('simulate_callback') 598 grok.require('waeup.payApplicant') 599 600 # This update method simulates a valid callback und must be 601 # neutralized in the customization package. 597 grok.name('approve') 598 grok.require('waeup.managePortal') 599 602 600 def update(self): 603 601 self.wf_info = IWorkflowInfo(self.context.__parent__) … … 607 605 self.flash('Error: %s' % sys.exc_info()[1]) 608 606 return 609 self.context.r_amount_approved = self.context.amount_auth 610 self.context.r_code = u'00' 611 self.context.p_state = 'paid' 612 self.context.payment_date = datetime.utcnow() 607 self.context.approve() 613 608 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 614 609 self.context.__parent__.loggerInfo( -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r8406 r8420 696 696 #self.assertMatches('...Ticket not yet paid...', 697 697 # self.browser.contents) 698 # Request callback 699 self.browser.getLink("Request callback").click() 700 self.assertMatches('...Valid callback received...', 701 self.browser.contents) 702 # Callback can't be applied twice 703 self.browser.open(payment_url + '/simulate_callback') 704 self.assertMatches( 705 "...Transition 'pay' requires 'started' as source state...", 706 self.browser.contents) 698 # Approve payment 699 # Applicants can't approve payments 700 self.assertRaises( 701 Unauthorized, self.browser.open, payment_url + '/approve') 702 # We approve the payment by bypassing the view 703 payment_id = self.applicant.keys()[0] 704 payment = self.applicant[payment_id] 705 payment.approve() 707 706 # The payment slip can be downloaded now 708 707 self.browser.open(payment_url) … … 711 710 self.assertEqual(self.browser.headers['Content-Type'], 712 711 'application/pdf') 713 # Applicant is is in state 'paid' 712 # Applicant is is not yet in state 'paid' because it was only 713 # the payment which we set to paid 714 714 self.browser.open(self.view_path) 715 self.assertMatches('... paid...',715 self.assertMatches('...started...', 716 716 self.browser.contents) 717 717 state = IWorkflowState(self.applicant).getState() 718 self.assertTrue(state == 'started') 719 # Let's logout and approve the payment as manager 720 self.browser.getLink("Logout").click() 721 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 722 # First we reset the payment 723 payment.r_amount_approved = 0.0 724 payment.r_code = u'' 725 payment.p_state = 'unpaid' 726 payment.r_desc = u'' 727 payment.payment_date = None 728 self.browser.open(payment_url) 729 self.browser.getLink("Approve payment").click() 730 self.assertEqual(payment.p_state, 'paid') 731 self.assertEqual(payment.r_amount_approved, 200.0) 732 self.assertEqual(payment.r_code, 'AP') 733 state = IWorkflowState(self.applicant).getState() 718 734 self.assertTrue(state == 'paid') 735 return 719 736 720 737 def test_final_submit(self): -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py
r8406 r8420 185 185 return self.view.url(self.view.context, self.target) 186 186 187 class RequestCallbackActionButton(ManageActionButton):187 class ApprovePaymentActionButton(ManageActionButton): 188 188 grok.order(2) 189 189 grok.context(IApplicantOnlinePayment) 190 190 grok.view(OnlinePaymentDisplayFormPage) 191 grok.require('waeup. payApplicant')191 grok.require('waeup.managePortal') 192 192 icon = 'actionicon_call.png' 193 text = _('Request callback') 194 target = 'simulate_callback' 195 196 # This button must be neutralized 197 # in the customization package. 193 text = _('Approve payment') 194 target = 'approve' 195 198 196 @property 199 197 def target_url(self): -
main/waeup.kofa/trunk/src/waeup/kofa/payments/interfaces.py
r8260 r8420 130 130 readonly = False, 131 131 ) 132 133 def approve(): 134 "Approve an online payment and set to paid." -
main/waeup.kofa/trunk/src/waeup/kofa/payments/payment.py
r8194 r8420 24 24 from zope.component import getUtility 25 25 from waeup.kofa.interfaces import IKofaUtils 26 from waeup.kofa.interfaces import MessageFactory as _ 26 27 from waeup.kofa.payments.interfaces import ( 27 28 IPayment, ISCPayment, IOnlinePayment, 28 29 payment_states, payment_categories) 29 from waeup.kofa.utils.helpers import attrs_to_fields 30 from waeup.kofa.utils.helpers import attrs_to_fields, get_current_principal 30 31 31 32 class Payment(grok.Container): … … 50 51 return payment_categories.getTermByToken(self.p_category).title 51 52 53 # not used 52 54 class SCPayment(Payment): 53 55 """This is a scratch card payment. … … 74 76 return 75 77 78 def approve(self): 79 "Approve online payment and set to paid." 80 self.r_amount_approved = self.amount_auth 81 self.r_code = u'AP' 82 self.p_state = 'paid' 83 #user = get_current_principal() 84 self.payment_date = datetime.utcnow() 85 return 86 76 87 OnlinePayment = attrs_to_fields(OnlinePayment) -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r8404 r8420 32 32 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState 33 33 from waeup.kofa.accesscodes import ( 34 invalidate_accesscode, get_access_code , create_accesscode)34 invalidate_accesscode, get_access_code) 35 35 from waeup.kofa.accesscodes.workflow import USED 36 36 from waeup.kofa.browser import ( … … 1130 1130 'b':self.context.p_id}) 1131 1131 1132 class OnlinePayment CallbackPage(UtilityView, grok.View):1132 class OnlinePaymentApprovePage(UtilityView, grok.View): 1133 1133 """ Callback view 1134 1134 """ 1135 1135 grok.context(IStudentOnlinePayment) 1136 grok.name('simulate_callback') 1137 grok.require('waeup.payStudent') 1138 1139 # This update method simulates a valid callback und must be 1140 # neutralized in the customization package. 1136 grok.name('approve') 1137 grok.require('waeup.managePortal') 1138 1141 1139 def update(self): 1142 if self.context.p_state == 'paid': 1143 self.flash(_('This ticket has already been paid.')) 1144 return 1145 student = self.context.getStudent() 1146 write_log_message(self,'valid callback: %s' % self.context.p_id) 1147 self.context.r_amount_approved = self.context.amount_auth 1148 self.context.r_code = u'00' 1149 self.context.p_state = 'paid' 1150 self.context.payment_date = datetime.utcnow() 1151 if self.context.p_category == 'clearance': 1152 # Create CLR access code 1153 pin, error = create_accesscode( 1154 'CLR',0,self.context.amount_auth,student.student_id) 1155 if error: 1156 self.flash(_('Valid callback received. ${a}', 1157 mapping = {'a':error})) 1158 return 1159 self.context.ac = pin 1160 elif self.context.p_category == 'schoolfee': 1161 # Create SFE access code 1162 pin, error = create_accesscode( 1163 'SFE',0,self.context.amount_auth,student.student_id) 1164 if error: 1165 self.flash(_('Valid callback received. ${a}', 1166 mapping = {'a':error})) 1167 return 1168 self.context.ac = pin 1169 elif self.context.p_category == 'bed_allocation': 1170 # Create HOS access code 1171 pin, error = create_accesscode( 1172 'HOS',0,self.context.amount_auth,student.student_id) 1173 if error: 1174 self.flash(_('Valid callback received. ${a}', 1175 mapping = {'a':error})) 1176 return 1177 self.context.ac = pin 1178 self.flash(_('Valid callback received.')) 1140 success, msg = self.context.approveStudentPayment() 1141 if success: 1142 write_log_message(self,'valid callback: %s' % self.context.p_id) 1143 self.flash(msg) 1179 1144 return 1180 1145 … … 1182 1147 self.redirect(self.url(self.context, '@@index')) 1183 1148 return 1149 1150 class OnlinePaymentFakeApprovePage(OnlinePaymentApprovePage): 1151 """ Approval view for students. 1152 1153 This view is used for browser tests only and 1154 must be neutralized in custom pages! 1155 """ 1156 1157 grok.name('fake_approve') 1158 grok.require('waeup.payStudent') 1184 1159 1185 1160 class ExportPDFPaymentSlipPage(UtilityView, grok.View): -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r8409 r8420 510 510 ) 511 511 512 def approveStudentPayment(): 513 """Approve payment and create respective activation codes. 514 515 """ 516 512 517 IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[ 513 518 'p_session'].order -
main/waeup.kofa/trunk/src/waeup/kofa/students/payments.py
r8368 r8420 22 22 from zope.component.interfaces import IFactory 23 23 from zope.interface import implementedBy 24 from waeup.kofa.interfaces import MessageFactory as _ 24 25 from waeup.kofa.students.interfaces import ( 25 26 IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment) 26 27 from waeup.kofa.payments import PaymentsContainer, OnlinePayment 27 28 from waeup.kofa.utils.helpers import attrs_to_fields 29 from waeup.kofa.accesscodes import create_accesscode 28 30 29 31 class StudentPaymentsContainer(PaymentsContainer): … … 58 60 return None 59 61 62 def approveStudentPayment(self): 63 """Approve payment and create respective activation code. 64 """ 65 if self.p_state == 'paid': 66 return False, _('This ticket has already been paid.') 67 student = self.getStudent() 68 self.approve() 69 if self.p_category == 'clearance': 70 # Create CLR access code 71 pin, error = create_accesscode( 72 'CLR',0,self.amount_auth,student.student_id) 73 if error: 74 return False, _('Valid callback received. ${a}', 75 mapping = {'a':error}) 76 self.ac = pin 77 elif self.p_category == 'schoolfee': 78 # Create SFE access code 79 pin, error = create_accesscode( 80 'SFE',0,self.amount_auth,student.student_id) 81 if error: 82 return False, _('Valid callback received. ${a}', 83 mapping = {'a':error}) 84 self.ac = pin 85 elif self.p_category == 'bed_allocation': 86 # Create HOS access code 87 pin, error = create_accesscode( 88 'HOS',0,self.amount_auth,student.student_id) 89 if error: 90 return False, _('Valid callback received. ${a}', 91 mapping = {'a':error}) 92 self.ac = pin 93 return True, _('Valid callback received.') 94 60 95 StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment) 61 96 -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r8346 r8420 176 176 configuration.academic_session = 2004 177 177 configuration.clearance_fee = 3456.0 178 configuration.booking_fee = 123.4 178 179 self.app['configuration'].addSessionConfiguration(configuration) 179 180 … … 1288 1289 self.browser.contents) 1289 1290 1290 # Managers can open the callback view which simulates a valid callback1291 # Managers can approve the payment 1291 1292 self.assertEqual(len(self.app['accesscodes']['SFE-0']),0) 1292 1293 self.browser.open(payment_url) 1293 self.browser.getLink(" Request callback").click()1294 self.browser.getLink("Approve payment").click() 1294 1295 self.assertMatches('...Valid callback received...', 1295 1296 self.browser.contents) … … 1299 1300 self.app['accesscodes']['SFE-0'].values()[0].cost,40000.0) 1300 1301 1301 # Callback can't be applied twice1302 self.browser.open(payment_url + '/ simulate_callback')1302 # Payments can't be approved twice 1303 self.browser.open(payment_url + '/approve') 1303 1304 self.assertMatches('...This ticket has already been paid...', 1304 1305 self.browser.contents) … … 1337 1338 self.browser.contents) 1338 1339 1339 # Managers can open the callback view which simulates a valid callback1340 # Managers can approve the payment 1340 1341 self.assertEqual(len(self.app['accesscodes']['CLR-0']),0) 1341 1342 ctrl = self.browser.getControl(name='val_id') 1342 1343 value = ctrl.options[1] # The clearance payment is the second in the table 1343 1344 self.browser.getLink(value).click() 1344 self.browser.open(self.browser.url + '/ simulate_callback')1345 self.browser.open(self.browser.url + '/approve') 1345 1346 self.assertMatches('...Valid callback received...', 1346 1347 self.browser.contents) … … 1372 1373 self.browser.contents) 1373 1374 1374 # Students can open the callback view which simulates a valid callback1375 # Students can't approve the payment 1375 1376 self.assertEqual(len(self.app['accesscodes']['CLR-0']),0) 1376 1377 ctrl = self.browser.getControl(name='val_id') … … 1378 1379 self.browser.getLink(value).click() 1379 1380 payment_url = self.browser.url 1380 self.browser.open(payment_url + '/simulate_callback') 1381 self.assertRaises( 1382 Unauthorized, self.browser.open, payment_url + '/approve') 1383 # In the base package they can 'use' a fake approval view 1384 self.browser.open(payment_url + '/fake_approve') 1381 1385 self.assertMatches('...Valid callback received...', 1382 1386 self.browser.contents) … … 1385 1389 <span>Paid</span> 1386 1390 </td>...''' 1391 expected = '''... 1392 <td> 1393 <span>Paid</span> 1394 </td>...''' 1387 1395 self.assertMatches(expected,self.browser.contents) 1396 payment_id = self.student['payments'].keys()[0] 1397 payment = self.student['payments'][payment_id] 1398 self.assertEqual(payment.p_state, 'paid') 1399 self.assertEqual(payment.r_amount_approved, 3456.0) 1400 self.assertEqual(payment.r_code, 'AP') 1388 1401 # The new CLR-0 pin has been created 1389 1402 self.assertEqual(len(self.app['accesscodes']['CLR-0']),1) … … 1441 1454 self.assertEqual(self.student['payments'][value].p_level, 200) 1442 1455 1443 # Students can open the callback view which simulates a valid callback1456 # We simulate the approval 1444 1457 self.assertEqual(len(self.app['accesscodes']['SFE-0']),0) 1445 self.browser.open(self.browser.url + '/ simulate_callback')1458 self.browser.open(self.browser.url + '/fake_approve') 1446 1459 self.assertMatches('...Valid callback received...', 1447 1460 self.browser.contents) … … 1453 1466 LookupError, self.browser.getControl, name='val_id') 1454 1467 self.browser.open(self.payments_path + '/addop') 1455 self.browser.getControl(name="form.p_category").value = [' gown']1468 self.browser.getControl(name="form.p_category").value = ['bed_allocation'] 1456 1469 self.browser.getControl("Create ticket").click() 1457 1470 self.browser.open(self.payments_path) … … 1495 1508 value = ctrl.options[0] 1496 1509 self.browser.getLink(value).click() 1497 self.browser.open(self.browser.url + '/ simulate_callback')1510 self.browser.open(self.browser.url + '/approve') 1498 1511 # The new HOS-0 pin has been created 1499 1512 self.assertEqual(len(self.app['accesscodes']['HOS-0']),1) … … 1608 1621 return 1609 1622 1610 def test_student_accommodation(self):1623 def xx_test_student_accommodation(self): 1611 1624 # Login 1612 1625 self.browser.open(self.login_path) … … 1624 1637 value = ctrl.options[0] 1625 1638 self.browser.getLink(value).click() 1626 self.browser.open(self.browser.url + '/ simulate_callback')1639 self.browser.open(self.browser.url + '/fake_approve') 1627 1640 # The new HOS-0 pin has been created 1628 1641 self.assertEqual(len(self.app['accesscodes']['HOS-0']),1) -
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r8410 r8420 266 266 academic_session = grok.getSite()['configuration'][session] 267 267 except KeyError: 268 details['error'] = u'Session configuration object is not available.'268 details['error'] = _(u'Session configuration object is not available.') 269 269 return details 270 270 if category == 'schoolfee': … … 284 284 details['p_item'] = self.getAccommodationDetails(student)['bt'] 285 285 details['amount'] = academic_session.booking_fee 286 if details['amount'] in (0.0, None): 287 details['error'] = _(u'Amount could not be determined.') 286 288 return details 287 289 -
main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py
r8323 r8420 328 328 return self.view.url(self.view.context, self.target) 329 329 330 class RequestCallbackActionButton(ManageActionButton): 330 331 class ApprovePaymentActionButton(ManageActionButton): 331 332 grok.order(2) 332 333 grok.context(IStudentOnlinePayment) 333 334 grok.view(OnlinePaymentDisplayFormPage) 334 grok.require('waeup. payStudent')335 grok.require('waeup.managePortal') 335 336 icon = 'actionicon_call.png' 336 text = _('Request callback') 337 target = 'simulate_callback' 338 339 # This button must be neutralized 340 # in the customization package. 337 text = _('Approve payment') 338 target = 'approve' 339 341 340 @property 342 341 def target_url(self):
Note: See TracChangeset for help on using the changeset viewer.