source: WAeUP_SRP/base/Payment.py @ 2938

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

do not update payments online if status == 'started' (too many conflict errors)

  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
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
15import logging
16import re
17p_home = Globals.package_home(globals())
18i_home = Globals.INSTANCE_HOME
19
20class PaymentsFolder(CPSDocument): ###(
21    """
22    WAeUP PaymentsFolder containing Payment objects
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"""
31        return "Payments"
32
33
34    security.declareProtected(View,"updatePayments")
35    def updatePayments(self,force = None):
36        """upgrade all payments in folder"""
37        logger = logging.getLogger('Payment.PaymentsFolder.updatePayments')
38        #import pdb;pdb.set_trace()
39        for payment in self.aq_parent.objectValues():
40            student_record = self.students_catalog.getRecordByKey(self.getStudentId())
41            payment['updatePayment'](student_record,force=force)
42
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    """
53    WAeUP Payment containing Nothing
54    """
55    meta_type = 'Payment'
56    portal_type = meta_type
57    security = ClassSecurityInfo()
58
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
73    security.declareProtected(View,"updatePayment")
74    def updatePayment(self,student_record,force=None):
75        logger = logging.getLogger('Payment.Payment.updatePayment')
76        doc = self.getContent()
77        status = getattr(doc,'status',None)
78        type_description = getattr(doc,'type_description',None)
79        #if status and status != 'started' and not type_description.startswith('Transfer') and not force:
80        if status and not force: # should not be done online for all started objects (too many conflict errors)
81            return
82        wftool = self.portal_workflow
83        d = {}
84        #d['key'] = self.getId()
85        d['amount'] = doc.amount
86        category = ''
87        if doc.type_description.startswith('School'):
88            category = 'schoolfee'
89            sp = doc.type_description.rfind('/')
90            d['session_id'] = doc.type_description[sp-2:sp]
91            d['category'] = category # zb. schoolfee
92        if doc.type_description.startswith('Transfer'):
93            category = 'transfer'
94            sp = doc.type_description.rfind('/')
95            d['session_id'] = doc.type_description[sp-2:sp]
96            d['category'] = category # zb. schoolfee
97        while True:
98            if doc.resp_code == "SC":
99                p_type = "sc"
100                p_status = "paid"
101                if type(doc.order_id) != type(''):
102                    d['order_id'] = str(doc.order_id)
103                break
104
105            #if self.order_id.startswith('p'):
106            #    try:
107            #        self.payments_catalog.deleteRecord(self.order_id)
108            #    except:
109            #        pass
110            #    d['order_id'] = "%s%s" % (student_record.id[1:],self.aq_parent.getId()[1:])
111
112            p_type = "online"
113            if doc.resp_code in ("00","IP","AP"):
114                p_status = "paid"
115            elif doc.resp_code == '':
116                p_status = "started"
117            else:
118                p_status = "failed"
119            # don't set order_id it is already correct
120            break
121        d['type'] = p_type  # scratch card
122        d['item'] = getattr(student_record,'course','')
123        d['status'] = p_status
124        # d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
125        # d['resp_pay_reference'] = doc.resp_pay_reference
126        # d['resp_desc'] = doc.resp_desc
127        # d['resp_code'] = doc.resp_code
128        # d['resp_card_num'] = doc.resp_card_num
129        # d['date'] = getattr(doc,'date',None)
130
131        review_state = wftool.getInfoFor(self.aq_parent,'review_state',None)
132        if review_state == "closed":
133            wftool.doActionFor(self.aq_parent,'open')
134        doc.edit(mapping = d)
135        if review_state == "closed":
136            wftool.doActionFor(self.aq_parent,'close')
137        logger.info('updated student %s payment %s' % (student_record.id,self.aq_parent.getId()))
138
139InitializeClass(Payment)
140
141def addPayment(container, id, REQUEST=None, **kw):
142    """Add a Payment."""
143    ob = Payment(id, **kw)
144    return CPSBase_adder(container, ob, REQUEST=REQUEST)
145###)
Note: See TracBrowser for help on using the repository browser.