source: WAeUP_SRP/base/Payment.py @ 3443

Last change on this file since 3443 was 3274, checked in by Henrik Bettermann, 17 years ago

new title for payment objects

  • Property svn:keywords set to Id
File size: 6.3 KB
RevLine 
[1224]1#-*- mode: python; mode: fold -*-
2from Globals import InitializeClass
3from AccessControl import ClassSecurityInfo
4
5from Products.CMFCore.utils import UniqueObject, getToolByName
6from Products.CMFCore.permissions import View
7from Products.CMFCore.permissions import ModifyPortalContent
8from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
9#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
10from Products.CPSDocument.CPSDocument import CPSDocument
11from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
12from Products.WAeUP_SRP.WAeUPTables import AccommodationTable
13import Globals
14import DateTime
[2859]15import logging
[1224]16import re
17p_home = Globals.package_home(globals())
18i_home = Globals.INSTANCE_HOME
19
20class PaymentsFolder(CPSDocument): ###(
21    """
[2900]22    WAeUP PaymentsFolder containing Payment objects
[1224]23    """
24    meta_type = 'PaymentsFolder'
25    portal_type = meta_type
26    security = ClassSecurityInfo()
27
28    security.declareProtected(View,"Title")
29    def Title(self):
30        """compose title"""
[1239]31        return "Payments"
[1224]32
[2897]33
[2859]34    security.declareProtected(View,"updatePayments")
[2904]35    def updatePayments(self,force = None):
[2859]36        """upgrade all payments in folder"""
[2932]37        logger = logging.getLogger('Payment.PaymentsFolder.updatePayments')
[2859]38        #import pdb;pdb.set_trace()
39        for payment in self.aq_parent.objectValues():
[2898]40            student_record = self.students_catalog.getRecordByKey(self.getStudentId())
[2904]41            payment['updatePayment'](student_record,force=force)
[2891]42
[1224]43InitializeClass(PaymentsFolder)
44
45def addPaymentsFolder(container, id, REQUEST=None, **kw):
46    """Add a PaymentsFolder."""
47    ob = PaymentsFolder(id, **kw)
48    return CPSBase_adder(container, ob, REQUEST=REQUEST)
49###)
50
51class Payment(CPSDocument): ###(
52    """
[2900]53    WAeUP Payment containing Nothing
[1224]54    """
55    meta_type = 'Payment'
56    portal_type = meta_type
57    security = ClassSecurityInfo()
58
[3274]59#    security.declareProtected(View,"Title")
60#    def Title(self):
61#        """compose title"""
62#        content = self.getContent()
63#        description = getattr(content,'type_description','')
64#        d = getattr(content,'date','')
65#        #pay_date = "%s/%s/%s %s:%s:%s" %(d[:2],d[2:4],d[4:6],d[6:8],d[8:10],d[10:])
66#        pay_date = d.strftime("%d/%m/%y %H:%M:%S")
67#        amount = getattr(content,'amount','')
68#        if not (description or pay_date or amount):
69#            return self.getId()
70#        return "%(description)s, Naira %(amount)s, %(pay_date)s" % vars()
71
72    security.declareProtected(View,"Title")
[1224]73    def Title(self):
74        """compose title"""
[3274]75        payment = self.getContent()
76        vocabularies = self.portal_vocabularies
77       
78        if payment.status == 'invalid':
79            return "Invalid Payment, Naira %s, %s" % (payment.amount,
80                                                      payment.date.strftime("%d/%m/%y %H:%M:%S"))             
81       
82        return "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
83                                                    vocabularies.sessions.get(payment.session_id),
84                                                    payment.amount,
85                                                    payment.date.strftime("%d/%m/%y %H:%M:%S"))       
[1224]86
[3274]87
[2947]88    # update Payment is no longer necessary
[2897]89    security.declareProtected(View,"updatePayment")
[2904]90    def updatePayment(self,student_record,force=None):
[2932]91        logger = logging.getLogger('Payment.Payment.updatePayment')
[2897]92        doc = self.getContent()
[2926]93        status = getattr(doc,'status',None)
[2929]94        type_description = getattr(doc,'type_description',None)
[2946]95
96        ## should not be done online for all started objects (too many conflict errors)
97        if status and status != 'started' and not type_description.startswith('Transfer') and not force:
[3274]98        #if status and not force:
[2897]99            return
100        wftool = self.portal_workflow
101        d = {}
[2931]102        #d['key'] = self.getId()
[2897]103        d['amount'] = doc.amount
104        category = ''
105        if doc.type_description.startswith('School'):
106            category = 'schoolfee'
[2909]107            sp = doc.type_description.rfind('/')
108            d['session_id'] = doc.type_description[sp-2:sp]
109            d['category'] = category # zb. schoolfee
[2928]110        if doc.type_description.startswith('Transfer'):
111            category = 'transfer'
112            sp = doc.type_description.rfind('/')
113            d['session_id'] = doc.type_description[sp-2:sp]
[2931]114            d['category'] = category # zb. schoolfee
[2897]115        while True:
116            if doc.resp_code == "SC":
117                p_type = "sc"
118                p_status = "paid"
[2907]119                if type(doc.order_id) != type(''):
120                    d['order_id'] = str(doc.order_id)
[2897]121                break
[2916]122
[2917]123            #if self.order_id.startswith('p'):
124            #    try:
125            #        self.payments_catalog.deleteRecord(self.order_id)
126            #    except:
127            #        pass
128            #    d['order_id'] = "%s%s" % (student_record.id[1:],self.aq_parent.getId()[1:])
[2916]129
[2925]130            p_type = "online"
[2897]131            if doc.resp_code in ("00","IP","AP"):
132                p_status = "paid"
[2925]133            elif doc.resp_code == '':
134                p_status = "started"
135            else:
136                p_status = "failed"
[2904]137            # don't set order_id it is already correct
[2897]138            break
139        d['type'] = p_type  # scratch card
140        d['item'] = getattr(student_record,'course','')
141        d['status'] = p_status
[2907]142        # d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
143        # d['resp_pay_reference'] = doc.resp_pay_reference
144        # d['resp_desc'] = doc.resp_desc
145        # d['resp_code'] = doc.resp_code
146        # d['resp_card_num'] = doc.resp_card_num
147        # d['date'] = getattr(doc,'date',None)
[2900]148
[2899]149        review_state = wftool.getInfoFor(self.aq_parent,'review_state',None)
[2897]150        if review_state == "closed":
[2899]151            wftool.doActionFor(self.aq_parent,'open')
[2897]152        doc.edit(mapping = d)
153        if review_state == "closed":
[2899]154            wftool.doActionFor(self.aq_parent,'close')
[2937]155        logger.info('updated student %s payment %s' % (student_record.id,self.aq_parent.getId()))
[2897]156
[1224]157InitializeClass(Payment)
158
159def addPayment(container, id, REQUEST=None, **kw):
160    """Add a Payment."""
161    ob = Payment(id, **kw)
162    return CPSBase_adder(container, ob, REQUEST=REQUEST)
163###)
Note: See TracBrowser for help on using the repository browser.