Changeset 14860 for main


Ignore:
Timestamp:
5 Oct 2017, 07:16:19 (7 years ago)
Author:
Henrik Bettermann
Message:

Start customizing setPaymentDetails.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.dspg/trunk/src/kofacustom/dspg/students/utils.py

    r14720 r14860  
    3030    # prefix
    3131    STUDENT_ID_PREFIX = u'P'
     32
     33    def setPaymentDetails(self, category, student,
     34            previous_session, previous_level):
     35        """Create a payment ticket and set the payment data of a
     36        student for the payment category specified.
     37        """
     38        p_item = u''
     39        amount = 0.0
     40        if previous_session:
     41            if previous_session < student['studycourse'].entry_session:
     42                return _('The previous session must not fall below '
     43                         'your entry session.'), None
     44            if category == 'schoolfee':
     45                # School fee is always paid for the following session
     46                if previous_session > student['studycourse'].current_session:
     47                    return _('This is not a previous session.'), None
     48            else:
     49                if previous_session > student['studycourse'].current_session - 1:
     50                    return _('This is not a previous session.'), None
     51            p_session = previous_session
     52            p_level = previous_level
     53            p_current = False
     54        else:
     55            p_session = student['studycourse'].current_session
     56            p_level = student['studycourse'].current_level
     57            p_current = True
     58        academic_session = self._getSessionConfiguration(p_session)
     59        if academic_session == None:
     60            return _(u'Session configuration object is not available.'), None
     61        # Determine fee.
     62        if category == 'schoolfee':
     63            try:
     64                certificate = student['studycourse'].certificate
     65                p_item = certificate.code
     66            except (AttributeError, TypeError):
     67                return _('Study course data are incomplete.'), None
     68            if previous_session:
     69                # Students can pay for previous sessions in all
     70                # workflow states.  Fresh students are excluded by the
     71                # update method of the PreviousPaymentAddFormPage.
     72                if previous_level == 100:
     73                    amount = getattr(certificate, 'school_fee_1', 0.0)
     74                else:
     75                    amount = getattr(certificate, 'school_fee_2', 0.0)
     76            else:
     77                if student.state == CLEARED:
     78                    amount = getattr(certificate, 'school_fee_1', 0.0)
     79                elif student.state == RETURNING:
     80                    # In case of returning school fee payment the
     81                    # payment session and level contain the values of
     82                    # the session the student has paid for. Payment
     83                    # session is always next session.
     84                    p_session, p_level = self.getReturningData(student)
     85                    academic_session = self._getSessionConfiguration(p_session)
     86                    if academic_session == None:
     87                        return _(
     88                            u'Session configuration object is not available.'
     89                            ), None
     90                    amount = getattr(certificate, 'school_fee_2', 0.0)
     91                elif student.is_postgrad and student.state == PAID:
     92                    # Returning postgraduate students also pay for the
     93                    # next session but their level always remains the
     94                    # same.
     95                    p_session += 1
     96                    academic_session = self._getSessionConfiguration(p_session)
     97                    if academic_session == None:
     98                        return _(
     99                            u'Session configuration object is not available.'
     100                            ), None
     101                    amount = getattr(certificate, 'school_fee_2', 0.0)
     102        elif category == 'clearance':
     103            try:
     104                p_item = student['studycourse'].certificate.code
     105            except (AttributeError, TypeError):
     106                return _('Study course data are incomplete.'), None
     107            amount = academic_session.clearance_fee
     108        elif category == 'bed_allocation':
     109            p_item = self.getAccommodationDetails(student)['bt']
     110            amount = academic_session.booking_fee
     111        elif category == 'hostel_maintenance':
     112            amount = 0.0
     113            bedticket = student['accommodation'].get(
     114                str(student.current_session), None)
     115            if bedticket is not None and bedticket.bed is not None:
     116                p_item = bedticket.bed_coordinates
     117                if bedticket.bed.__parent__.maint_fee > 0:
     118                    amount = bedticket.bed.__parent__.maint_fee
     119                else:
     120                    # fallback
     121                    amount = academic_session.maint_fee
     122            else:
     123                return _(u'No bed allocated.'), None
     124        elif category == 'transcript':
     125            amount = academic_session.transcript_fee
     126        elif category == 'transfer':
     127            amount = academic_session.transfer_fee
     128        elif category == 'late_registration':
     129            amount = academic_session.late_registration_fee
     130        if amount in (0.0, None):
     131            return _('Amount could not be determined.'), None
     132        if self.samePaymentMade(student, category, p_item, p_session):
     133            return _('This type of payment has already been made.'), None
     134        if self._isPaymentDisabled(p_session, category, student):
     135            return _('This category of payments has been disabled.'), None
     136        payment = createObject(u'waeup.StudentOnlinePayment')
     137        timestamp = ("%d" % int(time()*10000))[1:]
     138        payment.p_id = "p%s" % timestamp
     139        payment.p_category = category
     140        payment.p_item = p_item
     141        payment.p_session = p_session
     142        payment.p_level = p_level
     143        payment.p_current = p_current
     144        payment.amount_auth = amount
     145        return None, payment
Note: See TracChangeset for help on using the changeset viewer.