source: main/waeup.kofa/trunk/src/waeup/kofa/payments/payment.py @ 9984

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

FCEOkene wants to hide the bed coordinates if maintenance fee is not yet paid. Thus we need additional property attributes which return the p_item (payment tickets) and the bed_coordinates attributes (bed tickets) by default and can be easily customized to hide this information in certain cases. bed_coordinates and p_item must be omitted on forms. The new display_ attributes are displayed instead.

All packages must now be adjusted.

The 'cost-benefit ratio' of these kinds of customizations is quite bad and we should think about declining such customization requests. However, I started customization and these are the changed made in the base package.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: payment.py 9984 2013-02-24 08:29:24Z 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"""
19These are the payment tickets.
20"""
21import grok
22from datetime import datetime
23from grok import index
24from zope.event import notify
25from zope.component import getUtility
26from zope.i18n import translate
27from waeup.kofa.interfaces import IKofaUtils
28from waeup.kofa.interfaces import MessageFactory as _
29from waeup.kofa.payments.interfaces import (
30    IPayment, IOnlinePayment,
31    payment_states)
32from waeup.kofa.utils.helpers import attrs_to_fields, get_current_principal
33from waeup.kofa.utils.logger import Logger
34
35class Payment(grok.Container, Logger):
36    """This is a payment.
37    """
38    grok.implements(IPayment)
39    grok.provides(IPayment)
40    grok.baseclass()
41
42    logger_name = 'waeup.kofa.${sitename}.payments'
43    logger_filename = 'payments.log'
44    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
45
46    def logger_info(self, comment=None):
47        """Get the logger's info method.
48        """
49        self.logger.info('%s' % comment)
50        return
51
52    def __init__(self):
53        super(Payment, self).__init__()
54        self.creation_date = datetime.utcnow()
55        self.p_id = None
56        return
57
58    @property
59    def state(self):
60        return payment_states.getTermByToken(self.p_state).title
61
62    @property
63    def category(self):
64        utils = getUtility(IKofaUtils)
65        return utils.PAYMENT_CATEGORIES[self.p_category]
66
67    @property
68    def display_item(self):
69        return self.p_item
70
71class OnlinePayment(Payment):
72    """This is an online payment.
73    """
74    grok.implements(IOnlinePayment)
75    grok.provides(IOnlinePayment)
76
77    def __init__(self):
78        super(OnlinePayment, self).__init__()
79        p_id = None
80        return
81
82    def approve(self):
83        "Approve online payment and set to paid."
84        self.r_amount_approved = self.amount_auth
85        self.r_code = u'AP'
86        self.p_state = 'paid'
87        user = get_current_principal()
88        if user is None:
89            # in tests
90            usertitle = 'system'
91        else:
92            usertitle = getattr(user, 'public_name', None)
93            if not usertitle:
94                usertitle = user.title
95        r_desc = _('Payment approved by ${a}', mapping = {'a': usertitle})
96        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
97        self.r_desc = translate(r_desc, 'waeup.kofa',
98            target_language=portal_language)
99        self.payment_date = datetime.utcnow()
100        # Update catalog
101        notify(grok.ObjectModifiedEvent(self))
102        return
103
104OnlinePayment = attrs_to_fields(OnlinePayment, omit=['display_item'])
Note: See TracBrowser for help on using the repository browser.