source: WAeUP_SRP/trunk/skins/waeup_epayment/purgePayments2.py @ 3964

Last change on this file since 3964 was 3962, checked in by Henrik Bettermann, 16 years ago

purgePayments2 replaces purgePayments
getAccommodationInfo: show logging message if bed not found

File size: 1.9 KB
RevLine 
[3962]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"""
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'):
22    return
23students_folder = context.portal_url.getPortalObject().campus.students   
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.purgePayments2')
28from Products.AdvancedQuery import Eq, Between, Le,In
29
30paid_status = ('school_fee_paid','courses_registered','courses_validated')
31students = context.students_catalog(review_state = paid_status)
32counter = 0
33counter_unpaid = 0
34commit_after = 100
35for 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
57logger.info("finished, %d of %d unpaid payment objects removed" % (counter, counter_unpaid))
58return 'finished!'
59
60
Note: See TracBrowser for help on using the repository browser.