Changeset 13583 for main


Ignore:
Timestamp:
10 Jan 2016, 22:18:06 (9 years ago)
Author:
Henrik Bettermann
Message:

Implement first draft of bursary clearance slip.

Location:
main/waeup.uniben/trunk/src/waeup/uniben/students
Files:
5 edited

Legend:

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

    r13335 r13583  
    343343        tabledata = []
    344344        tableheader = []
    345         contenttitle = []
    346345        for i in range(1,7):
    347346            tabledata.append(sorted(
     
    409408        tabledata = []
    410409        tableheader = []
    411         contenttitle = []
    412410        for i in range(1,7):
    413411            tabledata.append(sorted(
     
    428426            )
    429427
     428class UnibenExportPDFBursaryClearancePage(UtilityView, grok.View):
     429    """Deliver a PDF bursary clearance slip.
     430    """
     431    grok.context(ICustomStudent)
     432    grok.name('bursary_clearance_slip.pdf')
     433    grok.require('waeup.viewStudent')
     434    prefix = 'form'
     435
     436    omit_fields = () # ('date_of_birth', 'current_level')
     437
     438    form_fields = None
     439
     440    @property
     441    def label(self):
     442        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     443        return translate(_('Bursary Clearance Slip of'),
     444            'waeup.kofa', target_language=portal_language) \
     445            + ' %s' % self.context.display_fullname
     446
     447    def _sigsInFooter(self):
     448        return (_('Date, Student Signature'),
     449                _('Date, Bursary Signature'),
     450                )
     451
     452    @property
     453    def tabletitle(self):
     454        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     455        tabletitle = []
     456        tabletitle.append(translate(_('Successful Payments'), 'waeup.kofa',
     457            target_language=portal_language))
     458        return tabletitle
     459
     460    def render(self):
     461        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     462        P_ID = translate(_('Payment Id'), 'waeup.kofa', target_language=portal_language)
     463        #CD = translate(_('Creation Date'), 'waeup.kofa', target_language=portal_language)
     464        PD = translate(_('Payment Date'), 'waeup.kofa', target_language=portal_language)
     465        CAT = translate(_('Payment Category'), 'waeup.kofa', target_language=portal_language)
     466        ITEM = translate(_('Payment Item'), 'waeup.kofa', target_language=portal_language)
     467        AMT = translate(_('Amount (Naira)'), 'waeup.kofa', target_language=portal_language)
     468        SSS = translate(_('Payment Session'), 'waeup.kofa', target_language=portal_language)
     469        studentview = StudentBasePDFFormPage(self.context.student,
     470            self.request, self.omit_fields)
     471        students_utils = getUtility(IStudentsUtils)
     472
     473        tabledata = []
     474        tableheader = []
     475        tabledata.append(sorted(
     476            [value for value in self.context['payments'].values()
     477             if value.p_state == 'paid'], key=lambda value: value.p_id))
     478        tableheader.append([(P_ID,'p_id', 3),
     479                         #(CD,'creation_date', 3),
     480                         (PD,'formatted_p_date', 3),
     481                         (CAT,'category', 3),
     482                         (ITEM, 'p_item', 3),
     483                         (AMT, 'amount_auth', 2),
     484                         (SSS, 'p_session', 2),
     485                         ])
     486        return students_utils.renderPDF(
     487            self, 'bursary_clearance_slip.pdf',
     488            self.context.student, studentview,
     489            tableheader=tableheader,
     490            tabledata=tabledata,
     491            signatures=None,
     492            sigs_in_footer=self._sigsInFooter(),
     493            omit_fields=self.omit_fields
     494            )
     495
    430496class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
    431497    """ Page to display course tickets
  • main/waeup.uniben/trunk/src/waeup/uniben/students/export.py

    r12879 r13583  
    7171        sorted(iface_names(
    7272            ICustomStudentOnlinePayment, exclude_attribs=False,
    73             omit=['display_item']))) + (
     73            omit=['display_item','formatted_p_date']))) + (
    7474            'student_id','state','current_session')
    7575
  • main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py

    r13085 r13583  
    1818
    1919from zope import schema
     20from zope.interface import Attribute
    2021from waeup.kofa.interfaces import validate_email
    2122from kofacustom.nigeria.students.interfaces import (
     
    8182    """
    8283
     84    formatted_p_date = Attribute("Formatted pyment date")
     85
    8386    p_current = schema.Bool(
    8487        title = _(u'Current Session Payment'),
  • main/waeup.uniben/trunk/src/waeup/uniben/students/payments.py

    r9993 r13583  
    2020"""
    2121import grok
     22from datetime import datetime
     23from zope.component import getUtility
    2224from zope.component.interfaces import IFactory
    2325from zope.interface import implementedBy
     26from waeup.kofa.interfaces import IKofaUtils
    2427from waeup.kofa.students.interfaces import IStudentNavigation
    2528from waeup.kofa.students.payments import (
    2629    StudentOnlinePayment, StudentOnlinePaymentFactory)
    27 from waeup.kofa.utils.helpers import attrs_to_fields
     30from waeup.kofa.utils.helpers import attrs_to_fields, to_timezone
    2831from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
    2932
     
    4750        return self.__parent__.__parent__
    4851
     52    @property
     53    def formatted_p_date(self):
     54        if isinstance(self.payment_date, datetime):
     55            tz = getUtility(IKofaUtils).tzinfo
     56            try:
     57                timestamp = to_timezone(
     58                    self.payment_date, tz).strftime("%Y-%m-%d %H:%M:%S")
     59            except ValueError:
     60                return None
     61            return timestamp
     62        else:
     63            return None
     64
    4965CustomStudentOnlinePayment = attrs_to_fields(
    5066    CustomStudentOnlinePayment, omit=['display_item'])
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r13460 r13583  
    2020import tempfile
    2121import pytz
     22from time import time
    2223from datetime import datetime, timedelta, date
    2324from StringIO import StringIO
     
    10431044        self.assertEqual(self.student['payments'][value].amount_auth, 987.0)
    10441045        return
     1046
     1047    def test_bursary_pdf_slip(self):
     1048        payment1 = createObject(u'waeup.StudentOnlinePayment')
     1049        timestamp = ("%d" % int(time()*10000))[1:]
     1050        payment1.p_id = "p%s" % timestamp
     1051        payment1.p_category = 'schoolfee'
     1052        payment1.p_item = u'My School Fee'
     1053        payment1.p_session = 2015
     1054        payment1.p_level = 100
     1055        payment1.p_current = True
     1056        payment1.amount_auth = 23456.9
     1057        payment1.approve()
     1058        payment2 = createObject(u'waeup.StudentOnlinePayment')
     1059        timestamp = ("%d" % int(time()*10000))[1:]
     1060        payment2.p_id = "p%s" % timestamp
     1061        payment2.p_category = 'clearance'
     1062        payment2.p_item = u'My Clearance Fee'
     1063        payment2.p_session = 2015
     1064        payment2.p_level = 100
     1065        payment2.p_current = True
     1066        payment2.amount_auth = 5678.6
     1067        payment2.approve()
     1068        self.student['payments'][payment1.p_id] = payment1
     1069        self.student['payments'][payment2.p_id] = payment2
     1070        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1071        self.browser.open(self.student_path + '/bursary_clearance_slip.pdf')
     1072        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1073        self.assertEqual(self.browser.headers['Content-Type'],
     1074                         'application/pdf')
     1075        path = os.path.join(samples_dir(), 'bursary_clearance_slip.pdf')
     1076        open(path, 'wb').write(self.browser.contents)
     1077        print "Sample PDF bursary_clearance_slip.pdf written to %s" % path
     1078        return
Note: See TracChangeset for help on using the changeset viewer.