Ignore:
Timestamp:
11 Jan 2013, 17:19:38 (12 years ago)
Author:
Henrik Bettermann
Message:

Implement BalancePaymentAddFormPage? and adjust interfaces (tests and further components will follow).

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/payments/interfaces.py

    r9733 r9864  
    3030
    3131class PaymentCategorySource(ContextualDictSourceFactoryBase):
    32     """A application category source delivers all special handling categories
    33     provided for accommodation booking.
     32    """A payment category source delivers all categories of payments.
     33
    3434    """
    3535    #: name of dict to deliver from kofa utils.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r9862 r9864  
    7171    IStudentAccommodation, IStudentStudyLevel,
    7272    ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer,
    73     IStudentOnlinePayment, IStudentPreviousPayment,
     73    IStudentOnlinePayment, IStudentPreviousPayment, IStudentBalancePayment,
    7474    IBedTicket, IStudentsUtils, IStudentRequestPW
    7575    )
     
    14791479    grok.context(IStudentPaymentsContainer)
    14801480    grok.name('addpp')
    1481     grok.template('previouspaymentaddform')
    14821481    grok.require('waeup.payStudent')
    1483     form_fields = grok.AutoFields(IStudentPreviousPayment).select(
    1484         'p_category', 'p_session', 'p_level')
     1482    form_fields = grok.AutoFields(IStudentPreviousPayment)
    14851483    label = _('Add previous session online payment')
    14861484    pnav = 4
     
    15081506        error, payment = students_utils.setPaymentDetails(
    15091507            p_category, student, previous_session, previous_level)
     1508        if error is not None:
     1509            self.flash(error)
     1510            return
     1511        self.context[payment.p_id] = payment
     1512        self.flash(_('Payment ticket created.'))
     1513        self.redirect(self.url(self.context))
     1514        return
     1515
     1516    @action(_('Cancel'), validator=NullValidator)
     1517    def cancel(self, **data):
     1518        self.redirect(self.url(self.context))
     1519
     1520class BalancePaymentAddFormPage(KofaAddFormPage):
     1521    """ Page to add an online payment ticket for balance sessions
     1522    """
     1523    grok.context(IStudentPaymentsContainer)
     1524    grok.name('addbp')
     1525    grok.require('waeup.payStudent')
     1526    form_fields = grok.AutoFields(IStudentBalancePayment)
     1527    label = _('Add balance')
     1528    pnav = 4
     1529
     1530    @property
     1531    def selectable_categories(self):
     1532        categories = getUtility(
     1533            IKofaUtils).SELECTABLE_BALANCE_PAYMENT_CATEGORIES
     1534        return sorted(categories.items())
     1535
     1536    @action(_('Create ticket'), style='primary')
     1537    def createTicket(self, **data):
     1538        balance_item = data.get('balance_item', None)
     1539        balance_session = data.get('balance_session', None)
     1540        balance_level = data.get('balance_level', None)
     1541        balance_amount = data.get('balance_amount', None)
     1542        student = self.context.__parent__
     1543        students_utils = getUtility(IStudentsUtils)
     1544        error, payment = students_utils.setBalanceDetails(
     1545            balance_item, student, balance_session,
     1546            balance_level, balance_amount)
    15101547        if error is not None:
    15111548            self.flash(error)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r9801 r9864  
    3333    IPaymentsContainer, IOnlinePayment)
    3434from waeup.kofa.university.vocabularies import (
    35     CourseSource, StudyModeSource, CertificateSource, SemesterSource)
     35    CourseSource, StudyModeSource, CertificateSource, SemesterSource,
     36    ContextualDictSourceFactoryBase)
     37
     38class PreviousPaymentCategorySource(ContextualDictSourceFactoryBase):
     39    """A source that delivers all selectable categories of previous session
     40    payments.
     41    """
     42    #: name of dict to deliver from kofa utils.
     43    DICT_NAME = 'PREVIOUS_PAYMENT_CATEGORIES'
     44
     45class BalancePaymentItemSource(ContextualDictSourceFactoryBase):
     46    """A source that delivers all selectable items of balance payments.
     47    """
     48    #: name of dict to deliver from kofa utils.
     49    DICT_NAME = 'BALANCE_PAYMENT_ITEMS'
    3650
    3751# VerdictSource can't be placed into the vocabularies module because it
     
    727741    'p_session'].order
    728742
    729 class IStudentPreviousPayment(IOnlinePayment):
     743class IStudentPreviousPayment(IKofaObject):
    730744    """An interface for adding previous session payments.
    731745
    732746    """
     747
     748    p_category = schema.Choice(
     749        title = _(u'Payment Category'),
     750        default = u'schoolfee',
     751        source = PreviousPaymentCategorySource(),
     752        required = True,
     753        )
    733754
    734755    p_session = schema.Choice(
     
    744765        )
    745766
     767class IStudentBalancePayment(IKofaObject):
     768    """An interface for adding balances.
     769
     770    """
     771
     772    balance_item = schema.Choice(
     773        title = _(u'Payment Category'),
     774        default = u'schoolfee',
     775        required = True,
     776        source = BalancePaymentItemSource(),
     777        )
     778
     779    balance_session = schema.Choice(
     780        title = _(u'Payment Session'),
     781        source = academic_sessions_vocab,
     782        required = True,
     783        )
     784
     785    balance_level = schema.Choice(
     786        title = _(u'Payment Level'),
     787        source = StudyLevelSource(),
     788        required = True,
     789        )
     790
     791    balance_amount = schema.Float(
     792        title = _(u'Balance Amount'),
     793        default = 0.0,
     794        required = True,
     795        readonly = False,
     796        description = _(
     797            u'Balance in Naira '),
     798        )
     799
    746800class ICSVStudentExporter(ICSVExporter):
    747801    """A regular ICSVExporter that additionally supports exporting
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r9830 r9864  
    421421        return None, payment
    422422
     423    def setBalanceDetails(self, balance_item, student,
     424            balance_session, balance_level, balance_amount):
     425        """Create Payment object and set the payment data of a student for.
     426
     427        """
     428        p_item = getUtility(IKofaUtils).BALANCE_PAYMENT_ITEMS[balance_item]
     429        p_item = unicode(p_item)
     430        p_session = balance_session
     431        p_level = balance_level
     432        p_current = False
     433        amount = balance_amount
     434        academic_session = self._getSessionConfiguration(p_session)
     435        if academic_session == None:
     436            return _(u'Session configuration object is not available.'), None
     437        if amount in (0.0, None):
     438            return _('Amount could not be determined.'), None
     439        for key in student['payments'].keys():
     440            ticket = student['payments'][key]
     441            if ticket.p_state == 'paid' and\
     442               ticket.p_category == 'balance' and \
     443               ticket.p_item == p_item and \
     444               ticket.p_session == p_session:
     445                  return _('This type of payment has already been made.'), None
     446        payment = createObject(u'waeup.StudentOnlinePayment')
     447        timestamp = ("%d" % int(time()*10000))[1:]
     448        payment.p_id = "p%s" % timestamp
     449        payment.p_category = 'balance'
     450        payment.p_item = p_item
     451        payment.p_session = p_session
     452        payment.p_level = p_level
     453        payment.p_current = p_current
     454        payment.amount_auth = amount
     455        return None, payment
     456
    423457    def getAccommodationDetails(self, student):
    424458        """Determine the accommodation data of a student.
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py

    r9862 r9864  
    163163    SELECTABLE_PAYMENT_CATEGORIES = PAYMENT_CATEGORIES
    164164
    165     SELECTABLE_PREVIOUS_PAYMENT_CATEGORIES = SELECTABLE_PAYMENT_CATEGORIES
     165    PREVIOUS_PAYMENT_CATEGORIES = SELECTABLE_PAYMENT_CATEGORIES
     166
     167    BALANCE_PAYMENT_ITEMS = SELECTABLE_PAYMENT_CATEGORIES
     168    BALANCE_PAYMENT_ITEMS['balance'] = 'Balance'
    166169
    167170    MODE_GROUPS = {
Note: See TracChangeset for help on using the changeset viewer.