source: WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py @ 2891

Last change on this file since 2891 was 2886, checked in by joachim, 17 years ago

use updatePayment from Payment

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