Changeset 8598
- Timestamp:
- 2 Jun 2012, 08:11:24 (12 years ago)
- Location:
- main/waeup.uniben/trunk/src/waeup/uniben/students
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py
r8506 r8598 178 178 form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( 179 179 'p_category') 180 factory = u'waeup.CustomStudentOnlinePayment'181 182 def _fillCustomFields(self, payment, pay_details):183 # No custom fields at the moment184 return payment185 180 186 181 class CustomOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage): -
main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py
r8473 r8598 30 30 from waeup.uniben.students.batching import CustomStudentProcessor 31 31 from waeup.uniben.testing import FunctionalLayer 32 from waeup.uniben.students.utils import get_school_fee33 32 from waeup.uniben.students.interfaces import ( 34 33 ICustomStudentStudyCourse, ICustomStudent, … … 303 302 return 304 303 305 def test_get_schoolfee(self): 306 self.assertEqual(get_school_fee(self.student),0.0) 307 IWorkflowState(self.student).setState('cleared') 308 self.assertEqual(get_school_fee(self.student),40000.0) 309 IWorkflowState(self.student).setState('returning') 310 self.assertEqual(get_school_fee(self.student),20000.0) 311 return 312 313 def test_get_payment_details(self): 304 def test_set_payment_details(self): 314 305 self.app['configuration']['2004'].gown_fee = 150.0 315 306 self.app['configuration']['2004'].transfer_fee = 90.0 … … 317 308 self.app['configuration']['2004'].maint_fee = 180.0 318 309 utils = getUtility(IStudentsUtils) 319 self.assertEqual(utils.getPaymentDetails('schoolfee',self.student), 320 {'p_level': 100, 'p_session': 2004, 'amount': 0.0, 321 'p_item': u'CERT1', 'error': u'Amount could not be determined.'} 322 ) 323 self.assertEqual(utils.getPaymentDetails('clearance',self.student), 324 {'p_level': 100, 'p_session': 2004, 'amount': 34250.0, 325 'p_item': u'CERT1', 'error': u''} 326 ) 327 self.assertEqual(utils.getPaymentDetails('gown',self.student), 328 {'p_level': 100, 'p_session': 2004, 'amount': 150.0, 329 'p_item': u'', 'error': u''} 330 ) 331 self.assertEqual(utils.getPaymentDetails('hostel_maintenance',self.student), 332 {'p_level': 100, 'p_session': 2004, 'amount': 180.0, 333 'p_item': u'', 'error': u''} 334 ) 335 self.assertEqual(utils.getPaymentDetails('bed_allocation',self.student), 336 {'p_level': 100, 'p_session': 2004, 'amount': 150.0, 337 'p_item': u'', 'error': u''} 338 ) 339 self.assertEqual(utils.getPaymentDetails('transfer',self.student), 340 {'p_level': 100, 'p_session': 2004, 'amount': 90.0, 341 'p_item': u'', 'error': u''} 342 ) 310 311 error, payment = utils.setPaymentDetails('schoolfee',self.student) 312 self.assertEqual(payment, None) 313 self.assertEqual(error, u'Amount could not be determined.') 314 315 IWorkflowState(self.student).setState('cleared') 316 error, payment = utils.setPaymentDetails('schoolfee',self.student) 317 self.assertEqual(payment.p_level, 100) 318 self.assertEqual(payment.p_session, 2004) 319 self.assertEqual(payment.amount_auth, 40000.0) 320 self.assertEqual(payment.p_item, u'CERT1') 321 self.assertEqual(error, None) 322 323 IWorkflowState(self.student).setState('returning') 324 error, payment = utils.setPaymentDetails('schoolfee',self.student) 325 self.assertEqual(payment.p_level, 200) 326 self.assertEqual(payment.p_session, 2005) 327 self.assertEqual(payment.amount_auth, 20000.0) 328 self.assertEqual(payment.p_item, u'CERT1') 329 self.assertEqual(error, None) 330 331 error, payment = utils.setPaymentDetails('clearance',self.student) 332 self.assertEqual(payment.p_level, 100) 333 self.assertEqual(payment.p_session, 2004) 334 self.assertEqual(payment.amount_auth, 34250.0) 335 self.assertEqual(payment.p_item, u'CERT1') 336 self.assertEqual(error, None) 337 338 error, payment = utils.setPaymentDetails('gown',self.student) 339 self.assertEqual(payment.p_level, 100) 340 self.assertEqual(payment.p_session, 2004) 341 self.assertEqual(payment.amount_auth, 150.0) 342 self.assertEqual(payment.p_item, u'') 343 self.assertEqual(error, None) 344 345 error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) 346 self.assertEqual(payment.p_level, 100) 347 self.assertEqual(payment.p_session, 2004) 348 self.assertEqual(payment.amount_auth, 180.0) 349 self.assertEqual(payment.p_item, u'') 350 self.assertEqual(error, None) 351 352 error, payment = utils.setPaymentDetails('bed_allocation',self.student) 353 self.assertEqual(payment.p_level, 100) 354 self.assertEqual(payment.p_session, 2004) 355 self.assertEqual(payment.amount_auth, 150.0) 356 self.assertEqual(payment.p_item, u'') 357 self.assertEqual(error, None) 358 359 error, payment = utils.setPaymentDetails('transfer',self.student) 360 self.assertEqual(payment.p_level, 100) 361 self.assertEqual(payment.p_session, 2004) 362 self.assertEqual(payment.amount_auth, 90.0) 363 self.assertEqual(payment.p_item, u'') 364 self.assertEqual(error, None) 343 365 return -
main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py
r8473 r8598 17 17 ## 18 18 import grok 19 from time import time 20 from zope.component import createObject 19 21 from waeup.kofa.interfaces import CLEARED, RETURNING, PAID 20 22 from waeup.kofa.students.utils import StudentsUtils … … 23 25 from waeup.uniben.interfaces import MessageFactory as _ 24 26 25 def get_school_fee(student):26 state = student.state27 fee = None28 if state == CLEARED:29 fee = getattr(student['studycourse'].certificate,'school_fee_1')30 elif state == RETURNING:31 fee = getattr(student['studycourse'].certificate,'school_fee_2')32 if fee is not None:33 return fee34 return 0.035 36 27 class CustomStudentsUtils(StudentsUtils): 37 28 """A collection of customized methods. … … 39 30 """ 40 31 grok.implements(IStudentsUtils) 32 33 paymentfactory = u'waeup.CustomStudentOnlinePayment' 41 34 42 35 def getReturningData(self, student): … … 59 52 return new_session, new_level 60 53 61 def getPaymentDetails(self, category, student): 54 def setPaymentDetails(self, category, student): 55 """Create Payment object and set the payment data of a student for 56 the payment category specified. 57 58 """ 62 59 details = {} 63 details['p_item']= u''64 details['amount']= 0.065 details['error']= u''66 details['p_session']= student['studycourse'].current_session67 session = str(details['p_session'])68 details['p_level'] = student['studycourse'].current_level60 p_item = u'' 61 amount = 0.0 62 error = u'' 63 p_session = student['studycourse'].current_session 64 p_level = student['studycourse'].current_level 65 session = str(p_session) 69 66 try: 70 67 academic_session = grok.getSite()['configuration'][session] 71 68 except KeyError: 72 details['error'] = _(u'Session configuration object is not available.') 73 return details 69 return _(u'Session configuration object is not available.'), None 74 70 if category == 'transfer': 75 details['amount']= academic_session.transfer_fee71 amount = academic_session.transfer_fee 76 72 elif category == 'gown': 77 details['amount']= academic_session.gown_fee73 amount = academic_session.gown_fee 78 74 elif category == 'bed_allocation': 79 details['amount']= academic_session.booking_fee75 amount = academic_session.booking_fee 80 76 elif category == 'hostel_maintenance': 81 details['amount']= academic_session.maint_fee77 amount = academic_session.maint_fee 82 78 elif category == 'clearance': 83 details['p_item'] = student['studycourse'].certificate.code 84 if details['p_item'] in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', 79 try: 80 p_item = student['studycourse'].certificate.code 81 except (AttributeError, TypeError): 82 return _('Study course data are incomplete.'), None 83 if p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', 85 84 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): 86 details['amount']= 17250.085 amount = 17250.0 87 86 else: 88 details['amount']= 34250.087 amount = 34250.0 89 88 elif category == 'schoolfee': 90 details['amount'] = get_school_fee(student) 91 code = student['studycourse'].certificate.code 92 details['p_item'] = code 93 if student.state == RETURNING: 89 try: 90 certificate = student['studycourse'].certificate 91 p_item = certificate.code 92 except (AttributeError, TypeError): 93 return _('Study course data are incomplete.'), None 94 if student.state == CLEARED: 95 amount = getattr(certificate, 'school_fee_1', 0.0) 96 elif student.state == RETURNING: 94 97 # In case of returning school fee payment the payment session 95 98 # and level contain the values of the session the student 96 99 # has paid for. 97 details['p_session'], details['p_level'] = self.getReturningData(student) 98 elif student.current_mode.startswith('pg') and student.state == PAID: 100 p_session, p_level = self.getReturningData(student) 101 amount = getattr(certificate, 'school_fee_2', 0.0) 102 elif student.is_postgrad and student.state == PAID: 99 103 # Returning postgraduate students also pay for the next session 100 104 # but their level always remains the same. 101 details['p_session'] += 1 102 details['amount'] = getattr( 103 student['studycourse'].certificate,'school_fee_2') 104 if details['amount'] in (0.0, None): 105 details['error'] = _(u'Amount could not be determined.') 106 return details 105 p_session += 1 106 amount = getattr(certificate, 'school_fee_2', 0.0) 107 if amount in (0.0, None): 108 return _(u'Amount could not be determined.'), None 109 for key in student['payments'].keys(): 110 ticket = student['payments'][key] 111 if ticket.p_state == 'paid' and\ 112 ticket.p_category == category and \ 113 ticket.p_item == p_item and \ 114 ticket.p_session == p_session: 115 return _('This type of payment has already been made.'), None 116 payment = createObject(self.paymentfactory) 117 timestamp = "%d" % int(time()*1000) 118 payment.p_id = "p%s" % timestamp 119 payment.p_category = category 120 payment.p_item = p_item 121 payment.p_session = p_session 122 payment.p_level = p_level 123 payment.amount_auth = amount 124 return None, payment 107 125 108 126 VERDICTS_DICT = {
Note: See TracChangeset for help on using the changeset viewer.