Changeset 8595


Ignore:
Timestamp:
2 Jun 2012, 06:44:23 (12 years ago)
Author:
Henrik Bettermann
Message:

Move logic for payment ticket creation to setPaymentDetails in StudentsUtils?.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r8558 r8595  
    2121import grok
    2222from urllib import urlencode
    23 from time import time
    2423from datetime import datetime
    2524from copy import deepcopy
     
    10491048    label = _('Add online payment')
    10501049    pnav = 4
    1051     factory = u'waeup.StudentOnlinePayment'
    1052 
    1053     def _fillCustomFields(self, payment, pay_details):
    1054         """No custom fields in the base package
    1055         """
    1056         return payment
    10571050
    10581051    @action(_('Create ticket'), style='primary')
     
    10691062                return
    10701063        students_utils = getUtility(IStudentsUtils)
    1071         try:
    1072             pay_details  = students_utils.getPaymentDetails(
    1073                 p_category,student)
    1074         except (AttributeError, TypeError):
    1075             self.flash(
    1076                 _('Study course data are incomplete.'))
     1064        error, payment = students_utils.setPaymentDetails(p_category, student)
     1065        if error is not None:
     1066            self.flash(error)
    10771067            self.redirect(self.url(self.context))
    10781068            return
    1079         if pay_details['error']:
    1080             self.flash(pay_details['error'])
    1081             self.redirect(self.url(self.context))
    1082             return
    1083         p_item = pay_details['p_item']
    1084         p_session = pay_details['p_session']
    1085         for key in self.context.keys():
    1086             ticket = self.context[key]
    1087             if ticket.p_state == 'paid' and\
    1088                ticket.p_category == p_category and \
    1089                ticket.p_item == p_item and \
    1090                ticket.p_session == p_session:
    1091                   self.flash(
    1092                       _('This type of payment has already been made.'))
    1093                   self.redirect(self.url(self.context))
    1094                   return
    1095         payment = createObject(self.factory)
    1096         self.applyData(payment, **data)
    1097         timestamp = "%d" % int(time()*1000)
    1098         payment.p_id = "p%s" % timestamp
    1099         payment.p_item = p_item
    1100         payment.p_session = p_session
    1101         payment.p_level = pay_details['p_level']
    1102         payment.amount_auth = pay_details['amount']
    1103         payment = self._fillCustomFields(payment, pay_details)
    11041069        self.context[payment.p_id] = payment
    11051070        self.flash(_('Payment ticket created.'))
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r8453 r8595  
    6464        """
    6565
    66     def getPaymentDetails(category, student):
    67         """Get the payment dates of a student for the payment category
    68         specified.
     66    def setPaymentDetails(category, student):
     67        """Create Payment object and set the payment data of a student for
     68        the payment category specified.
    6969
    7070        """
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r8524 r8595  
    2020import grok
    2121from random import SystemRandom as r
     22from time import time
    2223from datetime import datetime
    2324from zope.i18n import translate
    24 from zope.component import getUtility
     25from zope.component import getUtility, createObject
    2526from reportlab.pdfgen import canvas
    2627from reportlab.lib import colors
     
    252253        return
    253254
    254     def getPaymentDetails(self, category, student):
    255         """Get the payment data of a student for the payment category
    256         specified.
    257         """
     255    def setPaymentDetails(self, category, student):
     256        """Create Payment object and set the payment data of a student for
     257        the payment category specified.
     258
     259        """
     260        factory = u'waeup.StudentOnlinePayment'
    258261        details = {}
    259         details['p_item'] = u''
    260         details['amount'] = 0.0
    261         details['error'] = u''
    262         details['p_session'] = student['studycourse'].current_session
    263         details['p_level'] = student['studycourse'].current_level
    264         session = str(details['p_session'])
     262        p_item = u''
     263        amount = 0.0
     264        error = u''
     265        p_session = student['studycourse'].current_session
     266        p_level = student['studycourse'].current_level
     267        session = str(p_session)
    265268        try:
    266269            academic_session = grok.getSite()['configuration'][session]
    267270        except KeyError:
    268             details['error'] = _(u'Session configuration object is not available.')
    269             return details
     271            return _(u'Session configuration object is not available.'), None
    270272        if category == 'schoolfee':
    271             details['amount'] = getattr(
    272                 student['studycourse'].certificate,'school_fee_1')
    273             details['p_item'] = student['studycourse'].certificate.code
     273            try:
     274                amount = getattr(
     275                    student['studycourse'].certificate,'school_fee_1')
     276                p_item = student['studycourse'].certificate.code
     277            except (AttributeError, TypeError):
     278                return _('Study course data are incomplete.'), None
    274279            if student.state == RETURNING:
    275280                # In case of returning school fee payment the payment session
    276281                # and level contain the values of the session the student
    277282                # has paid for.
    278                 details['p_session'], details[
    279                     'p_level'] = self.getReturningData(student)
     283                p_session, p_level = self.getReturningData(student)
    280284            elif student.is_postgrad and student.state == PAID:
    281285                # Returning postgraduate students also pay for the next session
    282286                # but their level always remains the same.
    283                 details['p_session'] += 1
    284                 details['amount'] = getattr(
     287                p_session += 1
     288                amount = getattr(
    285289                    student['studycourse'].certificate,'school_fee_2')
    286290        elif category == 'clearance':
    287             details['p_item'] = student['studycourse'].certificate.code
    288             details['amount'] = academic_session.clearance_fee
     291            p_item = student['studycourse'].certificate.code
     292            amount = academic_session.clearance_fee
    289293        elif category == 'bed_allocation':
    290             details['p_item'] = self.getAccommodationDetails(student)['bt']
    291             details['amount'] = academic_session.booking_fee
    292         if details['amount'] in (0.0, None):
    293             details['error'] = _(u'Amount could not be determined.')
    294         return details
     294            p_item = self.getAccommodationDetails(student)['bt']
     295            amount = academic_session.booking_fee
     296        if amount in (0.0, None):
     297            return _(u'Amount could not be determined.'), None
     298        for key in student['payments'].keys():
     299            ticket = student['payments'][key]
     300            if ticket.p_state == 'paid' and\
     301               ticket.p_category == category and \
     302               ticket.p_item == p_item and \
     303               ticket.p_session == p_session:
     304                  return _('This type of payment has already been made.'), None
     305        payment = createObject(factory)
     306        #self.applyData(payment, **data)
     307        timestamp = "%d" % int(time()*1000)
     308        payment.p_id = "p%s" % timestamp
     309        payment.p_category = category
     310        payment.p_item = p_item
     311        payment.p_session = p_session
     312        payment.p_level = p_level
     313        payment.amount_auth = amount
     314        return None, payment
    295315
    296316    def getAccommodationDetails(self, student):
Note: See TracChangeset for help on using the changeset viewer.