Ignore:
Timestamp:
16 Jan 2016, 18:26:12 (9 years ago)
Author:
Henrik Bettermann
Message:

Implement bursary clearance slip.

Location:
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/browser.py

    r13620 r13623  
    2222from datetime import datetime
    2323from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
    24 from waeup.kofa.interfaces import IExtFileStore, IObjectHistory
     24from waeup.kofa.interfaces import IExtFileStore, IObjectHistory, IKofaUtils
    2525from waeup.kofa.browser.layout import action, UtilityView
    26 from waeup.kofa.utils.helpers import get_current_principal
     26from waeup.kofa.utils.helpers import get_current_principal, to_timezone
    2727from waeup.kofa.students.browser import (
    2828    StudentPersonalDisplayFormPage, StudentPersonalManageFormPage,
     
    3131    ExportPDFClearanceSlip, StudentBaseManageFormPage,
    3232    StudentBaseDisplayFormPage,
     33    StudentBasePDFFormPage,
    3334    StudentBaseEditFormPage, StudentPersonalEditFormPage,
    3435    OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage,
     
    314315    def render(self):
    315316        return
     317
     318cleared_note = """
     319<br /><br /><br />
     320<strong>Financially cleared on %s by %s.</strong>
     321
     322"""
     323
     324not_cleared_note = """
     325<br /><br /><br />
     326<strong>Not yet financially cleared.</strong>
     327
     328"""
     329
     330class NigeriaExportPDFBursaryClearancePage(UtilityView, grok.View):
     331    """Deliver a PDF bursary clearance slip.
     332    """
     333    grok.context(INigeriaStudent)
     334    grok.name('bursary_clearance_slip.pdf')
     335    grok.require('waeup.viewStudent')
     336    prefix = 'form'
     337
     338    omit_fields = (
     339        'suspended', 'phone',
     340        'adm_code', 'suspended_comment',
     341        'date_of_birth', 'current_level')
     342
     343    form_fields = None
     344
     345    @property
     346    def label(self):
     347        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     348        return translate(_('Bursary Clearance Slip of'),
     349            'waeup.kofa', target_language=portal_language) \
     350            + ' %s' % self.context.display_fullname
     351
     352    def _sigsInFooter(self):
     353
     354        isStudent = getattr(
     355            self.request.principal, 'user_type', None) == 'student'
     356        if isStudent:
     357            return ()
     358        return (_('Date, Student Signature'),
     359                _('Date, Bursary Signature'),
     360                )
     361
     362    @property
     363    def note(self):
     364        if self.context.financially_cleared_by:
     365            tz = getUtility(IKofaUtils).tzinfo
     366            try:
     367                timestamp = to_timezone(
     368                    self.context.financial_clearance_date, tz).strftime(
     369                        "%Y-%m-%d %H:%M:%S")
     370            except ValueError:
     371                return not_cleared_note
     372            return cleared_note % (
     373                timestamp, self.context.financially_cleared_by)
     374        return not_cleared_note
     375
     376    @property
     377    def tabletitle(self):
     378        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     379        tabletitle = []
     380        tabletitle.append(translate(_('Successful Payments'), 'waeup.kofa',
     381            target_language=portal_language))
     382        return tabletitle
     383
     384    def render(self):
     385        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     386        P_ID = translate(_('Payment Id'), 'waeup.kofa', target_language=portal_language)
     387        #CD = translate(_('Creation Date'), 'waeup.kofa', target_language=portal_language)
     388        PD = translate(_('Payment Date'), 'waeup.kofa', target_language=portal_language)
     389        CAT = translate(_('Payment Category'), 'waeup.kofa', target_language=portal_language)
     390        ITEM = translate(_('Payment Item'), 'waeup.kofa', target_language=portal_language)
     391        AMT = translate(_('Amount (Naira)'), 'waeup.kofa', target_language=portal_language)
     392        SSS = translate(_('Payment Session'), 'waeup.kofa', target_language=portal_language)
     393        studentview = StudentBasePDFFormPage(self.context.student,
     394            self.request, self.omit_fields)
     395        students_utils = getUtility(IStudentsUtils)
     396
     397        tabledata = []
     398        tableheader = []
     399        tabledata.append(sorted(
     400            [value for value in self.context['payments'].values()
     401             if value.p_state == 'paid'], key=lambda value: value.p_id))
     402        tableheader.append([(P_ID,'p_id', 3),
     403                         #(CD,'creation_date', 3),
     404                         (PD,'formatted_p_date', 3),
     405                         (CAT,'category', 3),
     406                         (ITEM, 'p_item', 3),
     407                         (AMT, 'amount_auth', 2),
     408                         (SSS, 'p_session', 2),
     409                         ])
     410        return students_utils.renderPDF(
     411            self, 'bursary_clearance_slip.pdf',
     412            self.context.student, studentview,
     413            tableheader=tableheader,
     414            tabledata=tabledata,
     415            signatures=None,
     416            sigs_in_footer=self._sigsInFooter(),
     417            omit_fields=self.omit_fields,
     418            note=self.note
     419            )
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/export.py

    r12875 r13623  
    8585        sorted(iface_names(
    8686            INigeriaStudentOnlinePayment, exclude_attribs=False,
    87             omit=['display_item']))) + (
     87            omit=['display_item','formatted_p_date']))) + (
    8888            'student_id','state','current_session')
    8989
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/interfaces.py

    r13620 r13623  
    519519    """
    520520
     521    formatted_p_date = Attribute("Formatted pyment date")
     522
    521523    p_current = schema.Bool(
    522524        title = _(u'Current Session Payment'),
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/payments.py

    r11639 r13623  
    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 kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment
    2932
     
    4750        return self.__parent__.__parent__
    4851
     52
     53    @property
     54    def formatted_p_date(self):
     55        if isinstance(self.payment_date, datetime):
     56            tz = getUtility(IKofaUtils).tzinfo
     57            try:
     58                timestamp = to_timezone(
     59                    self.payment_date, tz).strftime("%Y-%m-%d %H:%M:%S")
     60            except ValueError:
     61                return None
     62            return timestamp
     63        else:
     64            return None
     65
    4966NigeriaStudentOnlinePayment = attrs_to_fields(NigeriaStudentOnlinePayment,
    5067    omit=['display_item'])
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/tests/test_browser.py

    r13620 r13623  
    1919import shutil
    2020import tempfile
     21from time import time
    2122from datetime import datetime, timedelta
    2223from StringIO import StringIO
     
    3536from waeup.kofa.students.batching import StudentProcessor
    3637from waeup.kofa.students.interfaces import IStudentsUtils
     38from waeup.kofa.browser.tests.test_pdf import samples_dir
    3739from kofacustom.nigeria.students.batching import NigeriaStudentProcessor
    3840from kofacustom.nigeria.testing import FunctionalLayer
     
    417419            '...2016-01-16 15:50:48 WAT - Financial clearance withdrawn by Carlo Pitter...',
    418420            self.browser.contents)
     421
     422    def test_bursary_pdf_slip(self):
     423        payment1 = createObject(u'waeup.StudentOnlinePayment')
     424        timestamp = ("%d" % int(time()*10000))[1:]
     425        payment1.p_id = "p%s" % timestamp
     426        payment1.p_category = 'schoolfee'
     427        payment1.p_item = u'My School Fee'
     428        payment1.p_session = 2015
     429        payment1.p_level = 100
     430        payment1.p_current = True
     431        payment1.amount_auth = 23456.9
     432        payment1.approve()
     433        payment2 = createObject(u'waeup.StudentOnlinePayment')
     434        timestamp = ("%d" % int(time()*10000))[1:]
     435        payment2.p_id = "p%s" % timestamp
     436        payment2.p_category = 'clearance'
     437        payment2.p_item = u'My Clearance Fee'
     438        payment2.p_session = 2015
     439        payment2.p_level = 100
     440        payment2.p_current = True
     441        payment2.amount_auth = 5678.6
     442        payment2.approve()
     443        self.student['payments'][payment1.p_id] = payment1
     444        self.student['payments'][payment2.p_id] = payment2
     445        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     446        self.browser.open(self.student_path + '/clear_financially')
     447        self.browser.getLink("Download bursary clearance slip").click()
     448        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     449        self.assertEqual(self.browser.headers['Content-Type'],
     450                         'application/pdf')
     451        path = os.path.join(samples_dir(), 'bursary_clearance_slip.pdf')
     452        open(path, 'wb').write(self.browser.contents)
     453        print "Sample PDF bursary_clearance_slip.pdf written to %s" % path
     454        return
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/viewlets.py

    r13620 r13623  
    7070        return self.view.url(self.view.context, self.target)
    7171
     72class BursaryClearanceSlipActionButton(ManageActionButton):
     73    grok.order(12)
     74    grok.context(INigeriaStudent)
     75    grok.view(NigeriaStudentBaseDisplayFormPage)
     76    grok.require('waeup.viewStudent')
     77    text = _('Download bursary clearance slip')
     78    target = 'bursary_clearance_slip.pdf'
     79    icon = 'actionicon_pdf.png'
    7280
    7381# Acceptance Letter
Note: See TracChangeset for help on using the changeset viewer.