Ignore:
Timestamp:
30 Oct 2013, 19:43:48 (11 years ago)
Author:
Henrik Bettermann
Message:

New students must book and pay for accommodation first, before making school fee payments.

Location:
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py

    r10672 r10675  
    2828from waeup.kofa.configuration import SessionConfiguration
    2929from waeup.kwarapoly.testing import FunctionalLayer
     30from waeup.kwarapoly.students.payments import CustomStudentOnlinePayment
    3031
    3132# Also run tests that send requests to external servers?
     
    7677        notify(grok.ObjectModifiedEvent(self.student))
    7778
     79
     80    def test_schoolfee_ticket_creation(self):
    7881        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    7982        self.browser.open(self.payments_path)
     
    8285        self.browser.getControl(name="form.p_category").value = ['schoolfee']
    8386        self.browser.getControl("Create ticket").click()
     87        self.assertMatches('...Book and pay for accommodation first...',
     88                           self.browser.contents)
     89        # We add a fake maint. payment ticket to meet the condition
     90        maint_payment = CustomStudentOnlinePayment()
     91        self.student['payments']['any_key'] = maint_payment
     92        maint_payment.p_category = 'hostel_maintenance'
     93        maint_payment.p_state = 'unpaid'
     94        maint_payment.p_session = 2004
     95        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     96        self.browser.getControl("Create ticket").click()
     97        self.assertMatches('...Book and pay for accommodation first...',
     98                           self.browser.contents)
     99        # Ticket must be paid
     100        maint_payment.p_state = 'paid'
     101        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     102        self.browser.getControl("Create ticket").click()
    84103        self.assertMatches('...ticket created...',
    85104                           self.browser.contents)
    86105        ctrl = self.browser.getControl(name='val_id')
    87         self.value = ctrl.options[0]
     106        self.value = ctrl.options[1]
    88107        self.browser.getLink(self.value).click()
    89108        self.assertMatches('...Amount Authorized...',
     
    107126
    108127    def test_interswitch_form(self):
     128
     129        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     130        self.browser.open(self.payments_path)
     131        # In KwaraPoly only returning students can create school fee payment
     132        # without haveing paid accommodation fee
     133        IWorkflowState(self.student).setState('returning')
     134        configuration = createObject('waeup.SessionConfiguration')
     135        configuration.academic_session = 2005
     136        self.app['configuration'].addSessionConfiguration(configuration)
     137        self.browser.open(self.payments_path + '/addop')
     138        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     139        self.browser.getControl("Create ticket").click()
     140        self.assertMatches('...ticket created...', self.browser.contents)
     141        ctrl = self.browser.getControl(name='val_id')
     142        self.value = ctrl.options[0]
     143        self.browser.getLink(self.value).click()
     144        self.assertMatches('...Amount Authorized...', self.browser.contents)
     145        self.assertMatches(
     146            '...<span>29500.0</span>...',
     147            self.browser.contents)
     148        self.payment_url = self.browser.url
     149
    109150        # Manager can access InterswitchForm
    110151        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
     
    119160                           self.browser.contents)
    120161        self.assertTrue(
    121             '<input type="hidden" name="amount" value="3940000.0" />' in
    122             self.browser.contents)
    123         self.assertTrue(
    124             'item_name="School Fee" item_amt="3610000" bank_id="120" acct_num="1771180233"' in
     162            '<input type="hidden" name="amount" value="2950000.0" />' in
     163            self.browser.contents)
     164        self.assertTrue(
     165            'item_name="School Fee" item_amt="2620000" bank_id="120" acct_num="1771180233"' in
    125166            self.browser.contents)
    126167        self.assertTrue(
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_browser.py

    r10672 r10675  
    104104        self.browser.getControl(name="form.p_category").value = ['schoolfee']
    105105        self.browser.getControl("Create ticket").click()
     106
     107        self.assertMatches('...Book and pay for accommodation first...',
     108                           self.browser.contents)
     109
     110        # In KwaraPoly only returning students can create school fee payment
     111        # without haveing paid accommodation fee
     112        IWorkflowState(self.student).setState('returning')
     113        configuration = createObject('waeup.SessionConfiguration')
     114        configuration.academic_session = 2005
     115        self.app['configuration'].addSessionConfiguration(configuration)
     116        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     117        self.browser.getControl("Create ticket").click()
    106118        self.assertMatches('...ticket created...',
    107119                           self.browser.contents)
     
    155167        self.browser.open(self.payments_path + '/addop')
    156168        self.browser.getControl(name="form.p_category").value = ['schoolfee']
    157         self.browser.getControl("Create ticket").click()
    158         self.assertMatches('...ticket created...',
    159                            self.browser.contents)
    160         # In state returning we can add a new school fee ticket since
    161         # p_session and p_level is different
    162         IWorkflowState(self.student).setState('returning')
    163         self.browser.open(self.payments_path + '/addop')
    164         self.browser.getControl(name="form.p_category").value = ['schoolfee']
    165         self.browser.getControl("Create ticket").click()
    166         # Uups, we forgot to add a session configuration for next session
    167         self.assertTrue('Session configuration object is not available.'
    168             in self.browser.contents)
    169         configuration = createObject('waeup.SessionConfiguration')
    170         configuration.academic_session = 2005
    171         self.app['configuration'].addSessionConfiguration(configuration)
    172169        self.browser.getControl("Create ticket").click()
    173170        self.assertMatches('...ticket created...',
     
    222219        self.assertEqual(pt_ft(self.student), 'ft')
    223220
     221        error, payment = utils.setPaymentDetails('schoolfee',self.student)
     222        self.assertEqual(error,
     223            'Book and pay for accommodation first before making'
     224            ' school fee payments.')
     225        # We add a fake maint. payment ticket to meet the condition
     226        maint_payment = createObject('waeup.StudentOnlinePayment')
     227        self.student['payments']['any_key'] = maint_payment
     228        maint_payment.p_category = 'hostel_maintenance'
     229        maint_payment.p_state = 'paid'
     230        maint_payment.p_session = 2004
    224231        error, payment = utils.setPaymentDetails('schoolfee',self.student)
    225232        self.assertEqual(payment.p_level, 100)
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py

    r10672 r10675  
    2020from time import time
    2121from zope.component import createObject, getUtility
     22from zope.catalog.interfaces import ICatalog
    2223from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
    2324from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
     
    2526from waeup.kofa.interfaces import CLEARED, RETURNING, IKofaUtils
    2627from waeup.kofa.fees import FeeTable
     28from waeup.kofa.hostels.hostel import NOT_OCCUPIED
    2729from waeup.kwarapoly.interfaces import MessageFactory as _
    2830
     
    124126        new_session = student['studycourse'].current_session + 1
    125127        return new_session, new_level
     128
     129    def _maintPaymentMade(self, student, session):
     130        if len(student['payments']):
     131            for ticket in student['payments'].values():
     132                if ticket.p_category == 'hostel_maintenance' and \
     133                    ticket.p_session == session and ticket.p_state == 'paid':
     134                        return True
     135        return False
     136
     137    def _bedAvailable(self, student):
     138        acc_details  = self.getAccommodationDetails(student)
     139        cat = getUtility(ICatalog, name='beds_catalog')
     140        entries = cat.searchResults(
     141            owner=(student.student_id,student.student_id))
     142        if len(entries):
     143            # Bed has already been booked.
     144            return True
     145        entries = cat.searchResults(
     146            bed_type=(acc_details['bt'],acc_details['bt']))
     147        available_beds = [
     148            entry for entry in entries if entry.owner == NOT_OCCUPIED]
     149        if available_beds:
     150            # Bed has not yet been booked but beds are available.
     151            return True
     152        return False
    126153
    127154    def setPaymentDetails(self, category, student,
     
    170197                if academic_session == None:
    171198                    return _(u'Session configuration object is not available.'), None
     199            if student.state == CLEARED:
     200                # Fresh students must have booked and paid for accommodation.
     201                if self._bedAvailable(student):
     202                    if not self._maintPaymentMade(student, p_session):
     203                        return _('Book and pay for accommodation first '
     204                                 'before making school fee payments.'), None
    172205            if student.state in (RETURNING, CLEARED):
    173206                if p_level in PAYMENT_LEVELS:
Note: See TracChangeset for help on using the changeset viewer.