Ignore:
Timestamp:
4 Sep 2012, 07:06:20 (12 years ago)
Author:
Henrik Bettermann
Message:

Implement previous session payment.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py

    r8866 r9152  
    7171    """
    7272
     73    p_current = schema.Bool(
     74        title = _(u'Current Session Payment'),
     75        default = True,
     76        required = False,
     77        )
     78
    7379    p_level = schema.Int(
    7480        title = _(u'Payment Level'),
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r9006 r9152  
    221221        utils = getUtility(IStudentsUtils)
    222222
     223        self.student.nationality = u'NG'
     224
    223225        configuration = createObject('waeup.SessionConfiguration')
    224226        configuration.academic_session = 2005
    225227        self.app['configuration'].addSessionConfiguration(configuration)
    226228
    227         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     229        error, payment = utils.setPaymentDetails('schoolfee',
     230            self.student, None, None)
    228231        self.assertEqual(payment, None)
    229         self.assertEqual(error, u'Amount could not be determined.')
    230 
     232        self.assertTrue(u'Amount could not be determined.' in error)
     233
     234        # Previous session payment, fresh and returning
     235        # are being distinguished by their entry_level
     236        error, payment = utils.setPaymentDetails('schoolfee',
     237            self.student, 2004, 300)
     238        self.assertEqual(payment.amount_auth, 40000.0)
     239        self.assertEqual(payment.p_session, 2004)
     240        self.assertEqual(payment.p_level, 300)
     241        self.assertFalse(payment.p_current)
     242        self.student['studycourse'].entry_session = 2003
     243        error, payment = utils.setPaymentDetails('schoolfee',
     244            self.student, 2004, 300)
     245        self.assertEqual(payment.amount_auth, 20000.0)
     246        self.assertEqual(payment.p_session, 2004)
     247        self.assertEqual(payment.p_level, 300)
     248        self.assertFalse(payment.p_current)
     249
     250        # Current payment, fresh and returning
     251        # are being distinguished by their state
    231252        IWorkflowState(self.student).setState('cleared')
    232         self.student.nationality = u'NG'
    233         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     253        error, payment = utils.setPaymentDetails('schoolfee',
     254            self.student, None, None)
    234255        self.assertEqual(payment.p_level, 100)
    235256        self.assertEqual(payment.p_session, 2004)
     
    237258        self.assertEqual(payment.p_item, u'CERT1')
    238259        self.assertEqual(error, None)
     260        self.assertTrue(payment.p_current)
    239261
    240262        # Add penalty fee ...
     
    243265        # ... for returning
    244266        self.app['configuration']['2005'].penalty_ug = 88.0
    245         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     267        error, payment = utils.setPaymentDetails('schoolfee',
     268            self.student, None, None)
    246269        self.assertEqual(payment.amount_auth, 40099.0)
    247270
    248271        IWorkflowState(self.student).setState('returning')
    249         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     272        error, payment = utils.setPaymentDetails('schoolfee',
     273            self.student, None, None)
    250274        self.assertEqual(payment.p_level, 200)
    251275        self.assertEqual(payment.p_session, 2005)
     
    255279
    256280        self.student.is_staff = True
    257         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     281        error, payment = utils.setPaymentDetails('schoolfee',
     282            self.student, None, None)
    258283        self.assertEqual(payment.p_level, 200)
    259284        self.assertEqual(payment.p_session, 2005)
     
    266291        self.student.nationality = u'DE'
    267292        self.certificate.school_fee_3 = 60000.0
    268         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     293        error, payment = utils.setPaymentDetails(
     294            'schoolfee', self.student, None, None)
    269295        self.assertEqual(payment.p_level, 100)
    270296        self.assertEqual(payment.p_session, 2004)
     
    277303        self.student.nationality = u'DE'
    278304        self.certificate.school_fee_4 = 20000.0
    279         error, payment = utils.setPaymentDetails('schoolfee',self.student)
     305        error, payment = utils.setPaymentDetails(
     306            'schoolfee', self.student, None, None)
    280307        self.assertEqual(payment.p_level, 200)
    281308        self.assertEqual(payment.p_session, 2005)
     
    284311        self.assertEqual(error, None)
    285312
    286         error, payment = utils.setPaymentDetails('clearance',self.student)
     313        error, payment = utils.setPaymentDetails('clearance',
     314            self.student, None, None)
    287315        self.assertEqual(payment.p_level, 100)
    288316        self.assertEqual(payment.p_session, 2004)
     
    291319        self.assertEqual(error, None)
    292320
    293         error, payment = utils.setPaymentDetails('gown',self.student)
     321        error, payment = utils.setPaymentDetails('gown',
     322            self.student, None, None)
    294323        self.assertEqual(payment.p_level, 100)
    295324        self.assertEqual(payment.p_session, 2004)
     
    298327        self.assertEqual(error, None)
    299328
    300         error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
     329        error, payment = utils.setPaymentDetails('hostel_maintenance',
     330            self.student, None, None)
    301331        self.assertEqual(payment.p_level, 100)
    302332        self.assertEqual(payment.p_session, 2004)
     
    305335        self.assertEqual(error, None)
    306336
    307         error, payment = utils.setPaymentDetails('bed_allocation',self.student)
     337        error, payment = utils.setPaymentDetails('bed_allocation',
     338            self.student, None, None)
    308339        self.assertEqual(payment.p_level, 100)
    309340        self.assertEqual(payment.p_session, 2004)
     
    312343        self.assertEqual(error, None)
    313344
    314         error, payment = utils.setPaymentDetails('transfer',self.student)
     345        error, payment = utils.setPaymentDetails('transfer',
     346            self.student, None, None)
    315347        self.assertEqual(payment.p_level, 100)
    316348        self.assertEqual(payment.p_session, 2004)
  • main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py

    r9006 r9152  
    4848        return new_session, new_level
    4949
    50     def setPaymentDetails(self, category, student):
     50    def setPaymentDetails(self, category, student,
     51            previous_session, previous_level):
    5152        """Create Payment object and set the payment data of a student for
    5253        the payment category specified.
     
    5758        amount = 0.0
    5859        error = u''
    59         p_session = student['studycourse'].current_session
    60         p_level = student['studycourse'].current_level
     60        if previous_session:
     61            p_session = previous_session
     62            p_level = previous_level
     63            p_current = False
     64        else:
     65            p_session = student['studycourse'].current_session
     66            p_level = student['studycourse'].current_level
     67            p_current = True
    6168        session = str(p_session)
    6269        try:
     
    8996            except (AttributeError, TypeError):
    9097                return _('Study course data are incomplete.'), None
    91             if student.state == CLEARED:
    92                 if student.is_foreigner:
    93                     amount = getattr(certificate, 'school_fee_3', 0.0)
     98            if previous_session:
     99                if student.current_session == student['studycourse'].entry_session:
     100                    if student.is_foreigner:
     101                        amount = getattr(certificate, 'school_fee_3', 0.0)
     102                    else:
     103                        amount = getattr(certificate, 'school_fee_1', 0.0)
    94104                else:
    95                     amount = getattr(certificate, 'school_fee_1', 0.0)
    96             elif student.state == RETURNING:
    97                 # In case of returning school fee payment the payment session
    98                 # and level contain the values of the session the student
    99                 # has paid for.
    100                 p_session, p_level = self.getReturningData(student)
    101                 if student.is_foreigner:
    102                     amount = getattr(certificate, 'school_fee_4', 0.0)
    103                 else:
    104                     amount = getattr(certificate, 'school_fee_2', 0.0)
    105                 try:
    106                     academic_session = grok.getSite()[
    107                         'configuration'][str(p_session)]
    108                 except KeyError:
    109                     return _(u'Session configuration object is not available.'), None
    110             elif student.is_postgrad and student.state == PAID:
    111                 # Returning postgraduate students also pay for the next session
    112                 # but their level always remains the same.
    113                 p_session += 1
    114                 if student.is_foreigner:
    115                     amount = getattr(certificate, 'school_fee_4', 0.0)
    116                 else:
    117                     amount = getattr(certificate, 'school_fee_2', 0.0)
    118                 try:
    119                     academic_session = grok.getSite()[
    120                         'configuration'][str(p_session)]
    121                 except KeyError:
    122                     return _(u'Session configuration object is not available.'), None
     105                    if student.is_foreigner:
     106                        amount = getattr(certificate, 'school_fee_4', 0.0)
     107                    else:
     108                        amount = getattr(certificate, 'school_fee_2', 0.0)
     109            else:
     110                if student.state == CLEARED:
     111                    if student.is_foreigner:
     112                        amount = getattr(certificate, 'school_fee_3', 0.0)
     113                    else:
     114                        amount = getattr(certificate, 'school_fee_1', 0.0)
     115                elif student.state == RETURNING:
     116                    # In case of returning school fee payment the payment session
     117                    # and level contain the values of the session the student
     118                    # has paid for.
     119                    p_session, p_level = self.getReturningData(student)
     120                    if student.is_foreigner:
     121                        amount = getattr(certificate, 'school_fee_4', 0.0)
     122                    else:
     123                        amount = getattr(certificate, 'school_fee_2', 0.0)
     124                    try:
     125                        academic_session = grok.getSite()[
     126                            'configuration'][str(p_session)]
     127                    except KeyError:
     128                        return _(u'Session configuration object is not available.'), None
     129                elif student.is_postgrad and student.state == PAID:
     130                    # Returning postgraduate students also pay for the next session
     131                    # but their level always remains the same.
     132                    p_session += 1
     133                    if student.is_foreigner:
     134                        amount = getattr(certificate, 'school_fee_4', 0.0)
     135                    else:
     136                        amount = getattr(certificate, 'school_fee_2', 0.0)
     137                    try:
     138                        academic_session = grok.getSite()[
     139                            'configuration'][str(p_session)]
     140                    except KeyError:
     141                        return _(u'Session configuration object is not available.'), None
    123142            # Give 50% school fee discount to staff members.
    124143            if student.is_staff:
    125144                amount /= 2
    126145        if amount in (0.0, None):
    127             return _(u'Amount could not be determined.'), None
     146            return _('Amount could not be determined.' +
     147                     ' Would you like to pay for a previous session?'), None
    128148        # Add session specific penalty fee.
    129149        if category == 'schoolfee' and student.is_postgrad:
     
    138158               ticket.p_item == p_item and \
    139159               ticket.p_session == p_session:
    140                   return _('This type of payment has already been made.'), None
     160                  return _('This type of payment has already been made.' +
     161                           ' Would you like to pay for a previous session?'), None
    141162        payment = createObject(u'waeup.StudentOnlinePayment')
    142163        timestamp = ("%d" % int(time()*10000))[1:]
     
    146167        payment.p_session = p_session
    147168        payment.p_level = p_level
     169        payment.p_current = p_current
    148170        payment.amount_auth = amount
    149171        return None, payment
Note: See TracChangeset for help on using the changeset viewer.