[1224] | 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 |
---|
[2859] | 15 | import logging |
---|
[1224] | 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 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""" |
---|
[1239] | 31 | return "Payments" |
---|
[1224] | 32 | |
---|
[2859] | 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() |
---|
[2874] | 38 | wftool = self.portal_workflow |
---|
[2859] | 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) |
---|
[2874] | 78 | |
---|
| 79 | review_state = wftool.getInfoFor(payment,'review_state',None) |
---|
| 80 | if review_state == "closed": |
---|
| 81 | wftool.doActionFor(payment,'open') |
---|
[2859] | 82 | doc.edit(mapping = d) |
---|
[2874] | 83 | if review_state == "closed": |
---|
| 84 | wftool.doActionFor(payment,'close') |
---|
[2859] | 85 | |
---|
[1224] | 86 | InitializeClass(PaymentsFolder) |
---|
| 87 | |
---|
| 88 | def 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 | |
---|
| 94 | class 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() |
---|
[1243] | 106 | description = getattr(content,'type_description','') |
---|
| 107 | d = getattr(content,'date','') |
---|
[1247] | 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") |
---|
[1243] | 110 | amount = getattr(content,'amount','') |
---|
| 111 | if not (description or pay_date or amount): |
---|
| 112 | return self.getId() |
---|
[1247] | 113 | return "%(description)s, Naira %(amount)s, %(pay_date)s" % vars() |
---|
[1243] | 114 | ###) |
---|
[1224] | 115 | |
---|
| 116 | InitializeClass(Payment) |
---|
| 117 | |
---|
| 118 | def addPayment(container, id, REQUEST=None, **kw): |
---|
| 119 | """Add a Payment.""" |
---|
| 120 | ob = Payment(id, **kw) |
---|
| 121 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 122 | ###) |
---|