1 | #-*- mode: python; mode: fold -*- |
---|
2 | from Globals import InitializeClass |
---|
3 | from AccessControl import ClassSecurityInfo |
---|
4 | |
---|
5 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
6 | from Products.CMFCore.permissions import View |
---|
7 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
8 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
9 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
10 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
11 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
12 | from Products.WAeUP_SRP.WAeUPTables import AccommodationTable |
---|
13 | import Globals |
---|
14 | import DateTime |
---|
15 | import logging |
---|
16 | import re |
---|
17 | p_home = Globals.package_home(globals()) |
---|
18 | i_home = Globals.INSTANCE_HOME |
---|
19 | |
---|
20 | class 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('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 | |
---|
43 | InitializeClass(PaymentsFolder) |
---|
44 | |
---|
45 | def 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 | |
---|
51 | class 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 | doc = self.getContent() |
---|
76 | if getattr(doc,'status',None) and not force: |
---|
77 | return |
---|
78 | wftool = self.portal_workflow |
---|
79 | d = {} |
---|
80 | d['key'] = self.getId() |
---|
81 | d['amount'] = doc.amount |
---|
82 | category = '' |
---|
83 | if doc.type_description.startswith('School'): |
---|
84 | category = 'schoolfee' |
---|
85 | sp = doc.type_description.rfind('/') |
---|
86 | d['session_id'] = doc.type_description[sp-2:sp] |
---|
87 | d['category'] = category # zb. schoolfee |
---|
88 | while True: |
---|
89 | if doc.resp_code == "SC": |
---|
90 | p_type = "sc" |
---|
91 | p_status = "paid" |
---|
92 | if type(doc.order_id) != type(''): |
---|
93 | d['order_id'] = str(doc.order_id) |
---|
94 | break |
---|
95 | |
---|
96 | #if self.order_id.startswith('p'): |
---|
97 | # try: |
---|
98 | # self.payments_catalog.deleteRecord(self.order_id) |
---|
99 | # except: |
---|
100 | # pass |
---|
101 | # d['order_id'] = "%s%s" % (student_record.id[1:],self.aq_parent.getId()[1:]) |
---|
102 | |
---|
103 | p_type = "online" |
---|
104 | if doc.resp_code in ("00","IP","AP"): |
---|
105 | p_status = "paid" |
---|
106 | break |
---|
107 | elif doc.resp_code == '': |
---|
108 | p_status = "started" |
---|
109 | else: |
---|
110 | p_status = "failed" |
---|
111 | # don't set order_id it is already correct |
---|
112 | |
---|
113 | break |
---|
114 | d['type'] = p_type # scratch card |
---|
115 | d['item'] = getattr(student_record,'course','') |
---|
116 | d['status'] = p_status |
---|
117 | # d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None) |
---|
118 | # d['resp_pay_reference'] = doc.resp_pay_reference |
---|
119 | # d['resp_desc'] = doc.resp_desc |
---|
120 | # d['resp_code'] = doc.resp_code |
---|
121 | # d['resp_card_num'] = doc.resp_card_num |
---|
122 | # d['date'] = getattr(doc,'date',None) |
---|
123 | |
---|
124 | review_state = wftool.getInfoFor(self.aq_parent,'review_state',None) |
---|
125 | if review_state == "closed": |
---|
126 | wftool.doActionFor(self.aq_parent,'open') |
---|
127 | doc.edit(mapping = d) |
---|
128 | if review_state == "closed": |
---|
129 | wftool.doActionFor(self.aq_parent,'close') |
---|
130 | |
---|
131 | InitializeClass(Payment) |
---|
132 | |
---|
133 | def addPayment(container, id, REQUEST=None, **kw): |
---|
134 | """Add a Payment.""" |
---|
135 | ob = Payment(id, **kw) |
---|
136 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
137 | ###) |
---|