Ignore:
Timestamp:
3 Sep 2012, 14:47:24 (12 years ago)
Author:
Henrik Bettermann
Message:

Enable previous session payments. Do not create activation code after successful previous session payment. Show previous session payment form only if current session ticket creation failed.

Attention: setPaymentDetails method has changed. Two additional parameters expected.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r9141 r9148  
    5555    IStudentAccommodation, IStudentStudyLevel,
    5656    ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer,
    57     IStudentOnlinePayment, IBedTicket, IStudentsUtils, IStudentRequestPW
     57    IStudentOnlinePayment, IStudentPreviousPayment,
     58    IBedTicket, IStudentsUtils, IStudentRequestPW
    5859    )
    5960from waeup.kofa.students.catalog import search
     
    12131214    def createTicket(self, **data):
    12141215        p_category = data['p_category']
     1216        previous_session = data.get('p_session', None)
     1217        previous_level = data.get('p_level', None)
    12151218        student = self.context.__parent__
    12161219        if p_category == 'bed_allocation' and student[
     
    12231226                return
    12241227        students_utils = getUtility(IStudentsUtils)
    1225         error, payment = students_utils.setPaymentDetails(p_category, student)
     1228        error, payment = students_utils.setPaymentDetails(
     1229            p_category, student, previous_session, previous_level)
    12261230        if error is not None:
    12271231            self.flash(error)
     1232            if 'Would you like' in error:
     1233                self.redirect(self.url(self.context) + '/@@addpp')
     1234                return
    12281235            self.redirect(self.url(self.context))
    12291236            return
     
    12321239        self.redirect(self.url(self.context))
    12331240        return
     1241
     1242class PreviousPaymentAddFormPage(OnlinePaymentAddFormPage):
     1243    """ Page to add an online payment ticket for previous sessions
     1244    """
     1245    grok.context(IStudentPaymentsContainer)
     1246    grok.name('addpp')
     1247    grok.require('waeup.payStudent')
     1248    form_fields = grok.AutoFields(IStudentPreviousPayment).select(
     1249        'p_category', 'p_session', 'p_level')
     1250    label = _('Add previous session online payment')
     1251    pnav = 4
    12341252
    12351253class OnlinePaymentDisplayFormPage(KofaDisplayFormPage):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r9142 r9148  
    6666        """
    6767
    68     def setPaymentDetails(category, student):
     68    def setPaymentDetails(category, student, previous_session=None,
     69            previous_level=None,):
    6970        """Create Payment object and set the payment data of a student for
    7071        the payment category specified.
     
    560561    """
    561562
     563    p_current = schema.Bool(
     564        title = _(u'Current Session Payment'),
     565        default = True,
     566        required = False,
     567        readonly = True,
     568        )
     569
    562570    p_level = schema.Int(
    563571        title = _(u'Payment Level'),
     
    583591IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
    584592    'p_session'].order
     593
     594class IStudentPreviousPayment(IOnlinePayment):
     595    """An interface for adding previous session payments.
     596
     597    """
     598
     599    p_session = schema.Choice(
     600        title = _(u'Payment Session'),
     601        source = academic_sessions_vocab,
     602        required = True,
     603        )
     604
     605    p_level = schema.Choice(
     606        title = _(u'Payment Level'),
     607        source = StudyLevelSource(),
     608        required = True,
     609        )
    585610
    586611class ICSVStudentExporter(ICSVExporter):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/payments.py

    r8736 r9148  
    9797        """Process student after payment was made.
    9898        """
    99         error = self._createActivationCodes()
    100         if error is not None:
    101             return False, error, error
     99        if self.p_current:
     100            error = self._createActivationCodes()
     101            if error is not None:
     102                return False, error, error
    102103        log = 'successful payment: %s' % self.p_id
    103104        msg = _('Successful payment')
     
    107108        """Process student after payment was approved.
    108109        """
    109         error = self._createActivationCodes()
    110         if error is not None:
    111             return False, error, error
     110        if self.p_current:
     111            error = self._createActivationCodes()
     112            if error is not None:
     113                return False, error, error
    112114        log = 'payment approved: %s' % self.p_id
    113115        msg = _('Payment approved')
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9139 r9148  
    15751575        return
    15761576
    1577     def test_postgraduate_payments(self):
     1577    def test_student_previous_payments(self):
     1578        # Login
     1579        self.browser.open(self.login_path)
     1580        self.browser.getControl(name="form.login").value = self.student_id
     1581        self.browser.getControl(name="form.password").value = 'spwd'
     1582        self.browser.getControl("Login").click()
     1583
     1584        # Students can add previous school fee payment tickets in any state.
     1585        IWorkflowState(self.student).setState('courses registered')
     1586        self.browser.open(self.payments_path)
     1587        self.browser.getControl("Add online payment ticket").click()
     1588        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     1589        self.browser.getControl("Create ticket").click()
     1590
     1591        # Amount cannot be determined since the state is not
     1592        # 'cleared' or 'returning'
     1593        self.assertMatches('...Amount could not be determined...',
     1594                           self.browser.contents)
     1595        self.assertMatches('...Would you like to pay for a previous session?...',
     1596                           self.browser.contents)
     1597
     1598        # Previous session payment form is provided
     1599        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     1600        self.browser.getControl(name="form.p_session").value = ['2004']
     1601        self.browser.getControl(name="form.p_level").value = ['300']
     1602        self.browser.getControl("Create ticket").click()
     1603        self.assertMatches('...ticket created...',
     1604                           self.browser.contents)
     1605        ctrl = self.browser.getControl(name='val_id')
     1606        value = ctrl.options[0]
     1607        self.browser.getLink(value).click()
     1608        self.assertMatches('...Amount Authorized...',
     1609                           self.browser.contents)
     1610        self.assertEqual(self.student['payments'][value].amount_auth, 20000.0)
     1611
     1612        # Payment session is properly set
     1613        self.assertEqual(self.student['payments'][value].p_session, 2004)
     1614        self.assertEqual(self.student['payments'][value].p_level, 300)
     1615
     1616        # We simulate the approval
     1617        self.browser.open(self.browser.url + '/fake_approve')
     1618        self.assertMatches('...Payment approved...',
     1619                          self.browser.contents)
     1620
     1621        # No AC has been created
     1622        self.assertEqual(len(self.app['accesscodes']['SFE-0'].keys()), 0)
     1623        self.assertTrue(self.student['payments'][value].ac is None)
     1624
     1625        # Current payment flag is set False
     1626        self.assertFalse(self.student['payments'][value].p_current)
     1627        return
     1628
     1629    def test_student_postgraduate_payments(self):
    15781630        self.certificate.study_mode = 'pg_ft'
    15791631        self.certificate.start_level = 999
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9028 r9148  
    371371        self.assertEqual(
    372372            result,
    373             'ac,amount_auth,creation_date,p_category,p_id,'
     373            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
    374374            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
    375375            'r_code,r_desc,student_id\r\n'
    376376
    377             ',0.0,2012-04-01 13:12:01,schoolfee,,,,,unpaid,,0.0,,,\r\n'
     377            ',0.0,2012-04-01 13:12:01,schoolfee,1,,,,,unpaid,,0.0,,,\r\n'
    378378            )
    379379        return
     
    389389        self.assertEqual(
    390390            result,
    391             'ac,amount_auth,creation_date,p_category,p_id,'
     391            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
    392392            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
    393393            'r_code,r_desc,student_id\r\n'
    394394
    395             '666,0.0,2012-04-01 13:12:01,schoolfee,my-id,'
     395            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
    396396            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
    397397            'r-code,,A111111\r\n'
     
    408408        self.assertEqual(
    409409            result,
    410             'ac,amount_auth,creation_date,p_category,p_id,'
     410            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
    411411            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
    412412            'r_code,r_desc,student_id\r\n'
    413413
    414             '666,0.0,2012-04-01 13:12:01,schoolfee,my-id,'
     414            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
    415415            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
    416416            'r-code,,A111111\r\n'
     
    427427        self.assertEqual(
    428428            result,
    429             'ac,amount_auth,creation_date,p_category,p_id,'
     429            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
    430430            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
    431431            'r_code,r_desc,student_id\r\n'
    432432
    433             '666,0.0,2012-04-01 13:12:01,schoolfee,my-id,'
     433            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
    434434            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
    435435            'r-code,,A111111\r\n'
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r9141 r9148  
    281281        return
    282282
    283     def setPaymentDetails(self, category, student):
     283    def setPaymentDetails(self, category, student,
     284            previous_session=None, previous_level=None):
    284285        """Create Payment object and set the payment data of a student for
    285286        the payment category specified.
     
    288289        p_item = u''
    289290        amount = 0.0
    290         p_session = student['studycourse'].current_session
    291         p_level = student['studycourse'].current_level
     291        if previous_session:
     292            p_session = previous_session
     293            p_level = previous_level
     294            p_current = False
     295        else:
     296            p_session = student['studycourse'].current_session
     297            p_level = student['studycourse'].current_level
     298            p_current = True
    292299        session = str(p_session)
    293300        try:
     
    301308            except (AttributeError, TypeError):
    302309                return _('Study course data are incomplete.'), None
    303             if student.state == CLEARED:
    304                 amount = getattr(certificate, 'school_fee_1', 0.0)
    305             elif student.state == RETURNING:
    306                 # In case of returning school fee payment the payment session
    307                 # and level contain the values of the session the student
    308                 # has paid for.
    309                 p_session, p_level = self.getReturningData(student)
    310                 amount = getattr(certificate, 'school_fee_2', 0.0)
    311             elif student.is_postgrad and student.state == PAID:
    312                 # Returning postgraduate students also pay for the next session
    313                 # but their level always remains the same.
    314                 p_session += 1
    315                 amount = getattr(certificate, 'school_fee_2', 0.0)
     310            if previous_session:
     311                if previous_level == 100:
     312                    amount = getattr(certificate, 'school_fee_1', 0.0)
     313                else:
     314                    amount = getattr(certificate, 'school_fee_2', 0.0)
     315            else:
     316                if student.state == CLEARED:
     317                    amount = getattr(certificate, 'school_fee_1', 0.0)
     318                elif student.state == RETURNING:
     319                    # In case of returning school fee payment the payment session
     320                    # and level contain the values of the session the student
     321                    # has paid for.
     322                    p_session, p_level = self.getReturningData(student)
     323                    amount = getattr(certificate, 'school_fee_2', 0.0)
     324                elif student.is_postgrad and student.state == PAID:
     325                    # Returning postgraduate students also pay for the next session
     326                    # but their level always remains the same.
     327                    p_session += 1
     328                    amount = getattr(certificate, 'school_fee_2', 0.0)
    316329        elif category == 'clearance':
    317330            p_item = student['studycourse'].certificate.code
     
    321334            amount = academic_session.booking_fee
    322335        if amount in (0.0, None):
    323             return _(u'Amount could not be determined.'), None
     336            return _('Amount could not be determined.' +
     337                     ' Would you like to pay for a previous session?'), None
    324338        for key in student['payments'].keys():
    325339            ticket = student['payments'][key]
     
    328342               ticket.p_item == p_item and \
    329343               ticket.p_session == p_session:
    330                   return _('This type of payment has already been made.'), None
     344                  return _('This type of payment has already been made.' +
     345                           ' Would you like to pay for a previous session?'), None
    331346        payment = createObject(u'waeup.StudentOnlinePayment')
    332347        timestamp = ("%d" % int(time()*10000))[1:]
     
    336351        payment.p_session = p_session
    337352        payment.p_level = p_level
     353        payment.p_current = p_current
    338354        payment.amount_auth = amount
    339355        return None, payment
     
    358374            return
    359375        end_level = certificate.end_level
    360         if entry_session == grok.getSite()['hostels'].accommodation_session:
     376        if current_level == 10:
     377            bt = 'pr'
     378        elif entry_session == grok.getSite()['hostels'].accommodation_session:
    361379            bt = 'fr'
    362380        elif current_level >= end_level:
Note: See TracChangeset for help on using the changeset viewer.