source: WAeUP_SRP/base/Payment.py @ 2885

Last change on this file since 2885 was 2874, checked in by joachim, 17 years ago

fix for #430

  • Property svn:keywords set to Id
File size: 4.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 Paymentsmmodation halls
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    security.declareProtected(View,"updatePayments")
34    def updatePayments(self):
35        """upgrade all payments in folder"""
36        logger = logging.getLogger('PaymentsFolder.updatePayments')
37        #import pdb;pdb.set_trace()
38        wftool = self.portal_workflow
39        for payment in self.aq_parent.objectValues():
40            d = {}
41            student_record = self.students_catalog.getRecordByKey(self.getStudentId())
42            doc = payment.getContent()
43            d['key'] = payment.getId()
44            d['amount'] = doc.amount
45            d['description'] = d['type_description'] = doc.type_description
46            subject = ''
47            if doc.type_description.startswith('School'):
48                subject = 'schoolfee'
49            sp = doc.type_description.rfind('/')
50            d['session_id'] = doc.type_description[sp-2:sp]
51            d['subject'] = subject # zb. schoolfee
52            while True:
53                if doc.resp_code == "SC":
54                    p_type = "sc"
55                    p_status = "paid"
56                    break
57                if doc.resp_code in ("00","IP"):
58                    p_type = "online"
59                    p_status = "paid"
60                    break
61                p_type = "online"
62                p_status = "open"
63                break
64            d['key'] = payment.getId()
65            d['type'] = p_type  # scratch card
66            d['target'] = student_record.course
67            d['status'] = p_status
68            d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
69            d['resp_pay_reference'] = doc.resp_pay_reference
70            d['resp_desc'] = doc.resp_desc
71            d['order_id'] = doc.order_id
72            d['resp_code'] = doc.resp_code
73            d['resp_card_num'] = doc.resp_card_num
74            d['date'] = getattr(doc,'date',None)
75            d['resp_date'] = getattr(doc,'resp_date',None)
76            # msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()])
77            # logger.info(msg)
78           
79            review_state = wftool.getInfoFor(payment,'review_state',None)
80            if review_state == "closed":
81                wftool.doActionFor(payment,'open')
82            doc.edit(mapping = d)
83            if review_state == "closed":
84                wftool.doActionFor(payment,'close')
85
86InitializeClass(PaymentsFolder)
87
88def addPaymentsFolder(container, id, REQUEST=None, **kw):
89    """Add a PaymentsFolder."""
90    ob = PaymentsFolder(id, **kw)
91    return CPSBase_adder(container, ob, REQUEST=REQUEST)
92###)
93
94class Payment(CPSDocument): ###(
95    """
96    WAeUP Payment containing Departments
97    """
98    meta_type = 'Payment'
99    portal_type = meta_type
100    security = ClassSecurityInfo()
101
102    security.declareProtected(View,"Title") ###(
103    def Title(self):
104        """compose title"""
105        content = self.getContent()
106        description = getattr(content,'type_description','')
107        d = getattr(content,'date','')
108        #pay_date = "%s/%s/%s %s:%s:%s" %(d[:2],d[2:4],d[4:6],d[6:8],d[8:10],d[10:])
109        pay_date = d.strftime("%d/%m/%y %H:%M:%S")
110        amount = getattr(content,'amount','')
111        if not (description or pay_date or amount):
112            return self.getId()
113        return "%(description)s, Naira %(amount)s, %(pay_date)s" % vars()
114    ###)
115
116InitializeClass(Payment)
117
118def addPayment(container, id, REQUEST=None, **kw):
119    """Add a Payment."""
120    ob = Payment(id, **kw)
121    return CPSBase_adder(container, ob, REQUEST=REQUEST)
122###)
Note: See TracBrowser for help on using the repository browser.