[7195] | 1 | ## $Id: payment.py 8182 2012-04-16 20:56:59Z henrik $ |
---|
| 2 | ## |
---|
[6864] | 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 | """ |
---|
| 19 | These are the payment tickets. |
---|
| 20 | """ |
---|
| 21 | import grok |
---|
[6869] | 22 | from datetime import datetime |
---|
[6864] | 23 | from grok import index |
---|
[8182] | 24 | from zope.component import getUtility |
---|
| 25 | from waeup.kofa.interfaces import IKofaUtils |
---|
[7811] | 26 | from waeup.kofa.payments.interfaces import ( |
---|
[7627] | 27 | IPayment, ISCPayment, IOnlinePayment, |
---|
| 28 | payment_states, payment_categories) |
---|
[7811] | 29 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[6864] | 30 | |
---|
| 31 | class Payment(grok.Container): |
---|
| 32 | """This is a payment. |
---|
| 33 | """ |
---|
| 34 | grok.implements(IPayment) |
---|
| 35 | grok.provides(IPayment) |
---|
| 36 | grok.baseclass() |
---|
| 37 | |
---|
| 38 | def __init__(self): |
---|
| 39 | super(Payment, self).__init__() |
---|
[8182] | 40 | try: |
---|
| 41 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 42 | except: |
---|
| 43 | #In unit tests KofaUtils is not available. |
---|
| 44 | tz = None |
---|
| 45 | self.creation_date = datetime.now(tz) |
---|
[6869] | 46 | self.p_id = None |
---|
[6864] | 47 | return |
---|
| 48 | |
---|
[6869] | 49 | @property |
---|
| 50 | def state(self): |
---|
| 51 | return payment_states.getTermByToken(self.p_state).title |
---|
| 52 | |
---|
| 53 | @property |
---|
| 54 | def category(self): |
---|
| 55 | return payment_categories.getTermByToken(self.p_category).title |
---|
| 56 | |
---|
[6864] | 57 | class SCPayment(Payment): |
---|
| 58 | """This is a scratch card payment. |
---|
| 59 | """ |
---|
| 60 | grok.implements(ISCPayment) |
---|
| 61 | grok.provides(ISCPayment) |
---|
| 62 | |
---|
| 63 | def __init__(self): |
---|
| 64 | super(SCPayment, self).__init__() |
---|
[6869] | 65 | p_id = None |
---|
[6864] | 66 | return |
---|
| 67 | |
---|
| 68 | SCPayment = attrs_to_fields(SCPayment) |
---|
| 69 | |
---|
| 70 | class OnlinePayment(Payment): |
---|
| 71 | """This is an online payment. |
---|
| 72 | """ |
---|
| 73 | grok.implements(IOnlinePayment) |
---|
| 74 | grok.provides(IOnlinePayment) |
---|
| 75 | |
---|
| 76 | def __init__(self): |
---|
| 77 | super(OnlinePayment, self).__init__() |
---|
[6869] | 78 | p_id = None |
---|
[6864] | 79 | return |
---|
| 80 | |
---|
[7811] | 81 | OnlinePayment = attrs_to_fields(OnlinePayment) |
---|