Ignore:
Timestamp:
30 Oct 2013, 19:43:48 (11 years ago)
Author:
Henrik Bettermann
Message:

New students must book and pay for accommodation first, before making school fee payments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py

    r10672 r10675  
    2020from time import time
    2121from zope.component import createObject, getUtility
     22from zope.catalog.interfaces import ICatalog
    2223from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
    2324from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
     
    2526from waeup.kofa.interfaces import CLEARED, RETURNING, IKofaUtils
    2627from waeup.kofa.fees import FeeTable
     28from waeup.kofa.hostels.hostel import NOT_OCCUPIED
    2729from waeup.kwarapoly.interfaces import MessageFactory as _
    2830
     
    124126        new_session = student['studycourse'].current_session + 1
    125127        return new_session, new_level
     128
     129    def _maintPaymentMade(self, student, session):
     130        if len(student['payments']):
     131            for ticket in student['payments'].values():
     132                if ticket.p_category == 'hostel_maintenance' and \
     133                    ticket.p_session == session and ticket.p_state == 'paid':
     134                        return True
     135        return False
     136
     137    def _bedAvailable(self, student):
     138        acc_details  = self.getAccommodationDetails(student)
     139        cat = getUtility(ICatalog, name='beds_catalog')
     140        entries = cat.searchResults(
     141            owner=(student.student_id,student.student_id))
     142        if len(entries):
     143            # Bed has already been booked.
     144            return True
     145        entries = cat.searchResults(
     146            bed_type=(acc_details['bt'],acc_details['bt']))
     147        available_beds = [
     148            entry for entry in entries if entry.owner == NOT_OCCUPIED]
     149        if available_beds:
     150            # Bed has not yet been booked but beds are available.
     151            return True
     152        return False
    126153
    127154    def setPaymentDetails(self, category, student,
     
    170197                if academic_session == None:
    171198                    return _(u'Session configuration object is not available.'), None
     199            if student.state == CLEARED:
     200                # Fresh students must have booked and paid for accommodation.
     201                if self._bedAvailable(student):
     202                    if not self._maintPaymentMade(student, p_session):
     203                        return _('Book and pay for accommodation first '
     204                                 'before making school fee payments.'), None
    172205            if student.state in (RETURNING, CLEARED):
    173206                if p_level in PAYMENT_LEVELS:
Note: See TracChangeset for help on using the changeset viewer.