Ignore:
Timestamp:
2 Jun 2012, 08:11:24 (12 years ago)
Author:
Henrik Bettermann
Message:

Implement setPaymentDetails utility method.

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  
    178178    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
    179179        'p_category')
    180     factory = u'waeup.CustomStudentOnlinePayment'
    181 
    182     def _fillCustomFields(self, payment, pay_details):
    183         # No custom fields at the moment
    184         return payment
    185180
    186181class CustomOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage):
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r8473 r8598  
    3030from waeup.uniben.students.batching import CustomStudentProcessor
    3131from waeup.uniben.testing import FunctionalLayer
    32 from waeup.uniben.students.utils import get_school_fee
    3332from waeup.uniben.students.interfaces import (
    3433    ICustomStudentStudyCourse, ICustomStudent,
     
    303302        return
    304303
    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):
    314305        self.app['configuration']['2004'].gown_fee = 150.0
    315306        self.app['configuration']['2004'].transfer_fee = 90.0
     
    317308        self.app['configuration']['2004'].maint_fee = 180.0
    318309        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)
    343365        return
  • main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py

    r8473 r8598  
    1717##
    1818import grok
     19from time import time
     20from zope.component import createObject
    1921from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
    2022from waeup.kofa.students.utils import StudentsUtils
     
    2325from waeup.uniben.interfaces import MessageFactory as _
    2426
    25 def get_school_fee(student):
    26     state = student.state
    27     fee = None
    28     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 fee
    34     return 0.0
    35 
    3627class CustomStudentsUtils(StudentsUtils):
    3728    """A collection of customized methods.
     
    3930    """
    4031    grok.implements(IStudentsUtils)
     32
     33    paymentfactory = u'waeup.CustomStudentOnlinePayment'
    4134
    4235    def getReturningData(self, student):
     
    5952        return new_session, new_level
    6053
    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        """
    6259        details = {}
    63         details['p_item'] = u''
    64         details['amount'] = 0.0
    65         details['error'] = u''
    66         details['p_session'] = student['studycourse'].current_session
    67         session = str(details['p_session'])
    68         details['p_level'] = student['studycourse'].current_level
     60        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)
    6966        try:
    7067            academic_session = grok.getSite()['configuration'][session]
    7168        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
    7470        if category == 'transfer':
    75             details['amount'] = academic_session.transfer_fee
     71            amount = academic_session.transfer_fee
    7672        elif category == 'gown':
    77             details['amount'] = academic_session.gown_fee
     73            amount = academic_session.gown_fee
    7874        elif category == 'bed_allocation':
    79             details['amount'] = academic_session.booking_fee
     75            amount = academic_session.booking_fee
    8076        elif category == 'hostel_maintenance':
    81             details['amount'] = academic_session.maint_fee
     77            amount = academic_session.maint_fee
    8278        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',
    8584                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
    86                 details['amount'] = 17250.0
     85                amount = 17250.0
    8786            else:
    88                 details['amount'] = 34250.0
     87                amount = 34250.0
    8988        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:
    9497                # In case of returning school fee payment the payment session
    9598                # and level contain the values of the session the student
    9699                # 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:
    99103                # Returning postgraduate students also pay for the next session
    100104                # 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
    107125
    108126    VERDICTS_DICT = {
Note: See TracChangeset for help on using the changeset viewer.