#-*- 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 Payment objects """ 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,force = None): """upgrade all payments in folder""" logger = logging.getLogger('PaymentsFolder.updatePayments') #import pdb;pdb.set_trace() for payment in self.aq_parent.objectValues(): student_record = self.students_catalog.getRecordByKey(self.getStudentId()) payment['updatePayment'](student_record,force=force) 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 Nothing """ 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() ###) security.declareProtected(View,"updatePayment") def updatePayment(self,student_record,force=None): doc = self.getContent() if getattr(doc,'status',None) and not force: return wftool = self.portal_workflow d = {} d['key'] = self.getId() d['amount'] = doc.amount category = '' if doc.type_description.startswith('School'): category = 'schoolfee' sp = doc.type_description.rfind('/') d['session_id'] = doc.type_description[sp-2:sp] d['category'] = category # zb. schoolfee while True: if doc.resp_code == "SC": p_type = "sc" p_status = "paid" if type(doc.order_id) != type(''): d['order_id'] = str(doc.order_id) break if doc.resp_code in ("00","IP","AP"): p_type = "online" p_status = "paid" break p_type = "online" p_status = "started" # don't set order_id it is already correct if self.order_id.startswith('p'): try: self.payments_catalog.deleteRecord(self.order_id) except: pass d['order_id'] = "%s%s" % (student_record.id[1:],self.aq_parent.getId()[1:]) break d['type'] = p_type # scratch card d['item'] = getattr(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['resp_code'] = doc.resp_code # d['resp_card_num'] = doc.resp_card_num # d['date'] = getattr(doc,'date',None) review_state = wftool.getInfoFor(self.aq_parent,'review_state',None) if review_state == "closed": wftool.doActionFor(self.aq_parent,'open') doc.edit(mapping = d) if review_state == "closed": wftool.doActionFor(self.aq_parent,'close') InitializeClass(Payment) def addPayment(container, id, REQUEST=None, **kw): """Add a Payment.""" ob = Payment(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###)