1 | ## Script (Python) "purgePayments2" |
---|
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: purgePayments2.py 3132 2008-02-08 21:10:38Z henrik $ |
---|
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'): |
---|
22 | return |
---|
23 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
24 | |
---|
25 | import logging |
---|
26 | import DateTime |
---|
27 | logger = logging.getLogger('Skins.purgePayments2') |
---|
28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
29 | |
---|
30 | paid_status = ('school_fee_paid','courses_registered','courses_validated') |
---|
31 | students = context.students_catalog(review_state = paid_status) |
---|
32 | counter = 0 |
---|
33 | counter_unpaid = 0 |
---|
34 | commit_after = 100 |
---|
35 | for student in students: |
---|
36 | to_del = [] |
---|
37 | student_id = student.id |
---|
38 | payments_folder = getattr(getattr(students_folder,student_id),'payments',None) |
---|
39 | payments = context.payments_catalog(student_id = student_id) |
---|
40 | for payment in payments: |
---|
41 | if payment.status != 'paid': |
---|
42 | counter_unpaid += 1 |
---|
43 | if payment.status != 'started' or payment.category != 'schoolfee': |
---|
44 | continue |
---|
45 | counter += 1 |
---|
46 | pid = 'p' + payment.order_id[6:] |
---|
47 | #logger.info('to be removed: %s, %s, %s, %s, %s' % (payment.student_id, sbrain.review_state, payment.order_id, payment.status, payment.category)) |
---|
48 | logger.info('object deleted: %s, %s' % (payment.student_id, pid)) |
---|
49 | to_del += pid, |
---|
50 | if not counter % commit_after: |
---|
51 | context.waeup_tool.doCommit() |
---|
52 | logger.info("committing %d of total %d" % (commit_after,counter)) |
---|
53 | #if counter > 30: |
---|
54 | # return |
---|
55 | payments_folder.manage_delObjects(to_del) |
---|
56 | |
---|
57 | logger.info("finished, %d of %d unpaid payment objects removed" % (counter, counter_unpaid)) |
---|
58 | return 'finished!' |
---|
59 | |
---|
60 | |
---|