#-*- mode: python; mode: fold -*- from Globals import InitializeClass from AccessControl import ClassSecurityInfo from Products.CMFCore.utils import UniqueObject, getToolByName from Products.CMFCore.permissions import View from Products.CMFCore.permissions import ModifyPortalContent from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument from Products.CPSDocument.CPSDocument import CPSDocument from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder from Products.WAeUP_SRP.WAeUPTables import AccommodationTable import Globals import DateTime import logging import re p_home = Globals.package_home(globals()) i_home = Globals.INSTANCE_HOME class PaymentsFolder(CPSDocument): ###( """ WAeUP PaymentsFolder containing Paymentsmmodation halls """ meta_type = 'PaymentsFolder' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") def Title(self): """compose title""" return "Payments" security.declareProtected(View,"updatePayments") def updatePayments(self): """upgrade all payments in folder""" logger = logging.getLogger('PaymentsFolder.updatePayments') #import pdb;pdb.set_trace() wftool = self.portal_workflow for payment in self.aq_parent.objectValues(): d = {} student_record = self.students_catalog.getRecordByKey(self.getStudentId()) doc = payment.getContent() d['key'] = payment.getId() d['amount'] = doc.amount d['description'] = d['type_description'] = doc.type_description subject = '' if doc.type_description.startswith('School'): subject = 'schoolfee' sp = doc.type_description.rfind('/') d['session_id'] = doc.type_description[sp-2:sp] d['subject'] = subject # zb. schoolfee while True: if doc.resp_code == "SC": p_type = "sc" p_status = "paid" break if doc.resp_code in ("00","IP"): p_type = "online" p_status = "paid" break p_type = "online" p_status = "open" break d['key'] = payment.getId() d['type'] = p_type # scratch card d['target'] = student_record.course d['status'] = p_status d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None) d['resp_pay_reference'] = doc.resp_pay_reference d['resp_desc'] = doc.resp_desc d['order_id'] = doc.order_id d['resp_code'] = doc.resp_code d['resp_card_num'] = doc.resp_card_num d['date'] = getattr(doc,'date',None) d['resp_date'] = getattr(doc,'resp_date',None) # msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()]) # logger.info(msg) review_state = wftool.getInfoFor(payment,'review_state',None) if review_state == "closed": wftool.doActionFor(payment,'open') doc.edit(mapping = d) if review_state == "closed": wftool.doActionFor(payment,'close') InitializeClass(PaymentsFolder) def addPaymentsFolder(container, id, REQUEST=None, **kw): """Add a PaymentsFolder.""" ob = PaymentsFolder(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) class Payment(CPSDocument): ###( """ WAeUP Payment containing Departments """ meta_type = 'Payment' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") ###( def Title(self): """compose title""" content = self.getContent() description = getattr(content,'type_description','') d = getattr(content,'date','') #pay_date = "%s/%s/%s %s:%s:%s" %(d[:2],d[2:4],d[4:6],d[6:8],d[8:10],d[10:]) pay_date = d.strftime("%d/%m/%y %H:%M:%S") amount = getattr(content,'amount','') if not (description or pay_date or amount): return self.getId() return "%(description)s, Naira %(amount)s, %(pay_date)s" % vars() ###) InitializeClass(Payment) def addPayment(container, id, REQUEST=None, **kw): """Add a Payment.""" ob = Payment(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###)