source: main/waeup.kofa/trunk/src/waeup/kofa/students/payments.py @ 8735

Last change on this file since 8735 was 8735, checked in by Henrik Bettermann, 12 years ago

Let's use the msave helper function also in university and other packages. msave applies applyData to the view and writes a view-specific log message. The context object of the view must have a writeLogMessage method.

In the students package writeLogMessage is now provided by all classes which implement IStudentNavigation.

  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1## $Id: payments.py 8735 2012-06-17 06:42:20Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Student payment components.
20"""
21import grok
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from waeup.kofa.interfaces import MessageFactory as _
25from waeup.kofa.students.interfaces import (
26    IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment)
27from waeup.kofa.payments import PaymentsContainer, OnlinePayment
28from waeup.kofa.payments.interfaces import IPaymentWebservice
29from waeup.kofa.utils.helpers import attrs_to_fields
30from waeup.kofa.accesscodes import create_accesscode
31
32class StudentPaymentsContainer(PaymentsContainer):
33    """This is a container for student payments.
34    """
35    grok.implements(IStudentPaymentsContainer, IStudentNavigation)
36    grok.provides(IStudentPaymentsContainer)
37
38    def __init__(self):
39        super(StudentPaymentsContainer, self).__init__()
40        return
41
42    def getStudent(self):
43        return self.__parent__
44
45    def writeLogMessage(self, view, message):
46        return self.__parent__.writeLogMessage(view, message)
47
48StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
49
50class StudentOnlinePayment(OnlinePayment):
51    """This is an online payment.
52    """
53    grok.implements(IStudentOnlinePayment, IStudentNavigation)
54    grok.provides(IStudentOnlinePayment)
55
56    def __init__(self):
57        super(StudentOnlinePayment, self).__init__()
58        return
59
60    def getStudent(self):
61        try:
62            return self.__parent__.__parent__
63        except AttributeError:
64            return None
65
66    def writeLogMessage(self, view, message):
67        return self.__parent__.__parent__.writeLogMessage(view, message)
68
69    def _createActivationCodes(self):
70        student = self.getStudent()
71        if self.p_category == 'clearance':
72            # Create CLR access code
73            pin, error = create_accesscode(
74                'CLR',0,self.amount_auth,student.student_id)
75            if error:
76                return error
77            self.ac = pin
78        elif self.p_category in ('schoolfee', 'schoolfee_1'):
79            # Create SFE access code
80            pin, error = create_accesscode(
81                'SFE',0,self.amount_auth,student.student_id)
82            if error:
83                return error
84            self.ac = pin
85        elif self.p_category == 'bed_allocation':
86            # Create HOS access code
87            pin, error = create_accesscode(
88                'HOS',0,self.amount_auth,student.student_id)
89            if error:
90                return error
91            self.ac = pin
92        return None
93
94    def doAfterStudentPayment(self):
95        """Process student after payment was made.
96        """
97        error = self._createActivationCodes()
98        if error is not None:
99            return False, error, error
100        log = 'successful payment: %s' % self.p_id
101        msg = _('Successful payment')
102        return True, msg, log
103
104    def doAfterStudentPaymentApproval(self):
105        """Process student after payment was approved.
106        """
107        error = self._createActivationCodes()
108        if error is not None:
109            return False, error, error
110        log = 'payment approved: %s' % self.p_id
111        msg = _('Payment approved')
112        return True, msg, log
113
114    def approveStudentPayment(self):
115        """Approve payment and process student.
116        """
117        if self.p_state == 'paid':
118            return False, _('This ticket has already been paid.'), None
119        self.approve()
120        return self.doAfterStudentPaymentApproval()
121
122
123StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment)
124
125class PaymentWebservice(grok.Adapter):
126    """An adapter to publish student data through a webservice.
127    """
128    grok.context(IStudentOnlinePayment)
129    grok.implements(IPaymentWebservice)
130
131    @property
132    def display_fullname(self):
133        "Name of  payee."
134        return self.context.getStudent().display_fullname
135
136    @property
137    def id(self):
138        "Id of payee"
139        return self.context.getStudent().student_id
140
141    @property
142    def faculty(self):
143        "Faculty of payee"
144        return self.context.getStudent().faccode
145
146    @property
147    def department(self):
148        "Department of payee"
149        return self.context.getStudent().depcode
150
151# Student online payments must be importable. So we might need a factory.
152class StudentOnlinePaymentFactory(grok.GlobalUtility):
153    """A factory for student online payments.
154    """
155    grok.implements(IFactory)
156    grok.name(u'waeup.StudentOnlinePayment')
157    title = u"Create a new online payment.",
158    description = u"This factory instantiates new online payment instances."
159
160    def __call__(self, *args, **kw):
161        return StudentOnlinePayment()
162
163    def getInterfaces(self):
164        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.