[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 | """ |
---|
[2900] | 22 | WAeUP PaymentsFolder containing Payment objects |
---|
[1224] | 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 | |
---|
[2897] | 33 | |
---|
[2859] | 34 | security.declareProtected(View,"updatePayments") |
---|
[2904] | 35 | def updatePayments(self,force = None): |
---|
[2859] | 36 | """upgrade all payments in folder""" |
---|
[2932] | 37 | logger = logging.getLogger('Payment.PaymentsFolder.updatePayments') |
---|
[2859] | 38 | #import pdb;pdb.set_trace() |
---|
| 39 | for payment in self.aq_parent.objectValues(): |
---|
[2898] | 40 | student_record = self.students_catalog.getRecordByKey(self.getStudentId()) |
---|
[2904] | 41 | payment['updatePayment'](student_record,force=force) |
---|
[2891] | 42 | |
---|
[1224] | 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 | """ |
---|
[2900] | 53 | WAeUP Payment containing Nothing |
---|
[1224] | 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() |
---|
[1243] | 63 | description = getattr(content,'type_description','') |
---|
| 64 | d = getattr(content,'date','') |
---|
[1247] | 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") |
---|
[1243] | 67 | amount = getattr(content,'amount','') |
---|
| 68 | if not (description or pay_date or amount): |
---|
| 69 | return self.getId() |
---|
[1247] | 70 | return "%(description)s, Naira %(amount)s, %(pay_date)s" % vars() |
---|
[1243] | 71 | ###) |
---|
[1224] | 72 | |
---|
[2947] | 73 | # update Payment is no longer necessary |
---|
[2897] | 74 | security.declareProtected(View,"updatePayment") |
---|
[2904] | 75 | def updatePayment(self,student_record,force=None): |
---|
[2932] | 76 | logger = logging.getLogger('Payment.Payment.updatePayment') |
---|
[2897] | 77 | doc = self.getContent() |
---|
[2926] | 78 | status = getattr(doc,'status',None) |
---|
[2929] | 79 | type_description = getattr(doc,'type_description',None) |
---|
[2946] | 80 | |
---|
| 81 | ## should not be done online for all started objects (too many conflict errors) |
---|
| 82 | if status and status != 'started' and not type_description.startswith('Transfer') and not force: |
---|
| 83 | #if status and not force: |
---|
[2897] | 84 | return |
---|
| 85 | wftool = self.portal_workflow |
---|
| 86 | d = {} |
---|
[2931] | 87 | #d['key'] = self.getId() |
---|
[2897] | 88 | d['amount'] = doc.amount |
---|
| 89 | category = '' |
---|
| 90 | if doc.type_description.startswith('School'): |
---|
| 91 | category = 'schoolfee' |
---|
[2909] | 92 | sp = doc.type_description.rfind('/') |
---|
| 93 | d['session_id'] = doc.type_description[sp-2:sp] |
---|
| 94 | d['category'] = category # zb. schoolfee |
---|
[2928] | 95 | if doc.type_description.startswith('Transfer'): |
---|
| 96 | category = 'transfer' |
---|
| 97 | sp = doc.type_description.rfind('/') |
---|
| 98 | d['session_id'] = doc.type_description[sp-2:sp] |
---|
[2931] | 99 | d['category'] = category # zb. schoolfee |
---|
[2897] | 100 | while True: |
---|
| 101 | if doc.resp_code == "SC": |
---|
| 102 | p_type = "sc" |
---|
| 103 | p_status = "paid" |
---|
[2907] | 104 | if type(doc.order_id) != type(''): |
---|
| 105 | d['order_id'] = str(doc.order_id) |
---|
[2897] | 106 | break |
---|
[2916] | 107 | |
---|
[2917] | 108 | #if self.order_id.startswith('p'): |
---|
| 109 | # try: |
---|
| 110 | # self.payments_catalog.deleteRecord(self.order_id) |
---|
| 111 | # except: |
---|
| 112 | # pass |
---|
| 113 | # d['order_id'] = "%s%s" % (student_record.id[1:],self.aq_parent.getId()[1:]) |
---|
[2916] | 114 | |
---|
[2925] | 115 | p_type = "online" |
---|
[2897] | 116 | if doc.resp_code in ("00","IP","AP"): |
---|
| 117 | p_status = "paid" |
---|
[2925] | 118 | elif doc.resp_code == '': |
---|
| 119 | p_status = "started" |
---|
| 120 | else: |
---|
| 121 | p_status = "failed" |
---|
[2904] | 122 | # don't set order_id it is already correct |
---|
[2897] | 123 | break |
---|
| 124 | d['type'] = p_type # scratch card |
---|
| 125 | d['item'] = getattr(student_record,'course','') |
---|
| 126 | d['status'] = p_status |
---|
[2907] | 127 | # d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None) |
---|
| 128 | # d['resp_pay_reference'] = doc.resp_pay_reference |
---|
| 129 | # d['resp_desc'] = doc.resp_desc |
---|
| 130 | # d['resp_code'] = doc.resp_code |
---|
| 131 | # d['resp_card_num'] = doc.resp_card_num |
---|
| 132 | # d['date'] = getattr(doc,'date',None) |
---|
[2900] | 133 | |
---|
[2899] | 134 | review_state = wftool.getInfoFor(self.aq_parent,'review_state',None) |
---|
[2897] | 135 | if review_state == "closed": |
---|
[2899] | 136 | wftool.doActionFor(self.aq_parent,'open') |
---|
[2897] | 137 | doc.edit(mapping = d) |
---|
| 138 | if review_state == "closed": |
---|
[2899] | 139 | wftool.doActionFor(self.aq_parent,'close') |
---|
[2937] | 140 | logger.info('updated student %s payment %s' % (student_record.id,self.aq_parent.getId())) |
---|
[2897] | 141 | |
---|
[1224] | 142 | InitializeClass(Payment) |
---|
| 143 | |
---|
| 144 | def addPayment(container, id, REQUEST=None, **kw): |
---|
| 145 | """Add a Payment.""" |
---|
| 146 | ob = Payment(id, **kw) |
---|
| 147 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 148 | ###) |
---|