Ignore:
Timestamp:
4 Nov 2012, 07:48:11 (12 years ago)
Author:
Henrik Bettermann
Message:

Reorganize getReturningData.

Students can pay for previous sessions in all workflow states.
Fresh students are excluded by the update method of the
PreviousPaymentAddFormPage?.

Students are only allowed to pay for the next session if current session payment has really been made, i.e. payment object exists and is paid.

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

Legend:

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

    r9515 r9520  
    9797            self.browser.contents)
    9898
    99         # Create school fee ticket for returning students
     99        # Create school fee ticket for returning students. Payment is made
     100        # for next session.
     101        current_payment_key = self.student['payments'].keys()[0]
    100102        self.certificate.study_mode = u'ug_pt'
    101103        IWorkflowState(self.student).setState('returning')
     
    103105        configuration.academic_session = 2005
    104106        self.app['configuration'].addSessionConfiguration(configuration)
     107        self.browser.open(self.payments_path + '/addop')
     108        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     109        self.browser.getControl("Create ticket").click()
     110        # Next session payment can't be made ...
     111        self.assertMatches(
     112            '...You have not yet paid your current/active session...',
     113            self.browser.contents)
     114        # current session payment must be approved first.
     115        self.student['payments'][current_payment_key].approve()
    105116        self.browser.open(self.payments_path + '/addop')
    106117        self.browser.getControl(name="form.p_category").value = ['schoolfee']
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r9513 r9520  
    214214        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    215215        self.browser.open(self.payments_path)
    216         self.browser.getControl("Add online payment ticket").click()
     216        self.browser.getLink("Add current session payment ticket").click()
    217217        self.browser.getControl("Create ticket").click()
    218218        self.assertMatches('...Amount could not be determined...',
     
    248248        self.assertMatches('...ticket created...',
    249249                           self.browser.contents)
     250        schoolfee_ticket = self.student['payments'].values()[0]
    250251        self.browser.open(self.payments_path + '/addop')
    251252        self.browser.getControl(name="form.p_category").value = ['gown']
     
    286287        self.browser.getControl(name="form.p_category").value = ['schoolfee']
    287288        self.browser.getControl("Create ticket").click()
     289        # Uups, we forgot to add a session configuration for next session
    288290        self.assertMatches('...Session configuration object is not...',
    289291                           self.browser.contents)
    290         # Uups, we forgot to add a session configuration for next session
    291292        configuration = createObject('waeup.SessionConfiguration')
    292293        configuration.academic_session = 2005
    293294        self.app['configuration'].addSessionConfiguration(configuration)
     295        self.browser.open(self.payments_path + '/addop')
     296        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     297        self.browser.getControl("Create ticket").click()
     298        self.assertMatches('...You have not yet paid your current/active session...',
     299                           self.browser.contents)
     300        # Ok, let's pay the first schoolfee ticket.
     301        schoolfee_ticket.approve()
    294302        self.browser.open(self.payments_path + '/addop')
    295303        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     
    309317        del self.app['configuration']['2004']
    310318        self.browser.open(self.payments_path)
    311         self.browser.getControl("Add online payment ticket").click()
     319        self.browser.getLink("Add current session payment ticket").click()
    312320        self.browser.getControl("Create ticket").click()
    313321        self.assertMatches('...Session configuration object is not...',
     
    375383            self.student, None, None)
    376384        self.assertEqual(payment, None)
     385        # Student is in state 'created' and can thus not pay.
    377386        self.assertTrue(u'Amount could not be determined.' in error)
    378387
     
    383392        self.assertTrue(u'The previous session must not fall below' in error)
    384393        error, payment = utils.setPaymentDetails('schoolfee',
    385             self.student, 2004, 300)
     394            self.student, 2005, 300)
    386395        self.assertEqual(payment, None)
    387396        self.assertTrue(u'This is not a previous session' in error)
    388397
    389         # Previous session payment; fresh and returning
     398        # Previous session schoolfee payment; fresh and returning
    390399        # are distinguished by their entry_level
    391400        error, payment = utils.setPaymentDetails('schoolfee',
     
    402411        self.assertFalse(payment.p_current)
    403412
    404         # Current payment; fresh and returning
     413        # Current schoolfee payment; fresh and returning
    405414        # are distinguished by their state
    406415        IWorkflowState(self.student).setState('cleared')
     
    426435        error, payment = utils.setPaymentDetails('schoolfee',
    427436            self.student, None, None)
     437        self.assertTrue(
     438            u'You have not yet paid your current/active session.' in error)
     439        # Ok, that means we have to add paid payment ticket first.
     440        payment = createObject('waeup.StudentOnlinePayment')
     441        payment.p_category = u'schoolfee'
     442        payment.p_session = self.student.current_session
     443        payment.p_item = u'My Certificate'
     444        payment.p_id = u'anyid'
     445        payment.p_state = u'paid'
     446        self.student['payments']['anykey'] = payment
     447        error, payment = utils.setPaymentDetails('schoolfee',
     448            self.student, None, None)
    428449        self.assertEqual(payment.p_level, 200)
    429450        self.assertEqual(payment.p_session, 2005)
     
    431452        self.assertEqual(payment.p_item, u'CERT1')
    432453        self.assertEqual(error, None)
     454
     455        # Staff members pay less.
    433456        self.student.is_staff = True
    434457        error, payment = utils.setPaymentDetails('schoolfee',
     
    440463        self.assertEqual(error, None)
    441464
     465        # Foreigners pay more.
    442466        IWorkflowState(self.student).setState('cleared')
    443467        self.student.is_staff = False
     
    451475        self.assertEqual(payment.p_item, u'CERT1')
    452476        self.assertEqual(error, None)
    453 
    454477        IWorkflowState(self.student).setState('returning')
    455478        self.student.is_staff = False
    456         self.student.nationality = u'DE'
    457479        self.certificate.school_fee_4 = 20000.0
    458480        error, payment = utils.setPaymentDetails(
     
    467489        # if they are ug or pg students.
    468490        IWorkflowState(self.student).setState('school fee paid')
    469         self.certificate.study_mode = 'special_pg_pt'
    470491        self.student.is_staff = False
    471492        self.student.nationality = u'NG'
    472493        self.certificate.school_fee_2 = 10000.0
    473 
     494        error, payment = utils.setPaymentDetails(
     495            'schoolfee', self.student, None, None)
     496        self.assertEqual(payment.p_level, None)
     497        self.assertEqual(payment.p_session, 2005)
     498        self.assertEqual(payment.amount_auth, 10088.0)
     499        self.assertEqual(payment.p_item, u'CERT1')
     500        self.assertEqual(error, None)
     501        IWorkflowState(self.student).setState('courses registered')
     502        self.certificate.study_mode = 'special_pg_pt'
    474503        error, payment = utils.setPaymentDetails(
    475504            'schoolfee', self.student, None, None)
     
    479508        self.assertEqual(payment.p_item, u'CERT1')
    480509        self.assertEqual(error, None)
    481 
    482         IWorkflowState(self.student).setState('courses registered')
    483         error, payment = utils.setPaymentDetails(
    484             'schoolfee', self.student, None, None)
    485         self.assertEqual(payment.p_level, None)
    486         self.assertEqual(payment.p_session, 2005)
    487         self.assertEqual(payment.amount_auth, 10000.0)
    488         self.assertEqual(payment.p_item, u'CERT1')
    489         self.assertEqual(error, None)
    490 
    491510        IWorkflowState(self.student).setState('courses validated')
    492511        error, payment = utils.setPaymentDetails(
  • main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py

    r9513 r9520  
    5353        return new_session, new_level
    5454
     55    def _paymentMade(self, student, session):
     56        if len(student['payments']):
     57            for ticket in student['payments'].values():
     58                if ticket.p_state == 'paid' and \
     59                    ticket.p_category == 'schoolfee' and \
     60                    ticket.p_session == session:
     61                    return True
     62        return False
     63
    5564    def setPaymentDetails(self, category, student,
    5665            previous_session, previous_level):
     
    5968
    6069        """
    61         details = {}
    6270        p_item = u''
    6371        amount = 0.0
    64         error = u''
    6572        if previous_session:
     73            if previous_session < student['studycourse'].entry_session:
     74                return _('The previous session must not fall below '
     75                         'your entry session.'), None
     76            if category == 'schoolfee':
     77                # School fee is always paid for the following session
     78                if previous_session > student['studycourse'].current_session:
     79                    return _('This is not a previous session.'), None
     80            else:
     81                if previous_session > student['studycourse'].current_session - 1:
     82                    return _('This is not a previous session.'), None
    6683            p_session = previous_session
    6784            p_level = previous_level
     
    7188            p_level = student['studycourse'].current_level
    7289            p_current = True
    73         session = str(p_session)
    74         try:
    75             academic_session = grok.getSite()['configuration'][session]
    76         except KeyError:
     90        academic_session = self._getSessionConfiguration(p_session)
     91        if academic_session == None:
    7792            return _(u'Session configuration object is not available.'), None
    7893        # Determine fee.
     
    105120                return _('Study course data are incomplete.'), None
    106121            if previous_session:
    107                 if previous_session < student['studycourse'].entry_session:
    108                     return _('The previous session must not fall below '
    109                              'your entry session.'), None
    110                 if previous_session > student['studycourse'].current_session - 1:
    111                     return _('This is not a previous session.'), None
     122                # Students can pay for previous sessions in all workflow states.
     123                # Fresh students are excluded by the update method of the
     124                # PreviousPaymentAddFormPage.
    112125                if previous_session == student['studycourse'].entry_session:
    113126                    if student.is_foreigner:
     
    127140                        amount = getattr(certificate, 'school_fee_1', 0.0)
    128141                elif student.state in (PAID, REGISTERED, VALIDATED):
    129                     # Students are either postgraduate or are paying in advance.
    130                     # Both are paying for next session.
    131142                    p_session += 1
    132143                    # We don't know which level the student is paying for.
    133144                    p_level = None
    134                     try:
    135                         academic_session = grok.getSite()[
    136                             'configuration'][str(p_session)]
    137                     except KeyError:
     145                    academic_session = self._getSessionConfiguration(p_session)
     146                    if academic_session == None:
    138147                        return _(u'Session configuration object is not available.'), None
     148                    # Students are only allowed to pay for the next session
     149                    # if current session payment
     150                    # has really been made, i.e. payment object exists.
     151                    if not self._paymentMade(
     152                        student, student.current_session):
     153                        return _('You have not yet paid your current/active' +
     154                                 ' session. Please use the previous session' +
     155                                 ' payment form first.'), None
    139156                    if student.is_foreigner:
    140157                        amount = getattr(certificate, 'school_fee_4', 0.0)
     
    146163                    # has paid for.
    147164                    p_session, p_level = self.getReturningData(student)
    148                     try:
    149                         academic_session = grok.getSite()[
    150                             'configuration'][str(p_session)]
    151                     except KeyError:
     165                    academic_session = self._getSessionConfiguration(p_session)
     166                    if academic_session == None:
    152167                        return _(u'Session configuration object is not available.'), None
     168                    # Students are only allowed to pay for the next session
     169                    # if current session payment has really been made,
     170                    # i.e. payment object exists and is paid.
     171                    if not self._paymentMade(
     172                        student, student.current_session):
     173                        return _('You have not yet paid your current/active' +
     174                                 ' session. Please use the previous session' +
     175                                 ' payment form first.'), None
    153176                    if student.is_foreigner:
    154177                        amount = getattr(certificate, 'school_fee_4', 0.0)
     
    159182                amount /= 2
    160183        if amount in (0.0, None):
    161             return _('Amount could not be determined.' +
    162                      ' Would you like to pay for a previous session?'), None
     184            return _('Amount could not be determined.'), None
    163185        # Add session specific penalty fee.
    164186        if category == 'schoolfee' and student.is_postgrad:
     
    173195               ticket.p_item == p_item and \
    174196               ticket.p_session == p_session:
    175                   return _('This type of payment has already been made.' +
    176                            ' Would you like to pay for a previous session?'), None
     197                  return _('This type of payment has already been made.'), None
    177198        payment = createObject(u'waeup.StudentOnlinePayment')
    178199        timestamp = ("%d" % int(time()*10000))[1:]
Note: See TracChangeset for help on using the changeset viewer.