1 | ## Script (Python) "upgradePayments.py" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: upgradePayments.py 2859 2007-12-04 19:24:23Z joachim $ |
---|
11 | """ |
---|
12 | """ |
---|
13 | try: |
---|
14 | from Products.zdb import set_trace |
---|
15 | except: |
---|
16 | def set_trace(): |
---|
17 | pass |
---|
18 | |
---|
19 | mtool = context.portal_membership |
---|
20 | member = mtool.getAuthenticatedMember() |
---|
21 | if str(member) not in ('admin','joachim'): |
---|
22 | return |
---|
23 | |
---|
24 | |
---|
25 | import logging |
---|
26 | import DateTime |
---|
27 | logger = logging.getLogger('Skins.upgradePayments') |
---|
28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
29 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
30 | aq_student = context.students_catalog.evalAdvancedQuery |
---|
31 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
32 | |
---|
33 | request = context.REQUEST |
---|
34 | session = request.SESSION |
---|
35 | response = request.RESPONSE |
---|
36 | setheader = request.RESPONSE.setHeader |
---|
37 | def rwrite(s): |
---|
38 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
39 | response.write("%s<br>\n\r" % s) |
---|
40 | |
---|
41 | count = 1 |
---|
42 | d = {} |
---|
43 | l = [] |
---|
44 | sum_total = 0.0 |
---|
45 | log_after = 100 |
---|
46 | logger.info("start") |
---|
47 | query = Eq('portal_type','Payment') |
---|
48 | payments = aq_portal(query,sortSpecs=('container_path',)) |
---|
49 | total = len(payments) |
---|
50 | logger.info("found %d payments" % total) |
---|
51 | sid = "xxx" |
---|
52 | #set_trace() |
---|
53 | count = 1 |
---|
54 | commit_after = 5 |
---|
55 | commit_count = 0 |
---|
56 | |
---|
57 | set_trace() |
---|
58 | for payment in payments: |
---|
59 | student_id = payment.getPath().split('/')[-3] |
---|
60 | student_brain = context.students_catalog.getRecordByKey(student_id) |
---|
61 | if student_brain is None: |
---|
62 | logger.info("student %s not in students_catalog" % student_id) |
---|
63 | continue |
---|
64 | d = {} |
---|
65 | doc = payment.getObject().getContent() |
---|
66 | d['key'] = payment.getId |
---|
67 | d['amount'] = doc.amount |
---|
68 | d['description'] = d['type_description'] = doc.type_description |
---|
69 | subject = '' |
---|
70 | if doc.type_description.startswith('School'): |
---|
71 | subject = 'schoolfee' |
---|
72 | sp = doc.type_description.rfind('/') |
---|
73 | d['session_id'] = doc.type_description[sp-2:sp] |
---|
74 | d['subject'] = subject # zb. schoolfee |
---|
75 | d['target'] = "%s" % (student_brain.course) # faculty departmen course |
---|
76 | while True: |
---|
77 | if doc.resp_code == "SC": |
---|
78 | p_type = "sc" |
---|
79 | p_status = "paid" |
---|
80 | break |
---|
81 | if doc.resp_code == "00": |
---|
82 | p_type = "onl" |
---|
83 | p_status = "paid" |
---|
84 | break |
---|
85 | p_type = "ONL" |
---|
86 | p_status = "open" |
---|
87 | break |
---|
88 | d['key'] = payment.getId |
---|
89 | d['type'] = p_type # scratch card |
---|
90 | d['status'] = p_status |
---|
91 | d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None) |
---|
92 | d['resp_pay_reference'] = doc.resp_pay_reference |
---|
93 | d['resp_desc'] = doc.resp_desc |
---|
94 | d['order_id'] = doc.order_id |
---|
95 | d['resp_code'] = doc.resp_code |
---|
96 | d['resp_card_num'] = doc.resp_card_num |
---|
97 | d['date'] = getattr(doc,'date',None) |
---|
98 | d['resp_date'] = getattr(doc,'resp_date',None) |
---|
99 | doc.edit(mapping = d) |
---|
100 | msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()]) |
---|
101 | rwrite(msg) |
---|
102 | logger.info('upgraded student %s payment %s' % (student_id,d['key'])) |
---|
103 | if not count % commit_after: |
---|
104 | logger.info("committing %d total %d" % (commit_after,count)) |
---|
105 | commit_count += 1 |
---|
106 | # if not commit_count % 2: |
---|
107 | # break |
---|
108 | count += 1 |
---|
109 | logger.info("%d of %d upgraded" % (count,total)) |
---|