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

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

Export payments with student_state to sort out if payments do not correspond with states set manually by officers.

  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1## $Id: payments.py 9258 2012-09-30 13:05:04Z 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    @property
43    def student(self):
44        return self.__parent__
45
46    def writeLogMessage(self, view, message):
47        return self.__parent__.writeLogMessage(view, message)
48
49StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
50
51class StudentOnlinePayment(OnlinePayment):
52    """This is an online payment.
53    """
54    grok.implements(IStudentOnlinePayment, IStudentNavigation)
55    grok.provides(IStudentOnlinePayment)
56
57    def __init__(self):
58        super(StudentOnlinePayment, self).__init__()
59        return
60
61    @property
62    def student(self):
63        try:
64            return self.__parent__.__parent__
65        except AttributeError:
66            return None
67
68    @property
69    def student_state(self):
70        try:
71            return self.student.state
72        except AttributeError:
73            return None
74
75    def writeLogMessage(self, view, message):
76        return self.__parent__.__parent__.writeLogMessage(view, message)
77
78    def _createActivationCodes(self):
79        student = self.student
80        if self.p_category == 'clearance':
81            # Create CLR access code
82            pin, error = create_accesscode(
83                'CLR',0,self.amount_auth,student.student_id)
84            if error:
85                return error
86            self.ac = pin
87        elif self.p_category in ('schoolfee', 'schoolfee_1'):
88            # Create SFE access code
89            pin, error = create_accesscode(
90                'SFE',0,self.amount_auth,student.student_id)
91            if error:
92                return error
93            self.ac = pin
94        elif self.p_category == 'bed_allocation':
95            # Create HOS access code
96            pin, error = create_accesscode(
97                'HOS',0,self.amount_auth,student.student_id)
98            if error:
99                return error
100            self.ac = pin
101        return None
102
103    def doAfterStudentPayment(self):
104        """Process student after payment was made.
105        """
106        if self.p_current:
107            error = self._createActivationCodes()
108            if error is not None:
109                return False, error, error
110        log = 'successful payment: %s' % self.p_id
111        msg = _('Successful payment')
112        return True, msg, log
113
114    def doAfterStudentPaymentApproval(self):
115        """Process student after payment was approved.
116        """
117        if self.p_current:
118            error = self._createActivationCodes()
119            if error is not None:
120                return False, error, error
121        log = 'payment approved: %s' % self.p_id
122        msg = _('Payment approved')
123        return True, msg, log
124
125    def approveStudentPayment(self):
126        """Approve payment and process student.
127        """
128        if self.p_state == 'paid':
129            return False, _('This ticket has already been paid.'), None
130        self.approve()
131        return self.doAfterStudentPaymentApproval()
132
133
134StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment)
135
136class PaymentWebservice(grok.Adapter):
137    """An adapter to publish student data through a webservice.
138    """
139    grok.context(IStudentOnlinePayment)
140    grok.implements(IPaymentWebservice)
141
142    @property
143    def display_fullname(self):
144        "Name of  payee."
145        return self.context.student.display_fullname
146
147    @property
148    def id(self):
149        "Id of payee"
150        return self.context.student.student_id
151
152    @property
153    def faculty(self):
154        "Faculty of payee"
155        return self.context.student.faccode
156
157    @property
158    def department(self):
159        "Department of payee"
160        return self.context.student.depcode
161
162# Student online payments must be importable. So we might need a factory.
163class StudentOnlinePaymentFactory(grok.GlobalUtility):
164    """A factory for student online payments.
165    """
166    grok.implements(IFactory)
167    grok.name(u'waeup.StudentOnlinePayment')
168    title = u"Create a new online payment.",
169    description = u"This factory instantiates new online payment instances."
170
171    def __call__(self, *args, **kw):
172        return StudentOnlinePayment()
173
174    def getInterfaces(self):
175        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.